From 89d2f58c05044c94114dae64a5af7710e47ef7ad Mon Sep 17 00:00:00 2001 From: Steve Buzonas Date: Thu, 12 May 2016 21:21:50 -0400 Subject: [PATCH] use version parser in vcs downloader --- src/Composer/Downloader/GitDownloader.php | 21 +-------------------- src/Composer/Downloader/HgDownloader.php | 17 ----------------- src/Composer/Downloader/SvnDownloader.php | 18 ------------------ src/Composer/Downloader/VcsDownloader.php | 20 +++++++++++++++++++- 4 files changed, 20 insertions(+), 56 deletions(-) diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php index ee9609dd7..94a8d78d9 100644 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -23,7 +23,7 @@ use Composer\Config; /** * @author Jordi Boggiano */ -class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface, VcsCapableDownloaderInterface +class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface { private $hasStashedChanges = false; private $hasDiscardedChanges = false; @@ -196,25 +196,6 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface, Vc return $unpushedChanges; } - /** - * {@inheritDoc} - */ - public function getVcsReference(PackageInterface $package, $path) - { - if (!$this->hasMetadataRepository($path)) { - return; - } - - GitUtil::cleanEnv(); - - $command = 'git log --pretty="%H" -n1 HEAD'; - if (0 !== $this->process->execute($command, $output, $path)) { - throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); - } - - return trim($output) ?: null; - } - /** * {@inheritDoc} */ diff --git a/src/Composer/Downloader/HgDownloader.php b/src/Composer/Downloader/HgDownloader.php index 01a91db2e..4222282c0 100644 --- a/src/Composer/Downloader/HgDownloader.php +++ b/src/Composer/Downloader/HgDownloader.php @@ -77,23 +77,6 @@ class HgDownloader extends VcsDownloader return trim($output) ?: null; } - /** - * {@inheritDoc} - */ - public function getVcsReference(PackageInterface $package, $path) - { - if (!$this->hasMetadataRepository($path)) { - return; - } - - $command = 'hg parent --template ' . escapeshellarg('{node}'); - if (0 !== $this->process->execute($command, $output, $path)) { - throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); - } - - return trim($output) ?: null; - } - /** * {@inheritDoc} */ diff --git a/src/Composer/Downloader/SvnDownloader.php b/src/Composer/Downloader/SvnDownloader.php index 36b660022..a21f35858 100644 --- a/src/Composer/Downloader/SvnDownloader.php +++ b/src/Composer/Downloader/SvnDownloader.php @@ -81,24 +81,6 @@ class SvnDownloader extends VcsDownloader return preg_match('{^ *[^X ] +}m', $output) ? $output : null; } - /** - * {@inheritDoc} - */ - public function getVcsReference(PackageInterface $package, $path) - { - if (!$this->hasMetadataRepository($path)) { - return; - } - - SvnUtil::cleanEnv(); - - if (0 !== $this->process->execute('svnversion', $output, $path)) { - throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); - } - - return trim($output) ?: null; - } - /** * Execute an SVN command and try to fix up the process with credentials * if necessary. diff --git a/src/Composer/Downloader/VcsDownloader.php b/src/Composer/Downloader/VcsDownloader.php index 30323856f..e4fe312d7 100644 --- a/src/Composer/Downloader/VcsDownloader.php +++ b/src/Composer/Downloader/VcsDownloader.php @@ -13,7 +13,10 @@ namespace Composer\Downloader; use Composer\Config; +use Composer\Package\Dumper\ArrayDumper; use Composer\Package\PackageInterface; +use Composer\Package\Version\VersionGuesser; +use Composer\Package\Version\VersionParser; use Composer\Util\ProcessExecutor; use Composer\IO\IOInterface; use Composer\Util\Filesystem; @@ -21,7 +24,7 @@ use Composer\Util\Filesystem; /** * @author Jordi Boggiano */ -abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterface +abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterface, VcsCapableDownloaderInterface { /** @var IOInterface */ protected $io; @@ -193,6 +196,21 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa return $this; } + /** + * {@inheritDoc} + */ + public function getVcsReference(PackageInterface $package, $path) + { + $parser = new VersionParser; + $guesser = new VersionGuesser($this->config, $this->process, $parser); + $dumper = new ArrayDumper; + + $packageConfig = $dumper->dump($package); + if ($packageVersion = $guesser->guessVersion($packageConfig, $path)) { + return $packageVersion['commit']; + } + } + /** * Prompt the user to check if changes should be stashed/removed or the operation aborted *