From f51aa4fad6a8c254b9d4e2acecc882e9b226925f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 9 Oct 2013 14:21:51 +0200 Subject: [PATCH] Add local cache for Git repositories --- src/Composer/Repository/Vcs/GitDriver.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Composer/Repository/Vcs/GitDriver.php b/src/Composer/Repository/Vcs/GitDriver.php index b220ea573..e2a3a9eb0 100644 --- a/src/Composer/Repository/Vcs/GitDriver.php +++ b/src/Composer/Repository/Vcs/GitDriver.php @@ -17,12 +17,14 @@ use Composer\Util\ProcessExecutor; use Composer\Util\Filesystem; use Composer\Util\Git as GitUtil; use Composer\IO\IOInterface; +use Composer\Cache; /** * @author Jordi Boggiano */ class GitDriver extends VcsDriver { + protected $cache; protected $tags; protected $branches; protected $rootIdentifier; @@ -77,6 +79,8 @@ class GitDriver extends VcsDriver $this->getTags(); $this->getBranches(); + + $this->cache = new Cache($this->io, $this->config->get('cache-repo-dir').'/'.preg_replace('{[^a-z0-9.]}i', '-', $this->url)); } /** @@ -132,6 +136,10 @@ class GitDriver extends VcsDriver */ public function getComposerInformation($identifier) { + if (preg_match('{[a-f0-9]{40}}i', $identifier) && $res = $this->cache->read($identifier)) { + $this->infoCache[$identifier] = JsonFile::parseJson($res); + } + if (!isset($this->infoCache[$identifier])) { $resource = sprintf('%s:composer.json', escapeshellarg($identifier)); $this->process->execute(sprintf('git show %s', $resource), $composer, $this->repoDir); @@ -147,6 +155,11 @@ class GitDriver extends VcsDriver $date = new \DateTime('@'.trim($output), new \DateTimeZone('UTC')); $composer['time'] = $date->format('Y-m-d H:i:s'); } + + if (preg_match('{[a-f0-9]{40}}i', $identifier)) { + $this->cache->write($identifier, json_encode($composer)); + } + $this->infoCache[$identifier] = $composer; }