1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-21 11:09:02 +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:
epriestley 2015-04-27 03:51:53 -07:00
parent d3436c256c
commit 2a37459a5f
5 changed files with 62 additions and 8 deletions

View file

@ -18,16 +18,23 @@ final class DiffusionResolveRefsConduitAPIMethod
protected function defineCustomParamTypes() { protected function defineCustomParamTypes() {
return array( return array(
'refs' => 'required list<string>', 'refs' => 'required list<string>',
'types' => 'optional list<string>',
); );
} }
protected function getResult(ConduitAPIRequest $request) { protected function getResult(ConduitAPIRequest $request) {
$refs = $request->getValue('refs'); $refs = $request->getValue('refs');
$types = $request->getValue('types');
return id(new DiffusionLowLevelResolveRefsQuery()) $query = id(new DiffusionLowLevelResolveRefsQuery())
->setRepository($this->getDiffusionRequest()->getRepository()) ->setRepository($this->getDiffusionRequest()->getRepository())
->withRefs($refs) ->withRefs($refs);
->execute();
if ($types) {
$query->withTypes($types);
}
return $query->execute();
} }
} }

View file

@ -16,12 +16,18 @@ final class DiffusionCachedResolveRefsQuery
extends DiffusionLowLevelQuery { extends DiffusionLowLevelQuery {
private $refs; private $refs;
private $types;
public function withRefs(array $refs) { public function withRefs(array $refs) {
$this->refs = $refs; $this->refs = $refs;
return $this; return $this;
} }
public function withTypes(array $types) {
$this->types = $types;
return $this;
}
protected function executeQuery() { protected function executeQuery() {
if (!$this->refs) { if (!$this->refs) {
return array(); return array();
@ -39,6 +45,10 @@ final class DiffusionCachedResolveRefsQuery
throw new Exception('Unsupported repository type!'); throw new Exception('Unsupported repository type!');
} }
if ($this->types !== null) {
$result = $this->filterRefsByType($result, $this->types);
}
return $result; return $result;
} }

View file

@ -23,4 +23,21 @@ abstract class DiffusionLowLevelQuery extends Phobject {
return $this->executeQuery(); 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;
}
} }

View file

@ -14,12 +14,18 @@ final class DiffusionLowLevelResolveRefsQuery
extends DiffusionLowLevelQuery { extends DiffusionLowLevelQuery {
private $refs; private $refs;
private $types;
public function withRefs(array $refs) { public function withRefs(array $refs) {
$this->refs = $refs; $this->refs = $refs;
return $this; return $this;
} }
public function withTypes(array $types) {
$this->types = $types;
return $this;
}
protected function executeQuery() { protected function executeQuery() {
if (!$this->refs) { if (!$this->refs) {
return array(); return array();
@ -39,6 +45,10 @@ final class DiffusionLowLevelResolveRefsQuery
throw new Exception('Unsupported repository type!'); throw new Exception('Unsupported repository type!');
} }
if ($this->types !== null) {
$result = $this->filterRefsByType($result, $this->types);
}
return $result; return $result;
} }

View file

@ -718,17 +718,21 @@ abstract class DiffusionRequest {
} }
private function queryStableCommit() { private function queryStableCommit() {
$types = array();
if ($this->symbolicCommit) { if ($this->symbolicCommit) {
$ref = $this->symbolicCommit; $ref = $this->symbolicCommit;
} else { } else {
if ($this->supportsBranches()) { if ($this->supportsBranches()) {
$ref = $this->getResolvableBranchName($this->getBranch()); $ref = $this->getResolvableBranchName($this->getBranch());
$types = array(
PhabricatorRepositoryRefCursor::TYPE_BRANCH,
);
} else { } else {
$ref = 'HEAD'; $ref = 'HEAD';
} }
} }
$results = $this->resolveRefs(array($ref)); $results = $this->resolveRefs(array($ref), $types);
$matches = idx($results, $ref, array()); $matches = idx($results, $ref, array());
if (!$matches) { if (!$matches) {
@ -790,12 +794,17 @@ abstract class DiffusionRequest {
return $branch; return $branch;
} }
private function resolveRefs(array $refs) { private function resolveRefs(array $refs, array $types) {
// First, try to resolve refs from fast cache sources. // First, try to resolve refs from fast cache sources.
$cached_results = id(new DiffusionCachedResolveRefsQuery()) $cached_query = id(new DiffusionCachedResolveRefsQuery())
->setRepository($this->getRepository()) ->setRepository($this->getRepository())
->withRefs($refs) ->withRefs($refs);
->execute();
if ($types) {
$cached_query->withTypes($types);
}
$cached_results = $cached_query->execute();
// Throw away all the refs we resolved. Hopefully, we'll throw away // Throw away all the refs we resolved. Hopefully, we'll throw away
// everything here. // everything here.
@ -813,6 +822,7 @@ abstract class DiffusionRequest {
$this, $this,
'diffusion.resolverefs', 'diffusion.resolverefs',
array( array(
'types' => $types,
'refs' => $refs, 'refs' => $refs,
)); ));
} else { } else {