Skip to content

Commit

Permalink
Queue repository revision scan after a commit was made.
Browse files Browse the repository at this point in the history
  • Loading branch information
aik099 committed Jul 24, 2024
1 parent 5040023 commit 0c53b51
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Show update notifications only, when SVN-Buddy is being used from a PHAR file.
- The cache delete/set commands were displayed as "cache hit"/"cache miss" operations during verbose output.
- When there was a cache miss, then explain why (absent, invalidated, expired) during verbose output.
- Queue SVN-Buddy new repository commit discovery, after a new commit in SVN-Buddy was made.

## [0.7.0] - 2024-04-12
### Added
Expand Down
3 changes: 3 additions & 0 deletions src/SVNBuddy/Command/CommitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->_workingCopyConflictTracker->erase($wc_path);
unlink($tmp_file);

// Make committed revision instantly available for merging.
$this->getRevisionLog($this->getWorkingCopyUrl())->setForceRefreshFlag(true);

$this->io->writeln('<info>Done</info>');
}

Expand Down
3 changes: 2 additions & 1 deletion src/SVNBuddy/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ public function __construct(array $values = array())
return new RevisionLogFactory(
$c['repository_connector'],
$c['db_manager'],
$c['log_message_parser_factory']
$c['log_message_parser_factory'],
$c['working_directory']
);
};

Expand Down
43 changes: 43 additions & 0 deletions src/SVNBuddy/Repository/RevisionLog/RevisionLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,27 @@ class RevisionLog
*/
private $_revisionUrlBuilder;

/**
* Force refresh flag filename.
*
* @var string
*/
private $_forceRefreshFlagFilename;

/**
* Create revision log.
*
* @param string $repository_url Repository url.
* @param RevisionUrlBuilder $revision_url_builder Revision URL builder.
* @param Connector $repository_connector Repository connector.
* @param string $working_directory Working directory.
* @param ConsoleIO $io Console IO.
*/
public function __construct(
$repository_url,
RevisionUrlBuilder $revision_url_builder,
Connector $repository_connector,
$working_directory,
ConsoleIO $io = null
) {
$this->_io = $io;
Expand All @@ -98,6 +107,7 @@ public function __construct(
$this->_projectPath = $repository_connector->getProjectUrl($relative_path) . '/';
$this->_refName = $repository_connector->getRefByPath($relative_path);
$this->_revisionUrlBuilder = $revision_url_builder;
$this->_forceRefreshFlagFilename = $working_directory . '/' . md5($this->_repositoryRootUrl) . '.force-refresh';
}

/**
Expand Down Expand Up @@ -134,6 +144,12 @@ public function refresh($is_migration)
else {
// Import all data for new commits only.
$from_revision = $this->_getAggregateRevision('min');

if ( $this->getForceRefreshFlag() ) {
$this->_repositoryConnector->withCacheOverwrite(true);
$this->setForceRefreshFlag(false);
}

$to_revision = $this->_repositoryConnector->getLastRevision($this->_repositoryRootUrl);
}

Expand All @@ -142,6 +158,33 @@ public function refresh($is_migration)
}
}

/**
* Sets force refresh flag.
*
* @param boolean $flag Flag.
*
* @return void
*/
public function setForceRefreshFlag($flag)
{
if ( $flag ) {
touch($this->_forceRefreshFlagFilename);
}
else {
unlink($this->_forceRefreshFlagFilename);
}
}

/**
* Gets force refresh flag.
*
* @return boolean
*/
protected function getForceRefreshFlag()
{
return file_exists($this->_forceRefreshFlagFilename);
}

/**
* Reparses a revision.
*
Expand Down
20 changes: 18 additions & 2 deletions src/SVNBuddy/Repository/RevisionLog/RevisionLogFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ class RevisionLogFactory
*/
private $_logMessageParserFactory;

/**
* Working directory.
*
* @var string
*/
private $_workingDirectory;

/**
* Revision logs by url
*
Expand All @@ -61,15 +68,18 @@ class RevisionLogFactory
* @param Connector $repository_connector Repository connector.
* @param DatabaseManager $database_manager Database manager.
* @param LogMessageParserFactory $log_message_parser_factory Log message parser factory.
* @param string $working_directory Working directory.
*/
public function __construct(
Connector $repository_connector,
DatabaseManager $database_manager,
LogMessageParserFactory $log_message_parser_factory
LogMessageParserFactory $log_message_parser_factory,
$working_directory
) {
$this->_repositoryConnector = $repository_connector;
$this->_databaseManager = $database_manager;
$this->_logMessageParserFactory = $log_message_parser_factory;
$this->_workingDirectory = $working_directory;
}

/**
Expand Down Expand Up @@ -112,7 +122,13 @@ protected function createRevisionLog($repository_url, ConsoleIO $io = null)
$revision_url_builder = new RevisionUrlBuilder($this->_repositoryConnector, $repository_url);

// Create blank revision log.
$revision_log = new RevisionLog($repository_url, $revision_url_builder, $this->_repositoryConnector, $io);
$revision_log = new RevisionLog(
$repository_url,
$revision_url_builder,
$this->_repositoryConnector,
$this->_workingDirectory,
$io
);

// Add plugins to revision log.
$revision_log->registerPlugin(new SummaryPlugin($database, $repository_filler));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public function testGetRevisionLog()
$factory = new RevisionLogFactory(
$repository_connector->reveal(),
$database_manager->reveal(),
$log_message_parser_factory->reveal()
$log_message_parser_factory->reveal(),
sys_get_temp_dir() // TODO: Test with fake working directory class.
);
$this->assertInstanceOf(
RevisionLog::class,
Expand Down
1 change: 1 addition & 0 deletions tests/SVNBuddy/Repository/RevisionLog/RevisionLogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ protected function createRevisionLog($repository_url, ConsoleIO $io = null)
$repository_url,
$this->revisionUrlBuilder->reveal(),
$this->repositoryConnector->reveal(),
sys_get_temp_dir(), // TODO: Test with fake working directory class.
$io
);

Expand Down

0 comments on commit 0c53b51

Please sign in to comment.