Skip to content

Commit 22cc0de

Browse files
committed
The "reparse" command support for revision ranges
1 parent 1ba5720 commit 22cc0de

File tree

4 files changed

+91
-9
lines changed

4 files changed

+91
-9
lines changed

src/SVNBuddy/Command/ReparseCommand.php

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313

1414
use ConsoleHelpers\ConsoleKit\Exception\CommandException;
15+
use ConsoleHelpers\SVNBuddy\Repository\Parser\RevisionListParser;
1516
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\RevisionLog;
1617
use Symfony\Component\Console\Input\InputArgument;
1718
use Symfony\Component\Console\Input\InputInterface;
@@ -28,6 +29,13 @@ class ReparseCommand extends AbstractCommand
2829
*/
2930
private $_revisionLog;
3031

32+
/**
33+
* Revision list parser.
34+
*
35+
* @var RevisionListParser
36+
*/
37+
private $_revisionListParser;
38+
3139
/**
3240
* {@inheritdoc}
3341
*/
@@ -43,15 +51,29 @@ protected function configure()
4351
'.'
4452
)
4553
->addOption(
46-
'revision',
54+
'revisions',
4755
'r',
4856
InputOption::VALUE_REQUIRED,
49-
'Reparse specified revision'
57+
'List of revision(-s) and/or revision range(-s) to reparse, e.g. <comment>53324</comment>, <comment>1224-4433</comment> or <comment>all</comment>'
5058
);
5159

5260
parent::configure();
5361
}
5462

63+
/**
64+
* Prepare dependencies.
65+
*
66+
* @return void
67+
*/
68+
protected function prepareDependencies()
69+
{
70+
parent::prepareDependencies();
71+
72+
$container = $this->getContainer();
73+
74+
$this->_revisionListParser = $container['revision_list_parser'];
75+
}
76+
5577
/**
5678
* {@inheritdoc}
5779
*/
@@ -69,13 +91,24 @@ public function initialize(InputInterface $input, OutputInterface $output)
6991
*/
7092
protected function execute(InputInterface $input, OutputInterface $output)
7193
{
72-
$revision = $this->io->getOption('revision');
94+
$revisions = $this->io->getOption('revisions');
7395

74-
if ( !$revision ) {
75-
throw new CommandException('The "revision" option is mandatory.');
96+
if ( !$revisions ) {
97+
throw new CommandException('The "revisions" option is mandatory.');
7698
}
7799

78-
$this->_revisionLog->reparse($revision);
100+
// FIXME: Not checking, that given revisions belong to a working copy.
101+
$revisions = $this->_revisionListParser->expandRanges($this->getList($revisions));
102+
103+
foreach ( $this->_revisionListParser->collapseRanges($revisions) as $revision_range ) {
104+
if ( strpos($revision_range, '-') === false ) {
105+
$this->_revisionLog->reparse($revision_range, $revision_range);
106+
}
107+
else {
108+
list($from_revision, $to_revision) = explode('-', $revision_range, 2);
109+
$this->_revisionLog->reparse($from_revision, $to_revision);
110+
}
111+
}
79112
}
80113

81114
}

src/SVNBuddy/Repository/Parser/RevisionListParser.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,44 @@ public function expandRanges(array $revisions, $range_separator = '-')
5656
return array_keys($ret);
5757
}
5858

59+
/**
60+
* Collapses ranges.
61+
*
62+
* @param array $revisions Revisions.
63+
* @param string $range_separator Range separator.
64+
*
65+
* @return array
66+
*/
67+
public function collapseRanges(array $revisions, $range_separator = '-')
68+
{
69+
sort($revisions, SORT_NUMERIC);
70+
$revisions = array_map('intval', $revisions);
71+
72+
$ret = array();
73+
$range_start = $range_end = null;
74+
75+
foreach ( $revisions as $revision ) {
76+
// New range detected.
77+
if ( $range_start === null ) {
78+
$range_start = $range_end = $revision;
79+
continue;
80+
}
81+
82+
// Expanding existing range.
83+
if ( $range_end + 1 === $revision ) {
84+
$range_end = $revision;
85+
continue;
86+
}
87+
88+
$ret[] = $range_start === $range_end ? $range_start : $range_start . $range_separator . $range_end;
89+
$range_start = $range_end = $revision;
90+
}
91+
92+
if ( $range_start !== null && $range_end !== null ) {
93+
$ret[] = $range_start === $range_end ? $range_start : $range_start . $range_separator . $range_end;
94+
}
95+
96+
return $ret;
97+
}
98+
5999
}

src/SVNBuddy/Repository/RevisionLog/RevisionLog.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,20 @@ protected function getForceRefreshFlag()
188188
/**
189189
* Reparses a revision.
190190
*
191-
* @param integer $revision Revision.
191+
* @param integer $from_revision From revision.
192+
* @param integer $to_revision To revision.
192193
*
193194
* @return void
194195
* @throws \LogicException When no plugins are registered.
195196
*/
196-
public function reparse($revision)
197+
public function reparse($from_revision, $to_revision)
197198
{
198199
if ( !$this->_plugins ) {
199200
throw new \LogicException('Please register at least one revision log plugin.');
200201
}
201202

202203
$this->_databaseReady();
203-
$this->_queryRevisionData($revision, $revision, true);
204+
$this->_queryRevisionData($from_revision, $to_revision, true);
204205
}
205206

206207
/**

tests/SVNBuddy/Repository/Parser/RevisionListParserTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,12 @@ public function testMultiDigitRevisions()
107107
$this->assertEquals($expected, $actual);
108108
}
109109

110+
public function testCollapsing()
111+
{
112+
$expected = array('10-12', 15, '17-19', 25);
113+
$actual = $this->_revisionListParser->collapseRanges(array(18, 10, 11, 15, 17, 12, 19, 25));
114+
115+
$this->assertEquals($expected, $actual);
116+
}
117+
110118
}

0 commit comments

Comments
 (0)