@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.

Conditionally use `hg files` vs. `hg locate` depending on version of Mercurial

Summary:
In Mercurial 3.2 the `locate` command was deprecated in favor of `files` command. This change updates the DiffusionLowLevelMercurialPathsQuery command to conditionally use `locate` or `files` based on the version of Mercurial used.

Closes T7375

Test Plan:
My test/develop Phabricator instance is setup to run Mercurial 3.5.1.

The test procedure to verify valid file listings are being returned:
1. I navigated to `http://192.168.0.133/conduit/method/diffusion.querypaths/`
2. I populated the following fields:
- path: `"/"`
- commit: `"d721d5b57fc9ef72e47ff9d4e0c583d74a46590c"`
- callsign: `"HGTEST"`
3. I submitted request and verified that result contained all files in the repository:
```
{
"0": "README",
"1": "alpha/beta/trifle",
"2": "test/Chupacabra.cow",
"3": "test/socket.ks"
}
```

I repeated the above steps after setting up Mercurial 2.6.2, which I installed in the following manner:
1. I downloaded Mercurial 2.6.2 source and run `make local` which will only compile it to work from its own directory (`/opt/mercurial-2.6.2`)
2. I linked `/usr/local/bin/hg -> /opt/mercurial-2.6.2/hg` (there's also a `/usr/bin/hg` which is a link to `/usr/local/bin/hg`)
3. I navigated to my home directory and verify that `hg --version` returns 2.6.2.
4. I restarted phabricator services (probably unnecessary).

With the Multimeter application active
1. I verified that `/usr/local/bin/hg` referred to version 2.6
2. I ran the same conduit call from the conduit application
3. I verified that `http://192.168.0.133/multimeter/?type=2&group=label` incremented values for `bin.hg locate`.
4. I swapped out mercurial versions for 3.5.1
5. I ran the same conduit call from the conduit application
6. I verified that `http://192.168.0.133/multimeter/?type=2&group=label` incremented values for `bin.hg files`

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin

Maniphest Tasks: T7375

Differential Revision: https://secure.phabricator.com/D14253

authored by

Christopher Speck and committed by
epriestley
812c41a1 cd8be810

+60 -1
+2
src/__phutil_library_map__.php
··· 607 607 'DiffusionLowLevelGitRefQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelGitRefQuery.php', 608 608 'DiffusionLowLevelMercurialBranchesQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialBranchesQuery.php', 609 609 'DiffusionLowLevelMercurialPathsQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialPathsQuery.php', 610 + 'DiffusionLowLevelMercurialPathsQueryTests' => 'applications/diffusion/query/lowlevel/__tests__/DiffusionLowLevelMercurialPathsQueryTests.php', 610 611 'DiffusionLowLevelParentsQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelParentsQuery.php', 611 612 'DiffusionLowLevelQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelQuery.php', 612 613 'DiffusionLowLevelResolveRefsQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelResolveRefsQuery.php', ··· 4342 4343 'DiffusionLowLevelGitRefQuery' => 'DiffusionLowLevelQuery', 4343 4344 'DiffusionLowLevelMercurialBranchesQuery' => 'DiffusionLowLevelQuery', 4344 4345 'DiffusionLowLevelMercurialPathsQuery' => 'DiffusionLowLevelQuery', 4346 + 'DiffusionLowLevelMercurialPathsQueryTests' => 'PhabricatorTestCase', 4345 4347 'DiffusionLowLevelParentsQuery' => 'DiffusionLowLevelQuery', 4346 4348 'DiffusionLowLevelQuery' => 'Phobject', 4347 4349 'DiffusionLowLevelResolveRefsQuery' => 'DiffusionLowLevelQuery',
+8 -1
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)) { 31 + $hg_paths_command = 'files --print0 --rev %s -I %s'; 32 + } 33 + 27 34 $match_against = trim($path, '/'); 28 35 $prefix = trim('./'.$match_against, '/'); 29 36 list($entire_manifest) = $repository->execxLocalCommand( 30 - 'locate --print0 --rev %s -I %s', 37 + $hg_paths_command, 31 38 hgsprintf('%s', $commit), 32 39 $prefix); 33 40 return explode("\0", $entire_manifest);
+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 + }
+1
src/applications/multimeter/data/MultimeterControl.php
··· 265 265 'init' => true, 266 266 'diff' => true, 267 267 'cat' => true, 268 + 'files' => true, 268 269 ), 269 270 'svnadmin' => array( 270 271 'create' => true,
+18
src/applications/repository/constants/PhabricatorRepositoryVersion.php
··· 19 19 return null; 20 20 } 21 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 + 22 40 }