4 * Execute and parse a low-level Mercurial branches query using `hg branches`.
6 final class DiffusionLowLevelMercurialBranchesQuery
7 extends DiffusionLowLevelQuery
{
11 public function withContainsCommit($commit) {
12 $this->contains
= $commit;
16 protected function executeQuery() {
17 $repository = $this->getRepository();
20 if ($this->contains
!== null) {
21 $specs['all'] = hgsprintf(
22 '(descendants(%s) and head())',
24 $specs['open'] = hgsprintf(
25 '(descendants(%s) and head() and not closed())',
28 $specs['all'] = hgsprintf('head()');
29 $specs['open'] = hgsprintf('head() and not closed()');
33 foreach ($specs as $key => $spec) {
34 $futures[$key] = $repository->getLocalCommandFuture(
35 'log --template %s --rev %s',
42 foreach (new FutureIterator($futures) as $key => $future) {
43 list($stdout) = $future->resolvex();
45 $lines = explode("\2", $stdout);
46 $lines = array_filter($lines);
47 foreach ($lines as $line) {
48 list($node, $branch) = explode("\1", $line);
49 $id = $node.'/'.$branch;
50 if (empty($branches[$id])) {
51 $branches[$id] = id(new DiffusionRepositoryRef())
52 ->setShortName($branch)
53 ->setCommitIdentifier($node);
62 foreach ($branches as $id => $branch) {
63 $branch->setRawFields(
65 'closed' => (empty($open[$id])),
69 return array_values($branches);