@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+62 -8
+10 -3
src/applications/diffusion/conduit/DiffusionResolveRefsConduitAPIMethod.php
··· 18 18 protected function defineCustomParamTypes() { 19 19 return array( 20 20 'refs' => 'required list<string>', 21 + 'types' => 'optional list<string>', 21 22 ); 22 23 } 23 24 24 25 protected function getResult(ConduitAPIRequest $request) { 25 26 $refs = $request->getValue('refs'); 27 + $types = $request->getValue('types'); 26 28 27 - return id(new DiffusionLowLevelResolveRefsQuery()) 29 + $query = id(new DiffusionLowLevelResolveRefsQuery()) 28 30 ->setRepository($this->getDiffusionRequest()->getRepository()) 29 - ->withRefs($refs) 30 - ->execute(); 31 + ->withRefs($refs); 32 + 33 + if ($types) { 34 + $query->withTypes($types); 35 + } 36 + 37 + return $query->execute(); 31 38 } 32 39 33 40 }
+10
src/applications/diffusion/query/DiffusionCachedResolveRefsQuery.php
··· 16 16 extends DiffusionLowLevelQuery { 17 17 18 18 private $refs; 19 + private $types; 19 20 20 21 public function withRefs(array $refs) { 21 22 $this->refs = $refs; 23 + return $this; 24 + } 25 + 26 + public function withTypes(array $types) { 27 + $this->types = $types; 22 28 return $this; 23 29 } 24 30 ··· 37 43 break; 38 44 default: 39 45 throw new Exception('Unsupported repository type!'); 46 + } 47 + 48 + if ($this->types !== null) { 49 + $result = $this->filterRefsByType($result, $this->types); 40 50 } 41 51 42 52 return $result;
+17
src/applications/diffusion/query/lowlevel/DiffusionLowLevelQuery.php
··· 23 23 return $this->executeQuery(); 24 24 } 25 25 26 + protected function filterRefsByType(array $refs, array $types) { 27 + $type_map = array_fuse($types); 28 + 29 + foreach ($refs as $name => $ref_list) { 30 + foreach ($ref_list as $key => $ref) { 31 + if (empty($type_map[$ref['type']])) { 32 + unset($refs[$name][$key]); 33 + } 34 + } 35 + if (!$refs[$name]) { 36 + unset($refs[$name]); 37 + } 38 + } 39 + 40 + return $refs; 41 + } 42 + 26 43 }
+10
src/applications/diffusion/query/lowlevel/DiffusionLowLevelResolveRefsQuery.php
··· 14 14 extends DiffusionLowLevelQuery { 15 15 16 16 private $refs; 17 + private $types; 17 18 18 19 public function withRefs(array $refs) { 19 20 $this->refs = $refs; 21 + return $this; 22 + } 23 + 24 + public function withTypes(array $types) { 25 + $this->types = $types; 20 26 return $this; 21 27 } 22 28 ··· 37 43 break; 38 44 default: 39 45 throw new Exception('Unsupported repository type!'); 46 + } 47 + 48 + if ($this->types !== null) { 49 + $result = $this->filterRefsByType($result, $this->types); 40 50 } 41 51 42 52 return $result;
+15 -5
src/applications/diffusion/request/DiffusionRequest.php
··· 718 718 } 719 719 720 720 private function queryStableCommit() { 721 + $types = array(); 721 722 if ($this->symbolicCommit) { 722 723 $ref = $this->symbolicCommit; 723 724 } else { 724 725 if ($this->supportsBranches()) { 725 726 $ref = $this->getResolvableBranchName($this->getBranch()); 727 + $types = array( 728 + PhabricatorRepositoryRefCursor::TYPE_BRANCH, 729 + ); 726 730 } else { 727 731 $ref = 'HEAD'; 728 732 } 729 733 } 730 734 731 - $results = $this->resolveRefs(array($ref)); 735 + $results = $this->resolveRefs(array($ref), $types); 732 736 733 737 $matches = idx($results, $ref, array()); 734 738 if (!$matches) { ··· 790 794 return $branch; 791 795 } 792 796 793 - private function resolveRefs(array $refs) { 797 + private function resolveRefs(array $refs, array $types) { 794 798 // First, try to resolve refs from fast cache sources. 795 - $cached_results = id(new DiffusionCachedResolveRefsQuery()) 799 + $cached_query = id(new DiffusionCachedResolveRefsQuery()) 796 800 ->setRepository($this->getRepository()) 797 - ->withRefs($refs) 798 - ->execute(); 801 + ->withRefs($refs); 802 + 803 + if ($types) { 804 + $cached_query->withTypes($types); 805 + } 806 + 807 + $cached_results = $cached_query->execute(); 799 808 800 809 // Throw away all the refs we resolved. Hopefully, we'll throw away 801 810 // everything here. ··· 813 822 $this, 814 823 'diffusion.resolverefs', 815 824 array( 825 + 'types' => $types, 816 826 'refs' => $refs, 817 827 )); 818 828 } else {