Path: blob/master/src/applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialBranchesQuery.php
12242 views
<?php12/**3* Execute and parse a low-level Mercurial branches query using `hg branches`.4*/5final class DiffusionLowLevelMercurialBranchesQuery6extends DiffusionLowLevelQuery {78private $contains;910public function withContainsCommit($commit) {11$this->contains = $commit;12return $this;13}1415protected function executeQuery() {16$repository = $this->getRepository();1718$specs = array();19if ($this->contains !== null) {20$specs['all'] = hgsprintf(21'(descendants(%s) and head())',22$this->contains);23$specs['open'] = hgsprintf(24'(descendants(%s) and head() and not closed())',25$this->contains);26} else {27$specs['all'] = hgsprintf('head()');28$specs['open'] = hgsprintf('head() and not closed()');29}3031$futures = array();32foreach ($specs as $key => $spec) {33$futures[$key] = $repository->getLocalCommandFuture(34'log --template %s --rev %s',35'{node}\1{branch}\2',36$spec);37}3839$branches = array();40$open = array();41foreach (new FutureIterator($futures) as $key => $future) {42list($stdout) = $future->resolvex();4344$lines = explode("\2", $stdout);45$lines = array_filter($lines);46foreach ($lines as $line) {47list($node, $branch) = explode("\1", $line);48$id = $node.'/'.$branch;49if (empty($branches[$id])) {50$branches[$id] = id(new DiffusionRepositoryRef())51->setShortName($branch)52->setCommitIdentifier($node);53}5455if ($key == 'open') {56$open[$id] = true;57}58}59}6061foreach ($branches as $id => $branch) {62$branch->setRawFields(63array(64'closed' => (empty($open[$id])),65));66}6768return array_values($branches);69}7071}727374