1
0
Fork 0

* refactor svn command 'creation' into a single method: getSvnCommand()

pull/410/head
till 2012-03-08 15:39:22 +01:00
parent 6417a86651
commit d1482bfa3c
1 changed files with 32 additions and 31 deletions

View File

@ -109,27 +109,21 @@ class SvnDriver extends VcsDriver implements VcsDriverInterface
} }
$this->process->execute( $this->process->execute(
sprintf( $this->getSvnCommand('svn cat', $this->baseUrl . $identifier . 'composer.json' . $rev),
'svn cat --non-interactive %s %s',
$this->getSvnCredentialString(),
escapeshellarg($this->baseUrl.$identifier.'composer.json'.$rev)
),
$composer $composer
); );
if (!trim($composer)) { if (!trim($composer)) {
throw new \UnexpectedValueException('Failed to retrieve composer information for identifier '.$identifier.' in '.$this->getUrl()); throw new \UnexpectedValueException(
'Failed to retrieve composer information for identifier ' . $identifier . ' in ' . $this->getUrl()
);
} }
$composer = JsonFile::parseJson($composer); $composer = JsonFile::parseJson($composer);
if (!isset($composer['time'])) { if (!isset($composer['time'])) {
$this->process->execute( $this->process->execute(
sprintf( $this->getSvnCommand('svn info', $this->baseUrl . $identifier . $rev),
'svn info %s %s',
$this->getSvnCredentialString(),
escapeshellarg($this->baseUrl.$identifier.$rev)
),
$output $output
); );
foreach ($this->process->splitLines($output) as $line) { foreach ($this->process->splitLines($output) as $line) {
@ -153,11 +147,7 @@ class SvnDriver extends VcsDriver implements VcsDriverInterface
{ {
if (null === $this->tags) { if (null === $this->tags) {
$this->process->execute( $this->process->execute(
sprintf( $this->getSvnCommand('svn ls', $this->baseUrl . '/tags'),
'svn ls --non-interactive %s %s',
$this->getSvnCredentialString(),
escapeshellarg($this->baseUrl.'/tags')
),
$output $output
); );
$this->tags = array(); $this->tags = array();
@ -178,11 +168,7 @@ class SvnDriver extends VcsDriver implements VcsDriverInterface
{ {
if (null === $this->branches) { if (null === $this->branches) {
$this->process->execute( $this->process->execute(
sprintf( $this->getSvnCommand('svn ls --verbose', $this->baseUrl . '/'),
'svn ls --verbose --non-interactive %s %s',
$this->getSvnCredentialString(),
escapeshellarg($this->baseUrl.'/')
),
$output $output
); );
@ -197,11 +183,7 @@ class SvnDriver extends VcsDriver implements VcsDriverInterface
unset($output); unset($output);
$this->process->execute( $this->process->execute(
sprintf( $this->getSvnCommand('svn ls --verbose', $this->baseUrl . '/branches'),
'svn ls --verbose --non-interactive %s',
$this->getSvnCredentialString(),
escapeshellarg($this->baseUrl.'/branches')
),
$output $output
); );
foreach ($this->process->splitLines(trim($output)) as $line) { foreach ($this->process->splitLines(trim($output)) as $line) {
@ -216,6 +198,29 @@ class SvnDriver extends VcsDriver implements VcsDriverInterface
return $this->branches; return $this->branches;
} }
/**
* A method to create the svn commands run.
*
* @string $cmd Usually 'svn ls' or something like that.
* @string $url Repo URL.
* @string $pipe Optional pipe for the output.
*
* @return string
*/
public function getSvnCommand($cmd, $url, $pipe = null)
{
$cmd = sprintf('%s %s%s %s',
$cmd,
$this->getSvnInteractiveSetting(),
$this->getSvnCredentialString(),
escapeshellarg($url)
);
if ($pipe !== null) {
$cmd .= ' ' . $pipe;
}
return $cmd;
}
/** /**
* Return the credential string for the svn command. * Return the credential string for the svn command.
* *
@ -267,11 +272,7 @@ class SvnDriver extends VcsDriver implements VcsDriverInterface
$processExecutor = new ProcessExecutor(); $processExecutor = new ProcessExecutor();
$exit = $processExecutor->execute( $exit = $processExecutor->execute(
sprintf( $this->getSvnCommand('svn info', $url, '2>/dev/null'),
'svn info --non-interactive %s %s 2>/dev/null',
$this->getSvnCredentialString(),
escapeshellarg($url)
),
$ignored $ignored
); );
return $exit === 0; return $exit === 0;