Clean up hg --debug branches calls

Summary: Ref T1493. Consolidate these a bit; they might need some more magic once we do `--noupdate` checkouts. Mostly just trying to clean up and centralize this code a bit.

Test Plan: Viewed and `bin/repository discover`'d Mercurial repos with and without any branches.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1493

Differential Revision: https://secure.phabricator.com/D7480
This commit is contained in:
epriestley
2013-11-04 12:15:32 -08:00
parent d252a78434
commit b90e51ab0e
4 changed files with 38 additions and 19 deletions

View File

@@ -65,17 +65,9 @@ final class ConduitAPI_diffusion_branchquery_Method
$offset = $request->getValue('offset');
$limit = $request->getValue('limit');
list($stdout) = $repository->execxLocalCommand(
'--debug branches');
$branch_info = ArcanistMercurialParser::parseMercurialBranches($stdout);
$branches = array();
foreach ($branch_info as $name => $info) {
$branch = new DiffusionBranchInformation();
$branch->setName($name);
$branch->setHeadCommitIdentifier($info['rev']);
$branches[] = $branch->toDictionary();
}
$branches = id(new DiffusionLowLevelMercurialBranchesQuery())
->setRepository($repository)
->execute();
if ($offset) {
$branches = array_slice($branches, $offset);
@@ -85,6 +77,6 @@ final class ConduitAPI_diffusion_branchquery_Method
$branches = array_slice($branches, 0, $limit);
}
return $branches;
return mpull($branches, 'toDictionary');
}
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Execute and parse a low-level Mercurial branches query using `hg branches`.
*/
final class DiffusionLowLevelMercurialBranchesQuery
extends DiffusionLowLevelQuery {
protected function executeQuery() {
$repository = $this->getRepository();
// NOTE: `--debug` gives us 40-character hashes.
list($stdout) = $repository->execxLocalCommand(
'--debug branches');
$branches = array();
$lines = ArcanistMercurialParser::parseMercurialBranches($stdout);
foreach ($lines as $name => $spec) {
$branches[] = id(new DiffusionBranchInformation())
->setName($name)
->setHeadCommitIdentifier($spec['rev']);
}
return $branches;
}
}