Skip to content

Commit

Permalink
Allow setting SVN command cache duration & overwrite flags independently
Browse files Browse the repository at this point in the history
  • Loading branch information
aik099 committed Jul 24, 2024
1 parent 7708632 commit 5040023
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 22 deletions.
26 changes: 19 additions & 7 deletions src/SVNBuddy/Repository/Connector/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,28 @@ public function getCommand($sub_command, array $arguments = array())
}

/**
* Sets cache configuration for next created command.
* Sets cache duration for next created command.
*
* @param mixed $cache_duration Cache duration.
* @param boolean|null $cache_overwrite Cache overwrite.
* @param mixed $cache_duration Cache duration.
*
* @return self
*/
public function withCache($cache_duration, $cache_overwrite = null)
public function withCacheDuration($cache_duration)
{
$this->_nextCommandCacheDuration = $cache_duration;

return $this;
}

/**
* Sets cache overwrite flag for next created command.
*
* @param boolean $cache_overwrite Cache overwrite.
*
* @return self
*/
public function withCacheOverwrite($cache_overwrite)
{
$this->_nextCommandCacheOverwrite = $cache_overwrite;

return $this;
Expand Down Expand Up @@ -382,7 +394,7 @@ private function _getSvnInfoEntry($path_or_url, $cache_duration = null)

// TODO: When wc path (not url) is given, then credentials can be present in "svn info" result anyway.
$svn_info = $this
->withCache($cache_duration)
->withCacheDuration($cache_duration)
->getCommand('info', array('--xml', $path_or_url_escaped))
->run();

Expand Down Expand Up @@ -415,7 +427,7 @@ public function getFirstRevision($url)
throw new \InvalidArgumentException('The repository URL "' . $url . '" is invalid.');
}

$log = $this->withCache('1 year')
$log = $this->withCacheDuration('1 year')
->getCommand('log', array('-r', '1:HEAD', '--limit', 1, '--xml', $url))
->run();

Expand Down Expand Up @@ -866,7 +878,7 @@ protected function getMergedRevisions($wc_path, $revision = null)
public function getFileContent($path_or_url, $revision)
{
return $this
->withCache(self::SVN_CAT_CACHE_DURATION)
->withCacheDuration(self::SVN_CAT_CACHE_DURATION)
->getCommand('cat', array($path_or_url, '--revision', $revision))
->run();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ protected function detectProjectBugTraqRegEx($project_path, $revision, $project_

foreach ( $ref_paths as $ref_path ) {
$logregex = $this->_repositoryConnector
->withCache('1 year', $cache_overwrite)
->withCacheDuration('1 year')
->withCacheOverwrite($cache_overwrite)
->getProperty(
'bugtraq:logregex',
$this->_repositoryUrl . $ref_path . ($project_deleted ? '@' . $revision : '')
Expand Down
35 changes: 24 additions & 11 deletions tests/SVNBuddy/Repository/Connector/ConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,33 +88,46 @@ protected function setupTest()
}

/**
* @dataProvider getCommandWithCachingDataProvider
* @dataProvider getCommandWithCacheDurationDataProvider
*/
public function testGetCommandWithCaching($duration, $overwrite)
public function testGetCommandWithCacheDuration($duration)
{
$command = $this->_expectCommand('info', array(), 'OK');

if ( $duration !== null ) {
$command->setCacheDuration($duration)->shouldBeCalled();
}

$this->_repositoryConnector->withCacheDuration($duration)->getCommand('info')->run();
}

public static function getCommandWithCacheDurationDataProvider()
{
return array(
'enabled' => array(100),
'disabled' => array(null),
);
}

/**
* @dataProvider getCommandWithCacheOverwriteDataProvider
*/
public function testGetCommandWithCacheOverwrite($overwrite)
{
$command = $this->_expectCommand('info', array(), 'OK');

if ( $overwrite !== null ) {
$command->setCacheOverwrite($overwrite)->shouldBeCalled();
}

$this->_repositoryConnector->withCache($duration, $overwrite)->getCommand('info')->run();
$this->_repositoryConnector->withCacheOverwrite($overwrite)->getCommand('info')->run();
}

public static function getCommandWithCachingDataProvider()
public static function getCommandWithCacheOverwriteDataProvider()
{
return array(
'duration - enabled, overwrite - enabled' => array(100, true),
'duration - enabled, overwrite - disabled 1' => array(100, false),
'duration - enabled, overwrite - disabled 2' => array(100, null),

'duration - disabled, overwrite - enabled' => array(null, true),
'duration - disabled, overwrite - disabled 1' => array(null, false),
'duration - disabled, overwrite - disabled 2' => array(null, null),
'enabled' => array(true),
'disabled' => array(false),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ public function testProcessDetectsMissingBugRegexps($project_deleted)
$this->repositoryConnector->isRefRoot('/path/to/project/branches/branch-name/')->willReturn(true)->shouldBeCalled();
$this->repositoryConnector->isRefRoot(Argument::any())->willReturn(false)->shouldBeCalled();

$this->repositoryConnector->withCache('1 year', false)->willReturn($this->repositoryConnector);
$this->repositoryConnector->withCacheDuration('1 year')->willReturn($this->repositoryConnector);
$this->repositoryConnector->withCacheOverwrite(false)->willReturn($this->repositoryConnector);

$this->setBugRegexpExpectation($project_deleted, 'OK');

Expand Down Expand Up @@ -193,7 +194,8 @@ public function testBugRegexpsRefresh($project_deleted)
$this->repositoryConnector->isRefRoot('/path/to/project/branches/branch-name/')->willReturn(true)->shouldBeCalled();
$this->repositoryConnector->isRefRoot(Argument::any())->willReturn(false)->shouldBeCalled();

$this->repositoryConnector->withCache('1 year', false)->willReturn($this->repositoryConnector)->shouldBeCalled();
$this->repositoryConnector->withCacheDuration('1 year')->willReturn($this->repositoryConnector)->shouldBeCalled();
$this->repositoryConnector->withCacheOverwrite(false)->willReturn($this->repositoryConnector)->shouldBeCalled();

$this->setBugRegexpExpectation($project_deleted, 'FIRST_EXPRESSION');

Expand Down Expand Up @@ -233,7 +235,8 @@ public function testBugRegexpsRefresh($project_deleted)

$this->setBugRegexpExpectation($project_deleted, 'SECOND_EXPRESSION');

$this->repositoryConnector->withCache('1 year', true)->willReturn($this->repositoryConnector)->shouldBeCalled();
$this->repositoryConnector->withCacheDuration('1 year')->willReturn($this->repositoryConnector)->shouldBeCalled();
$this->repositoryConnector->withCacheOverwrite(true)->willReturn($this->repositoryConnector)->shouldBeCalled();

$this->plugin->refreshBugRegExp('/path/to/project/');

Expand Down

0 comments on commit 5040023

Please sign in to comment.