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 1/2] 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; } From 836986faf3bfefeada469303aa5fca25bd670a01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Thu, 10 Oct 2013 22:57:03 +0200 Subject: [PATCH 2/2] Add temp composer home for GitDriver test using cache --- tests/Composer/Test/Repository/VcsRepositoryTest.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/Composer/Test/Repository/VcsRepositoryTest.php b/tests/Composer/Test/Repository/VcsRepositoryTest.php index b98be6fc2..eaedc82a9 100644 --- a/tests/Composer/Test/Repository/VcsRepositoryTest.php +++ b/tests/Composer/Test/Repository/VcsRepositoryTest.php @@ -25,12 +25,14 @@ use Composer\Config; */ class VcsRepositoryTest extends \PHPUnit_Framework_TestCase { + private static $composerHome; private static $gitRepo; private $skipped; protected function initialize() { $oldCwd = getcwd(); + self::$composerHome = sys_get_temp_dir() . '/composer-home-'.mt_rand().'/'; self::$gitRepo = sys_get_temp_dir() . '/composer-git-'.mt_rand().'/'; $locator = new ExecutableFinder(); @@ -125,6 +127,7 @@ class VcsRepositoryTest extends \PHPUnit_Framework_TestCase public static function tearDownAfterClass() { $fs = new Filesystem; + $fs->removeDirectory(self::$composerHome); $fs->removeDirectory(self::$gitRepo); } @@ -140,7 +143,13 @@ class VcsRepositoryTest extends \PHPUnit_Framework_TestCase 'dev-master' => true, ); - $repo = new VcsRepository(array('url' => self::$gitRepo, 'type' => 'vcs'), new NullIO, new Config()); + $config = new Config(); + $config->merge(array( + 'config' => array( + 'home' => self::$composerHome, + ), + )); + $repo = new VcsRepository(array('url' => self::$gitRepo, 'type' => 'vcs'), new NullIO, $config); $packages = $repo->getPackages(); $dumper = new ArrayDumper();