1
0
Fork 0

Keep track of commit dates in the lock file in case the reference disappears

pull/812/head
Jordi Boggiano 2012-06-20 11:47:38 +02:00
parent 77f6b9e05b
commit c9ef7479c4
3 changed files with 19 additions and 2 deletions

View File

@ -144,7 +144,7 @@ class Factory
$lockFile = "json" === pathinfo($composerFile, PATHINFO_EXTENSION) $lockFile = "json" === pathinfo($composerFile, PATHINFO_EXTENSION)
? substr($composerFile, 0, -4).'lock' ? substr($composerFile, 0, -4).'lock'
: $composerFile . '.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); $composer->setLocker($locker);
} }

View File

@ -401,6 +401,10 @@ class Installer
$lockData = $this->locker->getLockData(); $lockData = $this->locker->getLockData();
foreach ($lockData['packages'] as $lockedPackage) { foreach ($lockData['packages'] as $lockedPackage) {
if (!empty($lockedPackage['source-reference']) && strtolower($lockedPackage['package']) === $package->getName()) { 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']); $package->setSourceReference($lockedPackage['source-reference']);
break; break;
} }

View File

@ -13,18 +13,22 @@
namespace Composer\Package; namespace Composer\Package;
use Composer\Json\JsonFile; use Composer\Json\JsonFile;
use Composer\Installer\InstallationManager;
use Composer\Repository\RepositoryManager; use Composer\Repository\RepositoryManager;
use Composer\Util\ProcessExecutor;
use Composer\Package\AliasPackage; use Composer\Package\AliasPackage;
/** /**
* Reads/writes project lockfile (composer.lock). * Reads/writes project lockfile (composer.lock).
* *
* @author Konstantin Kudryashiv <ever.zet@gmail.com> * @author Konstantin Kudryashiv <ever.zet@gmail.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
*/ */
class Locker class Locker
{ {
private $lockFile; private $lockFile;
private $repositoryManager; private $repositoryManager;
private $installationManager;
private $hash; private $hash;
private $lockDataCache; private $lockDataCache;
@ -33,12 +37,14 @@ class Locker
* *
* @param JsonFile $lockFile lockfile loader * @param JsonFile $lockFile lockfile loader
* @param RepositoryManager $repositoryManager repository manager instance * @param RepositoryManager $repositoryManager repository manager instance
* @param InstallationManager $installationManager installation manager instance
* @param string $hash unique hash of the current composer configuration * @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->lockFile = $lockFile;
$this->repositoryManager = $repositoryManager; $this->repositoryManager = $repositoryManager;
$this->installationManager = $installationManager;
$this->hash = $hash; $this->hash = $hash;
} }
@ -217,6 +223,13 @@ class Locker
if ($package->isDev() && !$alias) { if ($package->isDev() && !$alias) {
$spec['source-reference'] = $package->getSourceReference(); $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) { if ($alias) {