mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 14:52:41 +01:00
Move Phabricator to use PhutilBinaryAnalyzer and show binary versions
Summary: Fixes T12942. - Adds binary version and path information to {nav Config > Version Information}. - Replaces old code all over the place with new consolidated code. Test Plan: {F5073531} Also faked some cases of missing binaries, bad versions, etc. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12942 Differential Revision: https://secure.phabricator.com/D18306
This commit is contained in:
parent
a546b029b0
commit
f48f2dae9f
7 changed files with 34 additions and 88 deletions
|
@ -747,7 +747,6 @@ phutil_register_library_map(array(
|
||||||
'DiffusionLowLevelGitRefQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelGitRefQuery.php',
|
'DiffusionLowLevelGitRefQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelGitRefQuery.php',
|
||||||
'DiffusionLowLevelMercurialBranchesQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialBranchesQuery.php',
|
'DiffusionLowLevelMercurialBranchesQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialBranchesQuery.php',
|
||||||
'DiffusionLowLevelMercurialPathsQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialPathsQuery.php',
|
'DiffusionLowLevelMercurialPathsQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialPathsQuery.php',
|
||||||
'DiffusionLowLevelMercurialPathsQueryTests' => 'applications/diffusion/query/lowlevel/__tests__/DiffusionLowLevelMercurialPathsQueryTests.php',
|
|
||||||
'DiffusionLowLevelParentsQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelParentsQuery.php',
|
'DiffusionLowLevelParentsQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelParentsQuery.php',
|
||||||
'DiffusionLowLevelQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelQuery.php',
|
'DiffusionLowLevelQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelQuery.php',
|
||||||
'DiffusionLowLevelResolveRefsQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelResolveRefsQuery.php',
|
'DiffusionLowLevelResolveRefsQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelResolveRefsQuery.php',
|
||||||
|
@ -3857,7 +3856,6 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorRepositoryURITransaction' => 'applications/repository/storage/PhabricatorRepositoryURITransaction.php',
|
'PhabricatorRepositoryURITransaction' => 'applications/repository/storage/PhabricatorRepositoryURITransaction.php',
|
||||||
'PhabricatorRepositoryURITransactionQuery' => 'applications/repository/query/PhabricatorRepositoryURITransactionQuery.php',
|
'PhabricatorRepositoryURITransactionQuery' => 'applications/repository/query/PhabricatorRepositoryURITransactionQuery.php',
|
||||||
'PhabricatorRepositoryVCSPassword' => 'applications/repository/storage/PhabricatorRepositoryVCSPassword.php',
|
'PhabricatorRepositoryVCSPassword' => 'applications/repository/storage/PhabricatorRepositoryVCSPassword.php',
|
||||||
'PhabricatorRepositoryVersion' => 'applications/repository/constants/PhabricatorRepositoryVersion.php',
|
|
||||||
'PhabricatorRepositoryWorkingCopyVersion' => 'applications/repository/storage/PhabricatorRepositoryWorkingCopyVersion.php',
|
'PhabricatorRepositoryWorkingCopyVersion' => 'applications/repository/storage/PhabricatorRepositoryWorkingCopyVersion.php',
|
||||||
'PhabricatorRequestExceptionHandler' => 'aphront/handler/PhabricatorRequestExceptionHandler.php',
|
'PhabricatorRequestExceptionHandler' => 'aphront/handler/PhabricatorRequestExceptionHandler.php',
|
||||||
'PhabricatorResourceSite' => 'aphront/site/PhabricatorResourceSite.php',
|
'PhabricatorResourceSite' => 'aphront/site/PhabricatorResourceSite.php',
|
||||||
|
@ -5741,7 +5739,6 @@ phutil_register_library_map(array(
|
||||||
'DiffusionLowLevelGitRefQuery' => 'DiffusionLowLevelQuery',
|
'DiffusionLowLevelGitRefQuery' => 'DiffusionLowLevelQuery',
|
||||||
'DiffusionLowLevelMercurialBranchesQuery' => 'DiffusionLowLevelQuery',
|
'DiffusionLowLevelMercurialBranchesQuery' => 'DiffusionLowLevelQuery',
|
||||||
'DiffusionLowLevelMercurialPathsQuery' => 'DiffusionLowLevelQuery',
|
'DiffusionLowLevelMercurialPathsQuery' => 'DiffusionLowLevelQuery',
|
||||||
'DiffusionLowLevelMercurialPathsQueryTests' => 'PhabricatorTestCase',
|
|
||||||
'DiffusionLowLevelParentsQuery' => 'DiffusionLowLevelQuery',
|
'DiffusionLowLevelParentsQuery' => 'DiffusionLowLevelQuery',
|
||||||
'DiffusionLowLevelQuery' => 'Phobject',
|
'DiffusionLowLevelQuery' => 'Phobject',
|
||||||
'DiffusionLowLevelResolveRefsQuery' => 'DiffusionLowLevelQuery',
|
'DiffusionLowLevelResolveRefsQuery' => 'DiffusionLowLevelQuery',
|
||||||
|
@ -9387,7 +9384,6 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorRepositoryURITransaction' => 'PhabricatorApplicationTransaction',
|
'PhabricatorRepositoryURITransaction' => 'PhabricatorApplicationTransaction',
|
||||||
'PhabricatorRepositoryURITransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
'PhabricatorRepositoryURITransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||||
'PhabricatorRepositoryVCSPassword' => 'PhabricatorRepositoryDAO',
|
'PhabricatorRepositoryVCSPassword' => 'PhabricatorRepositoryDAO',
|
||||||
'PhabricatorRepositoryVersion' => 'Phobject',
|
|
||||||
'PhabricatorRepositoryWorkingCopyVersion' => 'PhabricatorRepositoryDAO',
|
'PhabricatorRepositoryWorkingCopyVersion' => 'PhabricatorRepositoryDAO',
|
||||||
'PhabricatorRequestExceptionHandler' => 'AphrontRequestExceptionHandler',
|
'PhabricatorRequestExceptionHandler' => 'AphrontRequestExceptionHandler',
|
||||||
'PhabricatorResourceSite' => 'PhabricatorSite',
|
'PhabricatorResourceSite' => 'PhabricatorSite',
|
||||||
|
|
|
@ -99,12 +99,12 @@ final class PhabricatorBinariesSetupCheck extends PhabricatorSetupCheck {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$version = null;
|
$version = PhutilBinaryAnalyzer::getForBinary($binary)
|
||||||
|
->getBinaryVersion();
|
||||||
|
|
||||||
switch ($vcs['versionControlSystem']) {
|
switch ($vcs['versionControlSystem']) {
|
||||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
|
||||||
$bad_versions = array();
|
$bad_versions = array();
|
||||||
list($err, $stdout, $stderr) = exec_manual('git --version');
|
|
||||||
$version = trim(substr($stdout, strlen('git version ')));
|
|
||||||
break;
|
break;
|
||||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
|
||||||
$bad_versions = array(
|
$bad_versions = array(
|
||||||
|
@ -117,8 +117,6 @@ final class PhabricatorBinariesSetupCheck extends PhabricatorSetupCheck {
|
||||||
'for files added in rN (Subversion issue #2873), fixed in 1.7.2.',
|
'for files added in rN (Subversion issue #2873), fixed in 1.7.2.',
|
||||||
'svn diff -c N'),
|
'svn diff -c N'),
|
||||||
);
|
);
|
||||||
list($err, $stdout, $stderr) = exec_manual('svn --version --quiet');
|
|
||||||
$version = trim($stdout);
|
|
||||||
break;
|
break;
|
||||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
|
||||||
$bad_versions = array(
|
$bad_versions = array(
|
||||||
|
@ -134,7 +132,6 @@ final class PhabricatorBinariesSetupCheck extends PhabricatorSetupCheck {
|
||||||
'in 2.2.1. Pushing fails with this version as well; see %s.',
|
'in 2.2.1. Pushing fails with this version as well; see %s.',
|
||||||
'T3046#54922'),
|
'T3046#54922'),
|
||||||
);
|
);
|
||||||
$version = PhabricatorRepositoryVersion::getMercurialVersion();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,29 @@ final class PhabricatorConfigVersionController
|
||||||
$version_from_file);
|
$version_from_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$binaries = PhutilBinaryAnalyzer::getAllBinaries();
|
||||||
|
foreach ($binaries as $binary) {
|
||||||
|
if (!$binary->isBinaryAvailable()) {
|
||||||
|
$binary_info = pht('Not Available');
|
||||||
|
} else {
|
||||||
|
$version = $binary->getBinaryVersion();
|
||||||
|
$path = $binary->getBinaryPath();
|
||||||
|
if ($path === null && $version === null) {
|
||||||
|
$binary_info = pht('-');
|
||||||
|
} else if ($path === null) {
|
||||||
|
$binary_info = $version;
|
||||||
|
} else if ($version === null) {
|
||||||
|
$binary_info = pht('- at %s', $path);
|
||||||
|
} else {
|
||||||
|
$binary_info = pht('%s at %s', $version, $path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$version_property_list->addProperty(
|
||||||
|
$binary->getBinaryName(),
|
||||||
|
$binary_info);
|
||||||
|
}
|
||||||
|
|
||||||
return $version_property_list;
|
return $version_property_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,11 +24,12 @@ final class DiffusionLowLevelMercurialPathsQuery
|
||||||
$path = $this->path;
|
$path = $this->path;
|
||||||
$commit = $this->commit;
|
$commit = $this->commit;
|
||||||
|
|
||||||
$hg_paths_command = 'locate --print0 --rev %s -I %s';
|
$has_files = PhutilBinaryAnalyzer::getForBinary('hg')
|
||||||
$hg_version = PhabricatorRepositoryVersion::getMercurialVersion();
|
->isMercurialFilesCommandAvailable();
|
||||||
if (PhabricatorRepositoryVersion::isMercurialFilesCommandAvailable(
|
if ($has_files) {
|
||||||
$hg_version)) {
|
|
||||||
$hg_paths_command = 'files --print0 --rev %s -I %s';
|
$hg_paths_command = 'files --print0 --rev %s -I %s';
|
||||||
|
} else {
|
||||||
|
$hg_paths_command = 'locate --print0 --rev %s -I %s';
|
||||||
}
|
}
|
||||||
|
|
||||||
$match_against = trim($path, '/');
|
$match_against = trim($path, '/');
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
final class DiffusionLowLevelMercurialPathsQueryTests
|
|
||||||
extends PhabricatorTestCase {
|
|
||||||
|
|
||||||
public function testCommandByVersion() {
|
|
||||||
$cases = array(
|
|
||||||
array(
|
|
||||||
'name' => pht('Versions which should not use `files`'),
|
|
||||||
'versions' => array('2.6.2', '2.9', '3.1'),
|
|
||||||
'match' => false,
|
|
||||||
),
|
|
||||||
|
|
||||||
array(
|
|
||||||
'name' => pht('Versions which should use `files`'),
|
|
||||||
'versions' => array('3.2', '3.3', '3.5.2'),
|
|
||||||
'match' => true,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($cases as $case) {
|
|
||||||
foreach ($case['versions'] as $version) {
|
|
||||||
$actual = PhabricatorRepositoryVersion
|
|
||||||
::isMercurialFilesCommandAvailable($version);
|
|
||||||
$expect = $case['match'];
|
|
||||||
$this->assertEqual($expect, $actual, $case['name']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
final class PhabricatorRepositoryVersion extends Phobject {
|
|
||||||
|
|
||||||
public static function getMercurialVersion() {
|
|
||||||
list($err, $stdout, $stderr) = exec_manual('hg --version --quiet');
|
|
||||||
|
|
||||||
// NOTE: At least on OSX, recent versions of Mercurial report this
|
|
||||||
// string in this format:
|
|
||||||
//
|
|
||||||
// Mercurial Distributed SCM (version 3.1.1+20140916)
|
|
||||||
|
|
||||||
$matches = null;
|
|
||||||
$pattern = '/^Mercurial Distributed SCM \(version ([\d.]+)/m';
|
|
||||||
if (preg_match($pattern, $stdout, $matches)) {
|
|
||||||
return $matches[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The `locate` command is deprecated as of Mercurial 3.2, to be
|
|
||||||
* replaced with `files` command, which supports most of the same
|
|
||||||
* arguments. This determines whether the new `files` command should
|
|
||||||
* be used instead of the `locate` command.
|
|
||||||
*
|
|
||||||
* @param string $mercurial_version - The current version of mercurial
|
|
||||||
* which can be retrieved by calling:
|
|
||||||
* PhabricatorRepositoryVersion::getMercurialVersion()
|
|
||||||
*
|
|
||||||
* @return boolean True if the version of Mercurial is new enough to support
|
|
||||||
* the `files` command, or false if otherwise.
|
|
||||||
*/
|
|
||||||
public static function isMercurialFilesCommandAvailable($mercurial_version) {
|
|
||||||
$min_version_for_files = '3.2';
|
|
||||||
return version_compare($mercurial_version, $min_version_for_files, '>=');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -485,8 +485,8 @@ final class PhabricatorRepositoryPullEngine
|
||||||
|
|
||||||
// On vulnerable versions of Mercurial, we refuse to clone remotes which
|
// On vulnerable versions of Mercurial, we refuse to clone remotes which
|
||||||
// contain characters which may be interpreted by the shell.
|
// contain characters which may be interpreted by the shell.
|
||||||
$hg_version = PhabricatorRepositoryVersion::getMercurialVersion();
|
$hg_binary = PhutilBinaryAnalyzer::getForBinary('hg');
|
||||||
$is_vulnerable = version_compare($hg_version, '3.2.4', '<');
|
$is_vulnerable = $hg_binary->isMercurialVulnerableToInjection();
|
||||||
if ($is_vulnerable) {
|
if ($is_vulnerable) {
|
||||||
$cleartext = $remote->openEnvelope();
|
$cleartext = $remote->openEnvelope();
|
||||||
// The use of "%R" here is an attempt to limit collateral damage
|
// The use of "%R" here is an attempt to limit collateral damage
|
||||||
|
@ -501,7 +501,7 @@ final class PhabricatorRepositoryPullEngine
|
||||||
'command injection security vulnerability. The remote URI for '.
|
'command injection security vulnerability. The remote URI for '.
|
||||||
'this repository (%s) is potentially unsafe. Upgrade Mercurial '.
|
'this repository (%s) is potentially unsafe. Upgrade Mercurial '.
|
||||||
'to at least 3.2.4 to clone it.',
|
'to at least 3.2.4 to clone it.',
|
||||||
$hg_version,
|
$hg_binary->getBinaryVersion(),
|
||||||
$repository->getMonogram()));
|
$repository->getMonogram()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue