Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / diffusion / query / lowlevel / DiffusionLowLevelMercurialPathsQuery.php
blob96b1ae239d5dfe816ff7d5aa71d929659794ae90
1 <?php
3 /**
4 * Execute and parse a low-level Mercurial paths query using `hg locate`.
5 */
6 final class DiffusionLowLevelMercurialPathsQuery
7 extends DiffusionLowLevelQuery {
9 private $commit;
10 private $path;
12 public function withCommit($commit) {
13 $this->commit = $commit;
14 return $this;
17 public function withPath($path) {
18 $this->path = $path;
19 return $this;
22 protected function executeQuery() {
23 $repository = $this->getRepository();
24 $path = $this->path;
25 $commit = $this->commit;
27 $has_files = PhutilBinaryAnalyzer::getForBinary('hg')
28 ->isMercurialFilesCommandAvailable();
29 if ($has_files) {
30 $hg_paths_command = 'files --print0 --rev %s -I %s';
31 } else {
32 $hg_paths_command = 'locate --print0 --rev %s -I %s';
35 if ($path !== null) {
36 $match_against = trim($path, '/');
37 $prefix = trim('./'.$match_against, '/');
38 } else {
39 $prefix = '.';
41 list($entire_manifest) = $repository->execxLocalCommand(
42 $hg_paths_command,
43 hgsprintf('%s', $commit),
44 $prefix);
45 return explode("\0", $entire_manifest);