Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialPathsQuery.php
12242 views
1
<?php
2
3
/**
4
* Execute and parse a low-level Mercurial paths query using `hg locate`.
5
*/
6
final class DiffusionLowLevelMercurialPathsQuery
7
extends DiffusionLowLevelQuery {
8
9
private $commit;
10
private $path;
11
12
public function withCommit($commit) {
13
$this->commit = $commit;
14
return $this;
15
}
16
17
public function withPath($path) {
18
$this->path = $path;
19
return $this;
20
}
21
22
protected function executeQuery() {
23
$repository = $this->getRepository();
24
$path = $this->path;
25
$commit = $this->commit;
26
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';
33
}
34
35
if ($path !== null) {
36
$match_against = trim($path, '/');
37
$prefix = trim('./'.$match_against, '/');
38
} else {
39
$prefix = '.';
40
}
41
list($entire_manifest) = $repository->execxLocalCommand(
42
$hg_paths_command,
43
hgsprintf('%s', $commit),
44
$prefix);
45
return explode("\0", $entire_manifest);
46
}
47
48
}
49
50