mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
Only resolve branch names to branches
Summary: Fixes T7100. In the bizarre case that a Git repository has a branch and tag with the same name, don't resolve branch names into tag names. Test Plan: Test repo with branch and tag both named "git" no longer reports ambiguity. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T7100 Differential Revision: https://secure.phabricator.com/D12553
This commit is contained in:
parent
d3436c256c
commit
2a37459a5f
5 changed files with 62 additions and 8 deletions
|
@ -18,16 +18,23 @@ final class DiffusionResolveRefsConduitAPIMethod
|
|||
protected function defineCustomParamTypes() {
|
||||
return array(
|
||||
'refs' => 'required list<string>',
|
||||
'types' => 'optional list<string>',
|
||||
);
|
||||
}
|
||||
|
||||
protected function getResult(ConduitAPIRequest $request) {
|
||||
$refs = $request->getValue('refs');
|
||||
$types = $request->getValue('types');
|
||||
|
||||
return id(new DiffusionLowLevelResolveRefsQuery())
|
||||
$query = id(new DiffusionLowLevelResolveRefsQuery())
|
||||
->setRepository($this->getDiffusionRequest()->getRepository())
|
||||
->withRefs($refs)
|
||||
->execute();
|
||||
->withRefs($refs);
|
||||
|
||||
if ($types) {
|
||||
$query->withTypes($types);
|
||||
}
|
||||
|
||||
return $query->execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,12 +16,18 @@ final class DiffusionCachedResolveRefsQuery
|
|||
extends DiffusionLowLevelQuery {
|
||||
|
||||
private $refs;
|
||||
private $types;
|
||||
|
||||
public function withRefs(array $refs) {
|
||||
$this->refs = $refs;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withTypes(array $types) {
|
||||
$this->types = $types;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function executeQuery() {
|
||||
if (!$this->refs) {
|
||||
return array();
|
||||
|
@ -39,6 +45,10 @@ final class DiffusionCachedResolveRefsQuery
|
|||
throw new Exception('Unsupported repository type!');
|
||||
}
|
||||
|
||||
if ($this->types !== null) {
|
||||
$result = $this->filterRefsByType($result, $this->types);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,4 +23,21 @@ abstract class DiffusionLowLevelQuery extends Phobject {
|
|||
return $this->executeQuery();
|
||||
}
|
||||
|
||||
protected function filterRefsByType(array $refs, array $types) {
|
||||
$type_map = array_fuse($types);
|
||||
|
||||
foreach ($refs as $name => $ref_list) {
|
||||
foreach ($ref_list as $key => $ref) {
|
||||
if (empty($type_map[$ref['type']])) {
|
||||
unset($refs[$name][$key]);
|
||||
}
|
||||
}
|
||||
if (!$refs[$name]) {
|
||||
unset($refs[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
return $refs;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,12 +14,18 @@ final class DiffusionLowLevelResolveRefsQuery
|
|||
extends DiffusionLowLevelQuery {
|
||||
|
||||
private $refs;
|
||||
private $types;
|
||||
|
||||
public function withRefs(array $refs) {
|
||||
$this->refs = $refs;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withTypes(array $types) {
|
||||
$this->types = $types;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function executeQuery() {
|
||||
if (!$this->refs) {
|
||||
return array();
|
||||
|
@ -39,6 +45,10 @@ final class DiffusionLowLevelResolveRefsQuery
|
|||
throw new Exception('Unsupported repository type!');
|
||||
}
|
||||
|
||||
if ($this->types !== null) {
|
||||
$result = $this->filterRefsByType($result, $this->types);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
|
|
@ -718,17 +718,21 @@ abstract class DiffusionRequest {
|
|||
}
|
||||
|
||||
private function queryStableCommit() {
|
||||
$types = array();
|
||||
if ($this->symbolicCommit) {
|
||||
$ref = $this->symbolicCommit;
|
||||
} else {
|
||||
if ($this->supportsBranches()) {
|
||||
$ref = $this->getResolvableBranchName($this->getBranch());
|
||||
$types = array(
|
||||
PhabricatorRepositoryRefCursor::TYPE_BRANCH,
|
||||
);
|
||||
} else {
|
||||
$ref = 'HEAD';
|
||||
}
|
||||
}
|
||||
|
||||
$results = $this->resolveRefs(array($ref));
|
||||
$results = $this->resolveRefs(array($ref), $types);
|
||||
|
||||
$matches = idx($results, $ref, array());
|
||||
if (!$matches) {
|
||||
|
@ -790,12 +794,17 @@ abstract class DiffusionRequest {
|
|||
return $branch;
|
||||
}
|
||||
|
||||
private function resolveRefs(array $refs) {
|
||||
private function resolveRefs(array $refs, array $types) {
|
||||
// First, try to resolve refs from fast cache sources.
|
||||
$cached_results = id(new DiffusionCachedResolveRefsQuery())
|
||||
$cached_query = id(new DiffusionCachedResolveRefsQuery())
|
||||
->setRepository($this->getRepository())
|
||||
->withRefs($refs)
|
||||
->execute();
|
||||
->withRefs($refs);
|
||||
|
||||
if ($types) {
|
||||
$cached_query->withTypes($types);
|
||||
}
|
||||
|
||||
$cached_results = $cached_query->execute();
|
||||
|
||||
// Throw away all the refs we resolved. Hopefully, we'll throw away
|
||||
// everything here.
|
||||
|
@ -813,6 +822,7 @@ abstract class DiffusionRequest {
|
|||
$this,
|
||||
'diffusion.resolverefs',
|
||||
array(
|
||||
'types' => $types,
|
||||
'refs' => $refs,
|
||||
));
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue