Skip to content

Commit

Permalink
Merge pull request #153 from aik099/revision-reparsing-feat
Browse files Browse the repository at this point in the history
Added the "reparse" command for specific revision data reparsing
  • Loading branch information
aik099 authored Jun 17, 2024
2 parents 6b0328c + a201d86 commit 1f80f78
Show file tree
Hide file tree
Showing 18 changed files with 707 additions and 47 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Added
- The `commit` command now highlights the line with a commited revision number.
- Added `reparse` command for reparsing data of a given revision (e.g. when it's log message was changed in repository).

### Changed
...
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,29 @@ Displays project meta information in following format:
![project meta information](docs/images/SvnBuddy_ProjectCommand_ShowMetaOption.png)


### The "reparse" command

CReparses given revision.

#### Arguments

* `path` - Working copy path [default: "`.`"]


#### Options

* `-r`, `--revision=REVISION` - Reparse specified revision


#### Examples

```
svn-buddy.phar reparse --revision 12345
```

Re-reads and reparses 12345 revision information.


### The "self-update" command

Updates application to most recent version. Following update channels are available:
Expand Down
81 changes: 81 additions & 0 deletions src/SVNBuddy/Command/ReparseCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/**
* This file is part of the SVN-Buddy library.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @copyright Alexander Obuhovich <[email protected]>
* @link https://github.com/console-helpers/svn-buddy
*/

namespace ConsoleHelpers\SVNBuddy\Command;


use ConsoleHelpers\ConsoleKit\Exception\CommandException;
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\RevisionLog;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class ReparseCommand extends AbstractCommand
{

/**
* Revision log
*
* @var RevisionLog
*/
private $_revisionLog;

/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('reparse')
->setDescription('Reparses given revision')
->addArgument(
'path',
InputArgument::OPTIONAL,
'Working copy path',
'.'
)
->addOption(
'revision',
'r',
InputOption::VALUE_REQUIRED,
'Reparse specified revision'
);

parent::configure();
}

/**
* {@inheritdoc}
*/
public function initialize(InputInterface $input, OutputInterface $output)
{
parent::initialize($input, $output);

$this->_revisionLog = $this->getRevisionLog($this->getWorkingCopyUrl());
}

/**
* {@inheritdoc}
*
* @throws CommandException When mandatory "revision" option wasn't given.
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$revision = $this->io->getOption('revision');

if ( !$revision ) {
throw new CommandException('The "revision" option is mandatory.');
}

$this->_revisionLog->reparse($revision);
}

}
4 changes: 4 additions & 0 deletions src/SVNBuddy/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use ConsoleHelpers\SVNBuddy\Command\LogCommand;
use ConsoleHelpers\SVNBuddy\Command\MergeCommand;
use ConsoleHelpers\SVNBuddy\Command\ProjectCommand;
use ConsoleHelpers\SVNBuddy\Command\ReparseCommand;
use ConsoleHelpers\SVNBuddy\Command\RevertCommand;
use ConsoleHelpers\SVNBuddy\Command\SearchCommand;
use ConsoleHelpers\SVNBuddy\Command\SelfUpdateCommand;
Expand Down Expand Up @@ -284,6 +285,9 @@ protected function addCommandFactories()
$this->commandFactories['revert'] = function () {
return new RevertCommand();
};
$this->commandFactories['reparse'] = function () {
return new ReparseCommand();
};
$this->commandFactories['log'] = function () {
return new LogCommand();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@
use Aura\Sql\ExtendedPdoInterface;
use ConsoleHelpers\SVNBuddy\Repository\Connector\Connector;
use ConsoleHelpers\SVNBuddy\Repository\Parser\LogMessageParserFactory;
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\IOverwriteAwarePlugin;
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\TOverwriteAwarePlugin;
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\RepositoryFiller;

class BugsPlugin extends AbstractDatabaseCollectorPlugin
class BugsPlugin extends AbstractDatabaseCollectorPlugin implements IOverwriteAwarePlugin
{

use TOverwriteAwarePlugin;

const STATISTIC_BUG_ADDED_TO_COMMIT = 'bug_added_to_commit';

const STATISTIC_BUG_REMOVED_FROM_COMMIT = 'bug_removed_from_commit';

/**
* Repository url.
*
Expand Down Expand Up @@ -83,7 +89,7 @@ public function getName()
public function defineStatisticTypes()
{
return array(
self::STATISTIC_BUG_ADDED_TO_COMMIT,
self::STATISTIC_BUG_ADDED_TO_COMMIT, self::STATISTIC_BUG_REMOVED_FROM_COMMIT,
);
}

Expand All @@ -101,12 +107,35 @@ public function doProcess($from_revision, $to_revision)

$last_revision = $this->getLastRevision();

if ( $to_revision > $last_revision ) {
if ( $this->isOverwriteMode() ) {
$this->remove($from_revision, $to_revision);
$this->detectBugs($from_revision, $to_revision);
}
elseif ( $to_revision > $last_revision ) {
$this->detectBugs($last_revision + 1, $to_revision);
}

if ( $to_revision > $last_revision ) {
$this->setLastRevision($to_revision);
}
}

/**
* Removes changes plugin made based on a given revision.
*
* @param integer $from_revision From revision.
* @param integer $to_revision To revision.
*
* @return void
*/
protected function remove($from_revision, $to_revision)
{
for ( $revision = $from_revision; $revision <= $to_revision; $revision++ ) {
$bug_count = $this->repositoryFiller->removeBugsFromCommit($revision);
$this->recordStatistic(self::STATISTIC_BUG_REMOVED_FROM_COMMIT, $bug_count);
}
}

/**
* Populate "BugRegExp" column for projects without it.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* This file is part of the SVN-Buddy library.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @copyright Alexander Obuhovich <[email protected]>
* @link https://github.com/console-helpers/svn-buddy
*/

namespace ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin;


interface IOverwriteAwarePlugin
{

/**
* Sets overwrite mode.
*
* @param boolean $overwrite_mode Overwrite mode.
*
* @return void
*/
public function setOverwriteMode($overwrite_mode);

/**
* Determines if overwrite mode is enabled.
*
* @return boolean
*/
public function isOverwriteMode();

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@


use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\AbstractPlugin;
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\IOverwriteAwarePlugin;

abstract class AbstractRepositoryCollectorPlugin extends AbstractPlugin implements IRepositoryCollectorPlugin
{
Expand All @@ -30,16 +31,31 @@ public function parse(\SimpleXMLElement $log)
$last_processed_revision = null;
$last_revision = $this->getLastRevision();

foreach ( $log->logentry as $log_entry ) {
$revision = (int)$log_entry['revision'];
if ( $this instanceof IOverwriteAwarePlugin && $this->isOverwriteMode() ) {
foreach ( $log->logentry as $log_entry ) {
$revision = (int)$log_entry['revision'];

// Don't handle same revision twice.
if ( $revision <= $last_revision ) {
continue;
$this->remove($revision);
$this->doParse($revision, $log_entry);

// When revision appeared only after overwrite parsing process.
if ( $revision > $last_revision ) {
$last_processed_revision = $revision;
}
}
}
else {
foreach ( $log->logentry as $log_entry ) {
$revision = (int)$log_entry['revision'];

// Don't handle same revision twice.
if ( $revision <= $last_revision ) {
continue;
}

$this->doParse($revision, $log_entry);
$last_processed_revision = $revision;
$this->doParse($revision, $log_entry);
$last_processed_revision = $revision;
}
}

if ( isset($last_processed_revision) ) {
Expand All @@ -61,6 +77,15 @@ public function parse(\SimpleXMLElement $log)
*/
abstract protected function doParse($revision, \SimpleXMLElement $log_entry);

/**
* Removes changes plugin made based on a given revision.
*
* @param integer $revision Revision.
*
* @return void
*/
abstract protected function remove($revision);

/**
* Returns revision query flags.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@
namespace ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\RepositoryCollectorPlugin;


use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\IOverwriteAwarePlugin;
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\TOverwriteAwarePlugin;
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\RevisionLog;

class MergesPlugin extends AbstractRepositoryCollectorPlugin
class MergesPlugin extends AbstractRepositoryCollectorPlugin implements IOverwriteAwarePlugin
{

use TOverwriteAwarePlugin;

const STATISTIC_MERGE_ADDED = 'merge_added';

const STATISTIC_MERGE_DELETED = 'merge_deleted';

/**
* Returns plugin name.
*
Expand Down Expand Up @@ -46,7 +52,7 @@ public function getRevisionQueryFlags()
public function defineStatisticTypes()
{
return array(
self::STATISTIC_MERGE_ADDED,
self::STATISTIC_MERGE_ADDED, self::STATISTIC_MERGE_DELETED,
);
}

Expand All @@ -70,6 +76,15 @@ protected function doParse($revision, \SimpleXMLElement $log_entry)
$this->recordStatistic(self::STATISTIC_MERGE_ADDED, count($merged_revisions));
}

/**
* @inheritDoc
*/
protected function remove($revision)
{
$merged_revisions_count = $this->repositoryFiller->removeMergeCommit($revision);
$this->recordStatistic(self::STATISTIC_MERGE_DELETED, $merged_revisions_count);
}

/**
* Find revisions by collected data.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,16 @@ protected function doParse($revision, \SimpleXMLElement $log_entry)
}
}

/**
* @inheritDoc
*
* @throws \RuntimeException When attempting to remove plugin collected data.
*/
protected function remove($revision)
{
throw new \RuntimeException('Not supported.');
}

/**
* Sorts paths to move parent folders above their sub-folders.
*
Expand Down
Loading

0 comments on commit 1f80f78

Please sign in to comment.