Differential D15986 Diff 38488 src/applications/diffusion/query/lowlevel/DiffusionLowLevelGitRefQuery.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/query/lowlevel/DiffusionLowLevelGitRefQuery.php
<?php | <?php | ||||
/** | /** | ||||
* Execute and parse a low-level Git ref query using `git for-each-ref`. This | * Execute and parse a low-level Git ref query using `git for-each-ref`. This | ||||
* is useful for returning a list of tags or branches. | * is useful for returning a list of tags or branches. | ||||
*/ | */ | ||||
final class DiffusionLowLevelGitRefQuery extends DiffusionLowLevelQuery { | final class DiffusionLowLevelGitRefQuery extends DiffusionLowLevelQuery { | ||||
private $isTag; | private $refTypes; | ||||
private $isOriginBranch; | |||||
public function withIsTag($is_tag) { | public function withRefTypes(array $ref_types) { | ||||
$this->isTag = $is_tag; | $this->refTypes = $ref_types; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withIsOriginBranch($is_origin_branch) { | protected function executeQuery() { | ||||
$this->isOriginBranch = $is_origin_branch; | $ref_types = $this->refTypes; | ||||
return $this; | if ($ref_types) { | ||||
$type_branch = PhabricatorRepositoryRefCursor::TYPE_BRANCH; | |||||
$type_tag = PhabricatorRepositoryRefCursor::TYPE_TAG; | |||||
$ref_types = array_fuse($ref_types); | |||||
$with_branches = isset($ref_types[$type_branch]); | |||||
$with_tags = isset($ref_types[$type_tag]); | |||||
} else { | |||||
$with_branches = true; | |||||
$with_tags = true; | |||||
} | } | ||||
protected function executeQuery() { | |||||
$repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
$prefixes = array(); | $prefixes = array(); | ||||
$any = ($this->isTag || $this->isOriginBranch); | if ($with_branches) { | ||||
if (!$any) { | |||||
throw new Exception(pht('Specify types of refs to query.')); | |||||
} | |||||
if ($this->isOriginBranch) { | |||||
if ($repository->isWorkingCopyBare()) { | if ($repository->isWorkingCopyBare()) { | ||||
$prefix = 'refs/heads/'; | $prefix = 'refs/heads/'; | ||||
} else { | } else { | ||||
$remote = DiffusionGitBranch::DEFAULT_GIT_REMOTE; | $remote = DiffusionGitBranch::DEFAULT_GIT_REMOTE; | ||||
$prefix = 'refs/remotes/'.$remote.'/'; | $prefix = 'refs/remotes/'.$remote.'/'; | ||||
} | } | ||||
$prefixes[] = $prefix; | $prefixes[] = $prefix; | ||||
} | } | ||||
if ($this->isTag) { | if ($with_tags) { | ||||
$prefixes[] = 'refs/tags/'; | $prefixes[] = 'refs/tags/'; | ||||
} | } | ||||
$order = '-creatordate'; | $order = '-creatordate'; | ||||
$futures = array(); | $futures = array(); | ||||
foreach ($prefixes as $prefix) { | foreach ($prefixes as $prefix) { | ||||
$futures[$prefix] = $repository->getLocalCommandFuture( | $futures[$prefix] = $repository->getLocalCommandFuture( | ||||
▲ Show 20 Lines • Show All 102 Lines • Show Last 20 Lines |