diff --git a/src/SVNBuddy/Command/ReparseCommand.php b/src/SVNBuddy/Command/ReparseCommand.php
index 2dfd1b8..f2ab592 100644
--- a/src/SVNBuddy/Command/ReparseCommand.php
+++ b/src/SVNBuddy/Command/ReparseCommand.php
@@ -12,6 +12,7 @@
use ConsoleHelpers\ConsoleKit\Exception\CommandException;
+use ConsoleHelpers\SVNBuddy\Repository\Parser\RevisionListParser;
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\RevisionLog;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@@ -28,6 +29,13 @@ class ReparseCommand extends AbstractCommand
*/
private $_revisionLog;
+ /**
+ * Revision list parser.
+ *
+ * @var RevisionListParser
+ */
+ private $_revisionListParser;
+
/**
* {@inheritdoc}
*/
@@ -43,15 +51,29 @@ protected function configure()
'.'
)
->addOption(
- 'revision',
+ 'revisions',
'r',
InputOption::VALUE_REQUIRED,
- 'Reparse specified revision'
+ 'List of revision(-s) and/or revision range(-s) to reparse, e.g. 53324, 1224-4433 or all'
);
parent::configure();
}
+ /**
+ * Prepare dependencies.
+ *
+ * @return void
+ */
+ protected function prepareDependencies()
+ {
+ parent::prepareDependencies();
+
+ $container = $this->getContainer();
+
+ $this->_revisionListParser = $container['revision_list_parser'];
+ }
+
/**
* {@inheritdoc}
*/
@@ -69,13 +91,24 @@ public function initialize(InputInterface $input, OutputInterface $output)
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
- $revision = $this->io->getOption('revision');
+ $revisions = $this->io->getOption('revisions');
- if ( !$revision ) {
- throw new CommandException('The "revision" option is mandatory.');
+ if ( !$revisions ) {
+ throw new CommandException('The "revisions" option is mandatory.');
}
- $this->_revisionLog->reparse($revision);
+ // FIXME: Not checking, that given revisions belong to a working copy.
+ $revisions = $this->_revisionListParser->expandRanges($this->getList($revisions));
+
+ foreach ( $this->_revisionListParser->collapseRanges($revisions) as $revision_range ) {
+ if ( strpos($revision_range, '-') === false ) {
+ $this->_revisionLog->reparse($revision_range, $revision_range);
+ }
+ else {
+ list($from_revision, $to_revision) = explode('-', $revision_range, 2);
+ $this->_revisionLog->reparse($from_revision, $to_revision);
+ }
+ }
}
}
diff --git a/src/SVNBuddy/Repository/Parser/RevisionListParser.php b/src/SVNBuddy/Repository/Parser/RevisionListParser.php
index 04d0e69..b4d8df7 100644
--- a/src/SVNBuddy/Repository/Parser/RevisionListParser.php
+++ b/src/SVNBuddy/Repository/Parser/RevisionListParser.php
@@ -56,4 +56,44 @@ public function expandRanges(array $revisions, $range_separator = '-')
return array_keys($ret);
}
+ /**
+ * Collapses ranges.
+ *
+ * @param array $revisions Revisions.
+ * @param string $range_separator Range separator.
+ *
+ * @return array
+ */
+ public function collapseRanges(array $revisions, $range_separator = '-')
+ {
+ sort($revisions, SORT_NUMERIC);
+ $revisions = array_map('intval', $revisions);
+
+ $ret = array();
+ $range_start = $range_end = null;
+
+ foreach ( $revisions as $revision ) {
+ // New range detected.
+ if ( $range_start === null ) {
+ $range_start = $range_end = $revision;
+ continue;
+ }
+
+ // Expanding existing range.
+ if ( $range_end + 1 === $revision ) {
+ $range_end = $revision;
+ continue;
+ }
+
+ $ret[] = $range_start === $range_end ? $range_start : $range_start . $range_separator . $range_end;
+ $range_start = $range_end = $revision;
+ }
+
+ if ( $range_start !== null && $range_end !== null ) {
+ $ret[] = $range_start === $range_end ? $range_start : $range_start . $range_separator . $range_end;
+ }
+
+ return $ret;
+ }
+
}
diff --git a/src/SVNBuddy/Repository/RevisionLog/RevisionLog.php b/src/SVNBuddy/Repository/RevisionLog/RevisionLog.php
index 38b7ffa..4ae2670 100644
--- a/src/SVNBuddy/Repository/RevisionLog/RevisionLog.php
+++ b/src/SVNBuddy/Repository/RevisionLog/RevisionLog.php
@@ -188,19 +188,20 @@ protected function getForceRefreshFlag()
/**
* Reparses a revision.
*
- * @param integer $revision Revision.
+ * @param integer $from_revision From revision.
+ * @param integer $to_revision To revision.
*
* @return void
* @throws \LogicException When no plugins are registered.
*/
- public function reparse($revision)
+ public function reparse($from_revision, $to_revision)
{
if ( !$this->_plugins ) {
throw new \LogicException('Please register at least one revision log plugin.');
}
$this->_databaseReady();
- $this->_queryRevisionData($revision, $revision, true);
+ $this->_queryRevisionData($from_revision, $to_revision, true);
}
/**
diff --git a/tests/SVNBuddy/Repository/Parser/RevisionListParserTest.php b/tests/SVNBuddy/Repository/Parser/RevisionListParserTest.php
index f816689..c9c408d 100644
--- a/tests/SVNBuddy/Repository/Parser/RevisionListParserTest.php
+++ b/tests/SVNBuddy/Repository/Parser/RevisionListParserTest.php
@@ -107,4 +107,12 @@ public function testMultiDigitRevisions()
$this->assertEquals($expected, $actual);
}
+ public function testCollapsing()
+ {
+ $expected = array('10-12', 15, '17-19', 25);
+ $actual = $this->_revisionListParser->collapseRanges(array(18, 10, 11, 15, 17, 12, 19, 25));
+
+ $this->assertEquals($expected, $actual);
+ }
+
}