3 final class DiffusionLowLevelParentsQuery
4 extends DiffusionLowLevelQuery
{
8 public function withIdentifier($identifier) {
9 $this->identifier
= $identifier;
13 protected function executeQuery() {
14 if (!strlen($this->identifier
)) {
15 throw new PhutilInvalidStateException('withIdentifier');
18 $type = $this->getRepository()->getVersionControlSystem();
20 case PhabricatorRepositoryType
::REPOSITORY_TYPE_GIT
:
21 $result = $this->loadGitParents();
23 case PhabricatorRepositoryType
::REPOSITORY_TYPE_MERCURIAL
:
24 $result = $this->loadMercurialParents();
26 case PhabricatorRepositoryType
::REPOSITORY_TYPE_SVN
:
27 $result = $this->loadSubversionParents();
30 throw new Exception(pht('Unsupported repository type "%s"!', $type));
36 private function loadGitParents() {
37 $repository = $this->getRepository();
39 list($stdout) = $repository->execxLocalCommand(
42 gitsprintf('%s', $this->identifier
));
44 return preg_split('/\s+/', trim($stdout));
47 private function loadMercurialParents() {
48 $repository = $this->getRepository();
50 $hg_analyzer = PhutilBinaryAnalyzer
::getForBinary('hg');
51 if ($hg_analyzer->isMercurialTemplatePnodeAvailable()) {
52 $hg_log_template = '{p1.node} {p2.node}';
54 $hg_log_template = '{p1node} {p2node}';
57 list($stdout) = $repository->execxLocalCommand(
58 'log --limit 1 --template %s --rev %s',
62 $hashes = preg_split('/\s+/', trim($stdout));
63 foreach ($hashes as $key => $value) {
64 // We get 40-character hashes but also get the "000000..." hash for
65 // missing parents; ignore it.
66 if (preg_match('/^0+\z/', $value)) {
74 private function loadSubversionParents() {
75 $repository = $this->getRepository();
76 $identifier = $this->identifier
;
78 $refs = id(new DiffusionCachedResolveRefsQuery())
79 ->setRepository($repository)
80 ->withRefs(array($identifier))
85 'No commit "%s" in this repository.',
89 $n = (int)$identifier;