@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+34 -88
-4
src/__phutil_library_map__.php
··· 747 747 'DiffusionLowLevelGitRefQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelGitRefQuery.php', 748 748 'DiffusionLowLevelMercurialBranchesQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialBranchesQuery.php', 749 749 'DiffusionLowLevelMercurialPathsQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialPathsQuery.php', 750 - 'DiffusionLowLevelMercurialPathsQueryTests' => 'applications/diffusion/query/lowlevel/__tests__/DiffusionLowLevelMercurialPathsQueryTests.php', 751 750 'DiffusionLowLevelParentsQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelParentsQuery.php', 752 751 'DiffusionLowLevelQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelQuery.php', 753 752 'DiffusionLowLevelResolveRefsQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelResolveRefsQuery.php', ··· 3857 3856 'PhabricatorRepositoryURITransaction' => 'applications/repository/storage/PhabricatorRepositoryURITransaction.php', 3858 3857 'PhabricatorRepositoryURITransactionQuery' => 'applications/repository/query/PhabricatorRepositoryURITransactionQuery.php', 3859 3858 'PhabricatorRepositoryVCSPassword' => 'applications/repository/storage/PhabricatorRepositoryVCSPassword.php', 3860 - 'PhabricatorRepositoryVersion' => 'applications/repository/constants/PhabricatorRepositoryVersion.php', 3861 3859 'PhabricatorRepositoryWorkingCopyVersion' => 'applications/repository/storage/PhabricatorRepositoryWorkingCopyVersion.php', 3862 3860 'PhabricatorRequestExceptionHandler' => 'aphront/handler/PhabricatorRequestExceptionHandler.php', 3863 3861 'PhabricatorResourceSite' => 'aphront/site/PhabricatorResourceSite.php', ··· 5741 5739 'DiffusionLowLevelGitRefQuery' => 'DiffusionLowLevelQuery', 5742 5740 'DiffusionLowLevelMercurialBranchesQuery' => 'DiffusionLowLevelQuery', 5743 5741 'DiffusionLowLevelMercurialPathsQuery' => 'DiffusionLowLevelQuery', 5744 - 'DiffusionLowLevelMercurialPathsQueryTests' => 'PhabricatorTestCase', 5745 5742 'DiffusionLowLevelParentsQuery' => 'DiffusionLowLevelQuery', 5746 5743 'DiffusionLowLevelQuery' => 'Phobject', 5747 5744 'DiffusionLowLevelResolveRefsQuery' => 'DiffusionLowLevelQuery', ··· 9387 9384 'PhabricatorRepositoryURITransaction' => 'PhabricatorApplicationTransaction', 9388 9385 'PhabricatorRepositoryURITransactionQuery' => 'PhabricatorApplicationTransactionQuery', 9389 9386 'PhabricatorRepositoryVCSPassword' => 'PhabricatorRepositoryDAO', 9390 - 'PhabricatorRepositoryVersion' => 'Phobject', 9391 9387 'PhabricatorRepositoryWorkingCopyVersion' => 'PhabricatorRepositoryDAO', 9392 9388 'PhabricatorRequestExceptionHandler' => 'AphrontRequestExceptionHandler', 9393 9389 'PhabricatorResourceSite' => 'PhabricatorSite',
+3 -6
src/applications/config/check/PhabricatorBinariesSetupCheck.php
··· 99 99 continue; 100 100 } 101 101 102 - $version = null; 102 + $version = PhutilBinaryAnalyzer::getForBinary($binary) 103 + ->getBinaryVersion(); 104 + 103 105 switch ($vcs['versionControlSystem']) { 104 106 case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: 105 107 $bad_versions = array(); 106 - list($err, $stdout, $stderr) = exec_manual('git --version'); 107 - $version = trim(substr($stdout, strlen('git version '))); 108 108 break; 109 109 case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: 110 110 $bad_versions = array( ··· 117 117 'for files added in rN (Subversion issue #2873), fixed in 1.7.2.', 118 118 'svn diff -c N'), 119 119 ); 120 - list($err, $stdout, $stderr) = exec_manual('svn --version --quiet'); 121 - $version = trim($stdout); 122 120 break; 123 121 case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: 124 122 $bad_versions = array( ··· 134 132 'in 2.2.1. Pushing fails with this version as well; see %s.', 135 133 'T3046#54922'), 136 134 ); 137 - $version = PhabricatorRepositoryVersion::getMercurialVersion(); 138 135 break; 139 136 } 140 137
+23
src/applications/config/controller/PhabricatorConfigVersionController.php
··· 64 64 $version_from_file); 65 65 } 66 66 67 + $binaries = PhutilBinaryAnalyzer::getAllBinaries(); 68 + foreach ($binaries as $binary) { 69 + if (!$binary->isBinaryAvailable()) { 70 + $binary_info = pht('Not Available'); 71 + } else { 72 + $version = $binary->getBinaryVersion(); 73 + $path = $binary->getBinaryPath(); 74 + if ($path === null && $version === null) { 75 + $binary_info = pht('-'); 76 + } else if ($path === null) { 77 + $binary_info = $version; 78 + } else if ($version === null) { 79 + $binary_info = pht('- at %s', $path); 80 + } else { 81 + $binary_info = pht('%s at %s', $version, $path); 82 + } 83 + } 84 + 85 + $version_property_list->addProperty( 86 + $binary->getBinaryName(), 87 + $binary_info); 88 + } 89 + 67 90 return $version_property_list; 68 91 } 69 92
+5 -4
src/applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialPathsQuery.php
··· 24 24 $path = $this->path; 25 25 $commit = $this->commit; 26 26 27 - $hg_paths_command = 'locate --print0 --rev %s -I %s'; 28 - $hg_version = PhabricatorRepositoryVersion::getMercurialVersion(); 29 - if (PhabricatorRepositoryVersion::isMercurialFilesCommandAvailable( 30 - $hg_version)) { 27 + $has_files = PhutilBinaryAnalyzer::getForBinary('hg') 28 + ->isMercurialFilesCommandAvailable(); 29 + if ($has_files) { 31 30 $hg_paths_command = 'files --print0 --rev %s -I %s'; 31 + } else { 32 + $hg_paths_command = 'locate --print0 --rev %s -I %s'; 32 33 } 33 34 34 35 $match_against = trim($path, '/');
-31
src/applications/diffusion/query/lowlevel/__tests__/DiffusionLowLevelMercurialPathsQueryTests.php
··· 1 - <?php 2 - 3 - final class DiffusionLowLevelMercurialPathsQueryTests 4 - extends PhabricatorTestCase { 5 - 6 - public function testCommandByVersion() { 7 - $cases = array( 8 - array( 9 - 'name' => pht('Versions which should not use `files`'), 10 - 'versions' => array('2.6.2', '2.9', '3.1'), 11 - 'match' => false, 12 - ), 13 - 14 - array( 15 - 'name' => pht('Versions which should use `files`'), 16 - 'versions' => array('3.2', '3.3', '3.5.2'), 17 - 'match' => true, 18 - ), 19 - ); 20 - 21 - foreach ($cases as $case) { 22 - foreach ($case['versions'] as $version) { 23 - $actual = PhabricatorRepositoryVersion 24 - ::isMercurialFilesCommandAvailable($version); 25 - $expect = $case['match']; 26 - $this->assertEqual($expect, $actual, $case['name']); 27 - } 28 - } 29 - } 30 - 31 - }
-40
src/applications/repository/constants/PhabricatorRepositoryVersion.php
··· 1 - <?php 2 - 3 - final class PhabricatorRepositoryVersion extends Phobject { 4 - 5 - public static function getMercurialVersion() { 6 - list($err, $stdout, $stderr) = exec_manual('hg --version --quiet'); 7 - 8 - // NOTE: At least on OSX, recent versions of Mercurial report this 9 - // string in this format: 10 - // 11 - // Mercurial Distributed SCM (version 3.1.1+20140916) 12 - 13 - $matches = null; 14 - $pattern = '/^Mercurial Distributed SCM \(version ([\d.]+)/m'; 15 - if (preg_match($pattern, $stdout, $matches)) { 16 - return $matches[1]; 17 - } 18 - 19 - return null; 20 - } 21 - 22 - /** 23 - * The `locate` command is deprecated as of Mercurial 3.2, to be 24 - * replaced with `files` command, which supports most of the same 25 - * arguments. This determines whether the new `files` command should 26 - * be used instead of the `locate` command. 27 - * 28 - * @param string $mercurial_version - The current version of mercurial 29 - * which can be retrieved by calling: 30 - * PhabricatorRepositoryVersion::getMercurialVersion() 31 - * 32 - * @return boolean True if the version of Mercurial is new enough to support 33 - * the `files` command, or false if otherwise. 34 - */ 35 - public static function isMercurialFilesCommandAvailable($mercurial_version) { 36 - $min_version_for_files = '3.2'; 37 - return version_compare($mercurial_version, $min_version_for_files, '>='); 38 - } 39 - 40 - }
+3 -3
src/applications/repository/engine/PhabricatorRepositoryPullEngine.php
··· 485 485 486 486 // On vulnerable versions of Mercurial, we refuse to clone remotes which 487 487 // contain characters which may be interpreted by the shell. 488 - $hg_version = PhabricatorRepositoryVersion::getMercurialVersion(); 489 - $is_vulnerable = version_compare($hg_version, '3.2.4', '<'); 488 + $hg_binary = PhutilBinaryAnalyzer::getForBinary('hg'); 489 + $is_vulnerable = $hg_binary->isMercurialVulnerableToInjection(); 490 490 if ($is_vulnerable) { 491 491 $cleartext = $remote->openEnvelope(); 492 492 // The use of "%R" here is an attempt to limit collateral damage ··· 501 501 'command injection security vulnerability. The remote URI for '. 502 502 'this repository (%s) is potentially unsafe. Upgrade Mercurial '. 503 503 'to at least 3.2.4 to clone it.', 504 - $hg_version, 504 + $hg_binary->getBinaryVersion(), 505 505 $repository->getMonogram())); 506 506 } 507 507 }