From c9ef7479c4a399e37a8bf48c9c94fc9de6d7f460 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 20 Jun 2012 11:47:38 +0200 Subject: [PATCH] Keep track of commit dates in the lock file in case the reference disappears --- src/Composer/Factory.php | 2 +- src/Composer/Installer.php | 4 ++++ src/Composer/Package/Locker.php | 15 ++++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index 43d805b79..0475a0688 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -144,7 +144,7 @@ class Factory $lockFile = "json" === pathinfo($composerFile, PATHINFO_EXTENSION) ? substr($composerFile, 0, -4).'lock' : $composerFile . '.lock'; - $locker = new Package\Locker(new JsonFile($lockFile, new RemoteFilesystem($io)), $rm, md5_file($composerFile)); + $locker = new Package\Locker(new JsonFile($lockFile, new RemoteFilesystem($io)), $rm, $im, md5_file($composerFile)); $composer->setLocker($locker); } diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index 074dfc399..d10c438f8 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -401,6 +401,10 @@ class Installer $lockData = $this->locker->getLockData(); foreach ($lockData['packages'] as $lockedPackage) { if (!empty($lockedPackage['source-reference']) && strtolower($lockedPackage['package']) === $package->getName()) { + // update commit date to allow recovery in case the commit disappeared + if (!empty($lockedPackage['commit-date'])) { + $package->setReleaseDate(new \DateTime('@'.$lockedPackage['commit-date'])); + } $package->setSourceReference($lockedPackage['source-reference']); break; } diff --git a/src/Composer/Package/Locker.php b/src/Composer/Package/Locker.php index 54a9deea3..a619c45e6 100644 --- a/src/Composer/Package/Locker.php +++ b/src/Composer/Package/Locker.php @@ -13,18 +13,22 @@ namespace Composer\Package; use Composer\Json\JsonFile; +use Composer\Installer\InstallationManager; use Composer\Repository\RepositoryManager; +use Composer\Util\ProcessExecutor; use Composer\Package\AliasPackage; /** * Reads/writes project lockfile (composer.lock). * * @author Konstantin Kudryashiv + * @author Jordi Boggiano */ class Locker { private $lockFile; private $repositoryManager; + private $installationManager; private $hash; private $lockDataCache; @@ -33,12 +37,14 @@ class Locker * * @param JsonFile $lockFile lockfile loader * @param RepositoryManager $repositoryManager repository manager instance + * @param InstallationManager $installationManager installation manager instance * @param string $hash unique hash of the current composer configuration */ - public function __construct(JsonFile $lockFile, RepositoryManager $repositoryManager, $hash) + public function __construct(JsonFile $lockFile, RepositoryManager $repositoryManager, InstallationManager $installationManager, $hash) { $this->lockFile = $lockFile; $this->repositoryManager = $repositoryManager; + $this->installationManager = $installationManager; $this->hash = $hash; } @@ -217,6 +223,13 @@ class Locker if ($package->isDev() && !$alias) { $spec['source-reference'] = $package->getSourceReference(); + if ('git' === $package->getSourceType()) { + $path = $this->installationManager->getInstallPath($package); + $process = new ProcessExecutor(); + if (0 === $process->execute('git log -n1 --pretty=%ct '.escapeshellarg($package->getSourceReference()), $output, $path)) { + $spec['commit-date'] = trim($output); + } + } } if ($alias) {