Path: blob/master/src/applications/diffusion/query/lowlevel/DiffusionLowLevelParentsQuery.php
12242 views
<?php12final class DiffusionLowLevelParentsQuery3extends DiffusionLowLevelQuery {45private $identifier;67public function withIdentifier($identifier) {8$this->identifier = $identifier;9return $this;10}1112protected function executeQuery() {13if (!strlen($this->identifier)) {14throw new PhutilInvalidStateException('withIdentifier');15}1617$type = $this->getRepository()->getVersionControlSystem();18switch ($type) {19case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:20$result = $this->loadGitParents();21break;22case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:23$result = $this->loadMercurialParents();24break;25case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:26$result = $this->loadSubversionParents();27break;28default:29throw new Exception(pht('Unsupported repository type "%s"!', $type));30}3132return $result;33}3435private function loadGitParents() {36$repository = $this->getRepository();3738list($stdout) = $repository->execxLocalCommand(39'log -n 1 %s %s --',40'--format=%P',41gitsprintf('%s', $this->identifier));4243return preg_split('/\s+/', trim($stdout));44}4546private function loadMercurialParents() {47$repository = $this->getRepository();4849$hg_analyzer = PhutilBinaryAnalyzer::getForBinary('hg');50if ($hg_analyzer->isMercurialTemplatePnodeAvailable()) {51$hg_log_template = '{p1.node} {p2.node}';52} else {53$hg_log_template = '{p1node} {p2node}';54}5556list($stdout) = $repository->execxLocalCommand(57'log --limit 1 --template %s --rev %s',58$hg_log_template,59$this->identifier);6061$hashes = preg_split('/\s+/', trim($stdout));62foreach ($hashes as $key => $value) {63// We get 40-character hashes but also get the "000000..." hash for64// missing parents; ignore it.65if (preg_match('/^0+\z/', $value)) {66unset($hashes[$key]);67}68}6970return $hashes;71}7273private function loadSubversionParents() {74$repository = $this->getRepository();75$identifier = $this->identifier;7677$refs = id(new DiffusionCachedResolveRefsQuery())78->setRepository($repository)79->withRefs(array($identifier))80->execute();81if (!$refs) {82throw new Exception(83pht(84'No commit "%s" in this repository.',85$identifier));86}8788$n = (int)$identifier;89if ($n > 1) {90$ids = array($n - 1);91} else {92$ids = array();93}9495return $ids;96}9798}99100101