Re-use locker content hash logic to generate dist reference, refs #4515
parent
f0a0ce5e98
commit
6c9b161c43
|
@ -56,12 +56,51 @@ class Locker
|
||||||
$this->repositoryManager = $repositoryManager;
|
$this->repositoryManager = $repositoryManager;
|
||||||
$this->installationManager = $installationManager;
|
$this->installationManager = $installationManager;
|
||||||
$this->hash = md5($composerFileContents);
|
$this->hash = md5($composerFileContents);
|
||||||
$this->contentHash = $this->getContentHash($composerFileContents);
|
$this->contentHash = self::getContentHash($composerFileContents);
|
||||||
$this->loader = new ArrayLoader(null, true);
|
$this->loader = new ArrayLoader(null, true);
|
||||||
$this->dumper = new ArrayDumper();
|
$this->dumper = new ArrayDumper();
|
||||||
$this->process = new ProcessExecutor($io);
|
$this->process = new ProcessExecutor($io);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the md5 hash of the sorted content of the composer file.
|
||||||
|
*
|
||||||
|
* @param string $composerFileContents The contents of the composer file.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getContentHash($composerFileContents)
|
||||||
|
{
|
||||||
|
$content = json_decode($composerFileContents, true);
|
||||||
|
|
||||||
|
$relevantKeys = array(
|
||||||
|
'name',
|
||||||
|
'version',
|
||||||
|
'require',
|
||||||
|
'require-dev',
|
||||||
|
'conflict',
|
||||||
|
'replace',
|
||||||
|
'provide',
|
||||||
|
'minimum-stability',
|
||||||
|
'prefer-stable',
|
||||||
|
'repositories',
|
||||||
|
'extra',
|
||||||
|
);
|
||||||
|
|
||||||
|
$relevantContent = array();
|
||||||
|
|
||||||
|
foreach (array_intersect($relevantKeys, array_keys($content)) as $key) {
|
||||||
|
$relevantContent[$key] = $content[$key];
|
||||||
|
}
|
||||||
|
if (isset($content['config']['platform'])) {
|
||||||
|
$relevantContent['config']['platform'] = $content['config']['platform'];
|
||||||
|
}
|
||||||
|
|
||||||
|
ksort($relevantContent);
|
||||||
|
|
||||||
|
return md5(json_encode($relevantContent));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether locker were been locked (lockfile found).
|
* Checks whether locker were been locked (lockfile found).
|
||||||
*
|
*
|
||||||
|
@ -390,43 +429,4 @@ class Locker
|
||||||
|
|
||||||
return $datetime ? $datetime->format('Y-m-d H:i:s') : null;
|
return $datetime ? $datetime->format('Y-m-d H:i:s') : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the md5 hash of the sorted content of the composer file.
|
|
||||||
*
|
|
||||||
* @param string $composerFileContents The contents of the composer file.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function getContentHash($composerFileContents)
|
|
||||||
{
|
|
||||||
$content = json_decode($composerFileContents, true);
|
|
||||||
|
|
||||||
$relevantKeys = array(
|
|
||||||
'name',
|
|
||||||
'version',
|
|
||||||
'require',
|
|
||||||
'require-dev',
|
|
||||||
'conflict',
|
|
||||||
'replace',
|
|
||||||
'provide',
|
|
||||||
'minimum-stability',
|
|
||||||
'prefer-stable',
|
|
||||||
'repositories',
|
|
||||||
'extra',
|
|
||||||
);
|
|
||||||
|
|
||||||
$relevantContent = array();
|
|
||||||
|
|
||||||
foreach (array_intersect($relevantKeys, array_keys($content)) as $key) {
|
|
||||||
$relevantContent[$key] = $content[$key];
|
|
||||||
}
|
|
||||||
if (isset($content['config']['platform'])) {
|
|
||||||
$relevantContent['config']['platform'] = $content['config']['platform'];
|
|
||||||
}
|
|
||||||
|
|
||||||
ksort($relevantContent);
|
|
||||||
|
|
||||||
return md5(json_encode($relevantContent));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ use Composer\Config;
|
||||||
use Composer\IO\IOInterface;
|
use Composer\IO\IOInterface;
|
||||||
use Composer\Json\JsonFile;
|
use Composer\Json\JsonFile;
|
||||||
use Composer\Package\Loader\ArrayLoader;
|
use Composer\Package\Loader\ArrayLoader;
|
||||||
|
use Composer\Package\Locker;
|
||||||
use Composer\Package\Version\VersionGuesser;
|
use Composer\Package\Version\VersionGuesser;
|
||||||
use Composer\Semver\VersionParser;
|
use Composer\Semver\VersionParser;
|
||||||
use Composer\Util\ProcessExecutor;
|
use Composer\Util\ProcessExecutor;
|
||||||
|
@ -122,7 +123,7 @@ class PathRepository extends ArrayRepository
|
||||||
if (is_dir($path.'/.git') && 0 === $this->process->execute('git log -n1 --pretty=%H', $output, $path)) {
|
if (is_dir($path.'/.git') && 0 === $this->process->execute('git log -n1 --pretty=%H', $output, $path)) {
|
||||||
$package['dist']['reference'] = trim($output);
|
$package['dist']['reference'] = trim($output);
|
||||||
} else {
|
} else {
|
||||||
$package['dist']['reference'] = sha1($json);
|
$package['dist']['reference'] = Locker::getContentHash($json);
|
||||||
}
|
}
|
||||||
|
|
||||||
$package = $this->loader->load($package);
|
$package = $this->loader->load($package);
|
||||||
|
|
Loading…
Reference in New Issue