mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-01 01:18:22 +01:00
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:
parent
d252a78434
commit
b90e51ab0e
4 changed files with 38 additions and 19 deletions
|
@ -496,6 +496,7 @@ phutil_register_library_map(array(
|
|||
'DiffusionLintDetailsController' => 'applications/diffusion/controller/DiffusionLintDetailsController.php',
|
||||
'DiffusionLintSaveRunner' => 'applications/diffusion/DiffusionLintSaveRunner.php',
|
||||
'DiffusionLowLevelGitRefQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelGitRefQuery.php',
|
||||
'DiffusionLowLevelMercurialBranchesQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialBranchesQuery.php',
|
||||
'DiffusionLowLevelQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelQuery.php',
|
||||
'DiffusionMercurialCommitParentsQuery' => 'applications/diffusion/query/parents/DiffusionMercurialCommitParentsQuery.php',
|
||||
'DiffusionMercurialExpandShortNameQuery' => 'applications/diffusion/query/expandshortname/DiffusionMercurialExpandShortNameQuery.php',
|
||||
|
@ -2701,6 +2702,7 @@ phutil_register_library_map(array(
|
|||
'DiffusionLintController' => 'DiffusionController',
|
||||
'DiffusionLintDetailsController' => 'DiffusionController',
|
||||
'DiffusionLowLevelGitRefQuery' => 'DiffusionLowLevelQuery',
|
||||
'DiffusionLowLevelMercurialBranchesQuery' => 'DiffusionLowLevelQuery',
|
||||
'DiffusionLowLevelQuery' => 'Phobject',
|
||||
'DiffusionMercurialCommitParentsQuery' => 'DiffusionCommitParentsQuery',
|
||||
'DiffusionMercurialExpandShortNameQuery' => 'DiffusionExpandShortNameQuery',
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -743,15 +743,12 @@ final class PhabricatorRepositoryPullLocalDaemon
|
|||
|
||||
|
||||
private function executeHgDiscover(PhabricatorRepository $repository) {
|
||||
// NOTE: "--debug" gives us 40-character hashes.
|
||||
list($stdout) = $repository->execxLocalCommand('--debug branches');
|
||||
|
||||
if (!trim($stdout)) {
|
||||
// No branches; likely a newly initialized repository.
|
||||
return false;
|
||||
}
|
||||
$branches = id(new DiffusionLowLevelMercurialBranchesQuery())
|
||||
->setRepository($repository)
|
||||
->execute();
|
||||
$branches = mpull($branches, 'getHeadCommitIdentifier', 'getName');
|
||||
|
||||
$branches = ArcanistMercurialParser::parseMercurialBranches($stdout);
|
||||
$got_something = false;
|
||||
foreach ($branches as $name => $branch) {
|
||||
$commit = $branch['rev'];
|
||||
|
|
Loading…
Add table
Reference in a new issue