From 58b94b66e559b48e479dd07ded31a0e0029f3b3b Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 11 Dec 2016 16:29:13 +0100 Subject: [PATCH] Shorten git hashes to 10chars to avoid long lines, refs #5946 --- src/Composer/Downloader/GitDownloader.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php index 6d87394bc..e3e751f46 100644 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -49,7 +49,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface // --dissociate option is only available since git 2.3.0-rc0 $gitVersion = $this->gitUtil->getVersion(); - $msg = " Cloning ".$ref; + $msg = " Cloning ".$this->getShortHash($ref); if ($gitVersion && version_compare($gitVersion, '2.3.0-rc0', '>=')) { $this->io->writeError('', true, IOInterface::DEBUG); $this->io->writeError(sprintf(' Cloning to cache at %s', ProcessExecutor::escape($cachePath)), true, IOInterface::DEBUG); @@ -57,7 +57,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface $this->gitUtil->syncMirror($url, $cachePath); if (is_dir($cachePath)) { $cacheOptions = sprintf('--dissociate --reference %s ', ProcessExecutor::escape($cachePath)); - $msg = " Cloning ".$ref.' from cache'; + $msg = " Cloning ".$this->getShortHash($ref).' from cache'; } } catch (\RuntimeException $e) {} } @@ -105,7 +105,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface } $ref = $target->getSourceReference(); - $this->io->writeError(" Checking out ".$ref); + $this->io->writeError(" Checking out ".$this->getShortHash($ref)); $command = 'git remote set-url composer %s && git rev-parse --quiet --verify %s^{commit} || (git fetch composer && git fetch --tags composer)'; $commandCallable = function ($url) use ($command, $ref) { @@ -492,4 +492,13 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface return is_dir($path.'/.git'); } + + protected function getShortHash($reference) + { + if (!$this->io->isVerbose() && preg_match('{^[0-9a-f]{40}$}', $reference)) { + return substr($reference, 10); + } + + return $reference; + } }