diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -607,6 +607,7 @@ 'DiffusionLowLevelGitRefQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelGitRefQuery.php', 'DiffusionLowLevelMercurialBranchesQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialBranchesQuery.php', 'DiffusionLowLevelMercurialPathsQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialPathsQuery.php', + 'DiffusionLowLevelMercurialPathsQueryTests' => 'applications/diffusion/query/lowlevel/__tests__/DiffusionLowLevelMercurialPathsQueryTests.php', 'DiffusionLowLevelParentsQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelParentsQuery.php', 'DiffusionLowLevelQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelQuery.php', 'DiffusionLowLevelResolveRefsQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelResolveRefsQuery.php', @@ -4342,6 +4343,7 @@ 'DiffusionLowLevelGitRefQuery' => 'DiffusionLowLevelQuery', 'DiffusionLowLevelMercurialBranchesQuery' => 'DiffusionLowLevelQuery', 'DiffusionLowLevelMercurialPathsQuery' => 'DiffusionLowLevelQuery', + 'DiffusionLowLevelMercurialPathsQueryTests' => 'PhabricatorTestCase', 'DiffusionLowLevelParentsQuery' => 'DiffusionLowLevelQuery', 'DiffusionLowLevelQuery' => 'Phobject', 'DiffusionLowLevelResolveRefsQuery' => 'DiffusionLowLevelQuery', diff --git a/src/applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialPathsQuery.php b/src/applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialPathsQuery.php --- a/src/applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialPathsQuery.php +++ b/src/applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialPathsQuery.php @@ -24,10 +24,17 @@ $path = $this->path; $commit = $this->commit; + $hg_paths_command = 'locate --print0 --rev %s -I %s'; + $hg_version = PhabricatorRepositoryVersion::getMercurialVersion(); + if (PhabricatorRepositoryVersion::isMercurialFilesCommandAvailable( + $hg_version)) { + $hg_paths_command = 'files --print0 --rev %s -I %s'; + } + $match_against = trim($path, '/'); $prefix = trim('./'.$match_against, '/'); list($entire_manifest) = $repository->execxLocalCommand( - 'locate --print0 --rev %s -I %s', + $hg_paths_command, hgsprintf('%s', $commit), $prefix); return explode("\0", $entire_manifest); diff --git a/src/applications/diffusion/query/lowlevel/__tests__/DiffusionLowLevelMercurialPathsQueryTests.php b/src/applications/diffusion/query/lowlevel/__tests__/DiffusionLowLevelMercurialPathsQueryTests.php new file mode 100644 --- /dev/null +++ b/src/applications/diffusion/query/lowlevel/__tests__/DiffusionLowLevelMercurialPathsQueryTests.php @@ -0,0 +1,31 @@ + 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']); + } + } + } + +} diff --git a/src/applications/multimeter/data/MultimeterControl.php b/src/applications/multimeter/data/MultimeterControl.php --- a/src/applications/multimeter/data/MultimeterControl.php +++ b/src/applications/multimeter/data/MultimeterControl.php @@ -265,6 +265,7 @@ 'init' => true, 'diff' => true, 'cat' => true, + 'files' => true, ), 'svnadmin' => array( 'create' => true, diff --git a/src/applications/repository/constants/PhabricatorRepositoryVersion.php b/src/applications/repository/constants/PhabricatorRepositoryVersion.php --- a/src/applications/repository/constants/PhabricatorRepositoryVersion.php +++ b/src/applications/repository/constants/PhabricatorRepositoryVersion.php @@ -19,4 +19,22 @@ 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, '>='); + } + }