@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.

Remove DiffusionBranchInformation in favor of DiffusionRepositoryRef

Summary: Ref T4327. At some point these two very similar classes got introduced. Collapse `DiffusionBranchInformation` into the nearly identical `DiffusionRepositoryRef`, which enjoys slightly more generality and support.

Test Plan: Viewed branch overview and detail pages. Ran `repository refs` and `repository discover`. Grepped for removed symbols.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4327

Differential Revision: https://secure.phabricator.com/D8002

+92 -119
+1 -1
src/__phutil_library_map__.php
··· 467 467 'DifferentialUnitStatus' => 'applications/differential/constants/DifferentialUnitStatus.php', 468 468 'DifferentialUnitTestResult' => 'applications/differential/constants/DifferentialUnitTestResult.php', 469 469 'DifferentialViewPolicyFieldSpecification' => 'applications/differential/field/specification/DifferentialViewPolicyFieldSpecification.php', 470 - 'DiffusionBranchInformation' => 'applications/diffusion/data/DiffusionBranchInformation.php', 471 470 'DiffusionBranchTableController' => 'applications/diffusion/controller/DiffusionBranchTableController.php', 472 471 'DiffusionBranchTableView' => 'applications/diffusion/view/DiffusionBranchTableView.php', 473 472 'DiffusionBrowseController' => 'applications/diffusion/controller/DiffusionBrowseController.php', ··· 3014 3013 1 => 'PhabricatorApplicationSearchResultsControllerInterface', 3015 3014 ), 3016 3015 'DiffusionRepositoryNewController' => 'DiffusionController', 3016 + 'DiffusionRepositoryRef' => 'Phobject', 3017 3017 'DiffusionRepositoryRemarkupRule' => 'PhabricatorRemarkupRuleObject', 3018 3018 'DiffusionResolveUserQuery' => 'Phobject', 3019 3019 'DiffusionSSHGitReceivePackWorkflow' => 'DiffusionSSHGitWorkflow',
+22 -31
src/applications/diffusion/conduit/ConduitAPI_diffusion_branchquery_Method.php
··· 21 21 ); 22 22 } 23 23 24 + 24 25 protected function getGitResult(ConduitAPIRequest $request) { 25 26 $drequest = $this->getDiffusionRequest(); 26 27 $repository = $drequest->getRepository(); 27 - $limit = $request->getValue('limit'); 28 - $offset = $request->getValue('offset'); 29 28 30 29 $refs = id(new DiffusionLowLevelGitRefQuery()) 31 30 ->setRepository($repository) 32 31 ->withIsOriginBranch(true) 33 32 ->execute(); 34 33 35 - $branches = array(); 36 - foreach ($refs as $ref) { 37 - $branch = id(new DiffusionBranchInformation()) 38 - ->setName($ref->getShortName()) 39 - ->setHeadCommitIdentifier($ref->getCommitIdentifier()); 34 + return $this->processBranchRefs($request, $refs); 35 + } 40 36 41 - if (!$repository->shouldTrackBranch($branch->getName())) { 42 - continue; 43 - } 37 + protected function getMercurialResult(ConduitAPIRequest $request) { 38 + $drequest = $this->getDiffusionRequest(); 39 + $repository = $drequest->getRepository(); 44 40 45 - $branches[] = $branch->toDictionary(); 46 - } 41 + $refs = id(new DiffusionLowLevelMercurialBranchesQuery()) 42 + ->setRepository($repository) 43 + ->execute(); 47 44 48 - // NOTE: We can't apply the offset or limit until here, because we may have 49 - // filtered untrackable branches out of the result set. 50 - 51 - if ($offset) { 52 - $branches = array_slice($branches, $offset); 53 - } 54 - 55 - if ($limit) { 56 - $branches = array_slice($branches, 0, $limit); 57 - } 58 - 59 - return $branches; 45 + return $this->processBranchRefs($request, $refs); 60 46 } 61 47 62 - protected function getMercurialResult(ConduitAPIRequest $request) { 48 + private function processBranchRefs(ConduitAPIRequest $request, array $refs) { 63 49 $drequest = $this->getDiffusionRequest(); 64 50 $repository = $drequest->getRepository(); 65 51 $offset = $request->getValue('offset'); 66 52 $limit = $request->getValue('limit'); 67 53 68 - $branches = id(new DiffusionLowLevelMercurialBranchesQuery()) 69 - ->setRepository($repository) 70 - ->execute(); 54 + foreach ($refs as $key => $ref) { 55 + if (!$repository->shouldTrackBranch($ref->getShortName())) { 56 + unset($refs[$key]); 57 + } 58 + } 59 + 60 + // NOTE: We can't apply the offset or limit until here, because we may have 61 + // filtered untrackable branches out of the result set. 71 62 72 63 if ($offset) { 73 - $branches = array_slice($branches, $offset); 64 + $refs = array_slice($refs, $offset); 74 65 } 75 66 76 67 if ($limit) { 77 - $branches = array_slice($branches, 0, $limit); 68 + $refs = array_slice($refs, 0, $limit); 78 69 } 79 70 80 - return mpull($branches, 'toDictionary'); 71 + return mpull($refs, 'toDictionary'); 81 72 } 82 73 }
+5 -2
src/applications/diffusion/conduit/ConduitAPI_diffusion_commitbranchesquery_Method.php
··· 39 39 $commit); 40 40 return DiffusionGitBranch::parseRemoteBranchOutput( 41 41 $contains, 42 - DiffusionBranchInformation::DEFAULT_GIT_REMOTE); 42 + DiffusionGitBranch::DEFAULT_GIT_REMOTE); 43 43 } 44 44 } 45 45 ··· 48 48 $repository = $drequest->getRepository(); 49 49 $commit = $request->getValue('commit'); 50 50 51 - // TODO: This should use `branches`. 51 + // TODO: This should use `branches`. Also, this entire method's API needs 52 + // to be fixed to support multiple branch heads in Mercurial. We should 53 + // probably return `DiffusionRepositoryRefs` and probably merge this into 54 + // `diffusion.branchesquery`. 52 55 53 56 list($contains) = $repository->execxLocalCommand( 54 57 'log --template %s --limit 1 --rev %s --',
+9 -8
src/applications/diffusion/controller/DiffusionBranchTableController.php
··· 18 18 $pager->setOffset($request->getInt('offset')); 19 19 20 20 // TODO: Add support for branches that contain commit 21 - $branches = DiffusionBranchInformation::newFromConduit( 22 - $this->callConduitWithDiffusionRequest( 23 - 'diffusion.branchquery', 24 - array( 25 - 'offset' => $pager->getOffset(), 26 - 'limit' => $pager->getPageSize() + 1 27 - ))); 21 + $branches = $this->callConduitWithDiffusionRequest( 22 + 'diffusion.branchquery', 23 + array( 24 + 'offset' => $pager->getOffset(), 25 + 'limit' => $pager->getPageSize() + 1 26 + )); 28 27 $branches = $pager->sliceResults($branches); 28 + 29 + $branches = DiffusionRepositoryRef::loadAllFromDictionaries($branches); 29 30 30 31 $content = null; 31 32 if (!$branches) { ··· 35 36 } else { 36 37 $commits = id(new DiffusionCommitQuery()) 37 38 ->setViewer($viewer) 38 - ->withIdentifiers(mpull($branches, 'getHeadCommitIdentifier')) 39 + ->withIdentifiers(mpull($branches, 'getCommitIdentifier')) 39 40 ->withRepository($repository) 40 41 ->execute(); 41 42
+8 -7
src/applications/diffusion/controller/DiffusionRepositoryController.php
··· 261 261 262 262 $limit = 15; 263 263 264 - $branches = DiffusionBranchInformation::newFromConduit( 265 - $this->callConduitWithDiffusionRequest( 266 - 'diffusion.branchquery', 267 - array( 268 - 'limit' => $limit + 1, 269 - ))); 264 + $branches = $this->callConduitWithDiffusionRequest( 265 + 'diffusion.branchquery', 266 + array( 267 + 'limit' => $limit + 1, 268 + )); 270 269 if (!$branches) { 271 270 return null; 272 271 } ··· 274 273 $more_branches = (count($branches) > $limit); 275 274 $branches = array_slice($branches, 0, $limit); 276 275 276 + $branches = DiffusionRepositoryRef::loadAllFromDictionaries($branches); 277 + 277 278 $commits = id(new DiffusionCommitQuery()) 278 279 ->setViewer($viewer) 279 - ->withIdentifiers(mpull($branches, 'getHeadCommitIdentifier')) 280 + ->withIdentifiers(mpull($branches, 'getCommitIdentifier')) 280 281 ->withRepository($drequest->getRepository()) 281 282 ->execute(); 282 283
-56
src/applications/diffusion/data/DiffusionBranchInformation.php
··· 1 - <?php 2 - 3 - final class DiffusionBranchInformation { 4 - 5 - const DEFAULT_GIT_REMOTE = 'origin'; 6 - 7 - private $name; 8 - private $headCommitIdentifier; 9 - 10 - public function setName($name) { 11 - $this->name = $name; 12 - return $this; 13 - } 14 - 15 - public function getName() { 16 - return $this->name; 17 - } 18 - 19 - public function setHeadCommitIdentifier($head_commit_identifier) { 20 - $this->headCommitIdentifier = $head_commit_identifier; 21 - return $this; 22 - } 23 - 24 - public function getHeadCommitIdentifier() { 25 - return $this->headCommitIdentifier; 26 - } 27 - 28 - public static function newFromConduit(array $dicts) { 29 - $branches = array(); 30 - foreach ($dicts as $dict) { 31 - $branches[] = id(new DiffusionBranchInformation()) 32 - ->setName($dict['name']) 33 - ->setHeadCommitIdentifier($dict['headCommitIdentifier']); 34 - } 35 - return $branches; 36 - } 37 - 38 - public function toDictionary() { 39 - return array( 40 - 'name' => $this->getName(), 41 - 'headCommitIdentifier' => $this->getHeadCommitIdentifier() 42 - ); 43 - } 44 - 45 - // TODO: These are hacks to make this compatible with DiffusionRepositoryRef 46 - // for PhabricatorRepositoryRefEngine. The two classes should be merged. 47 - 48 - public function getShortName() { 49 - return $this->getName(); 50 - } 51 - 52 - public function getCommitIdentifier() { 53 - return $this->getHeadCommitIdentifier(); 54 - } 55 - 56 - }
+2
src/applications/diffusion/data/DiffusionGitBranch.php
··· 2 2 3 3 final class DiffusionGitBranch { 4 4 5 + const DEFAULT_GIT_REMOTE = 'origin'; 6 + 5 7 /** 6 8 * Parse the output of 'git branch -r --verbose --no-abbrev' or similar into 7 9 * a map. For instance:
+32 -2
src/applications/diffusion/data/DiffusionRepositoryRef.php
··· 1 1 <?php 2 2 3 - final class DiffusionRepositoryRef { 3 + /** 4 + * @task serialization Serializing Repository Refs 5 + */ 6 + final class DiffusionRepositoryRef extends Phobject { 4 7 5 8 private $shortName; 6 9 private $commitIdentifier; 7 - private $rawFields; 10 + private $rawFields = array(); 8 11 9 12 public function setRawFields(array $raw_fields) { 10 13 $this->rawFields = $raw_fields; ··· 31 34 32 35 public function getShortName() { 33 36 return $this->shortName; 37 + } 38 + 39 + 40 + /* -( Serialization )------------------------------------------------------ */ 41 + 42 + 43 + public function toDictionary() { 44 + return array( 45 + 'shortName' => $this->shortName, 46 + 'commitIdentifier' => $this->commitIdentifier, 47 + 'rawFields' => $this->rawFields, 48 + ); 49 + } 50 + 51 + public static function newFromDictionary(array $dict) { 52 + return id(new DiffusionRepositoryRef()) 53 + ->setShortName($dict['shortName']) 54 + ->setCommitIdentifier($dict['commitIdentifier']) 55 + ->setRawFields($dict['rawFields']); 56 + } 57 + 58 + public static function loadAllFromDictionaries(array $dictionaries) { 59 + $refs = array(); 60 + foreach ($dictionaries as $dictionary) { 61 + $refs[] = self::newFromDictionary($dictionary); 62 + } 63 + return $refs; 34 64 } 35 65 36 66 }
+1 -1
src/applications/diffusion/query/lowlevel/DiffusionLowLevelGitRefQuery.php
··· 32 32 if ($repository->isWorkingCopyBare()) { 33 33 $prefix = 'refs/heads/'; 34 34 } else { 35 - $remote = DiffusionBranchInformation::DEFAULT_GIT_REMOTE; 35 + $remote = DiffusionGitBranch::DEFAULT_GIT_REMOTE; 36 36 $prefix = 'refs/remotes/'.$remote.'/'; 37 37 } 38 38 } else {
+3 -3
src/applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialBranchesQuery.php
··· 18 18 19 19 $lines = ArcanistMercurialParser::parseMercurialBranches($stdout); 20 20 foreach ($lines as $name => $spec) { 21 - $branches[] = id(new DiffusionBranchInformation()) 22 - ->setName($name) 23 - ->setHeadCommitIdentifier($spec['rev']); 21 + $branches[] = id(new DiffusionRepositoryRef()) 22 + ->setShortName($name) 23 + ->setCommitIdentifier($spec['rev']); 24 24 } 25 25 26 26 return $branches;
+1 -1
src/applications/diffusion/request/DiffusionGitRequest.php
··· 39 39 if ($this->repository->isWorkingCopyBare()) { 40 40 return $branch; 41 41 } else { 42 - $remote = DiffusionBranchInformation::DEFAULT_GIT_REMOTE; 42 + $remote = DiffusionGitBranch::DEFAULT_GIT_REMOTE; 43 43 return $remote.'/'.$branch; 44 44 } 45 45 }
+8 -7
src/applications/diffusion/view/DiffusionBranchTableView.php
··· 6 6 private $commits = array(); 7 7 8 8 public function setBranches(array $branches) { 9 - assert_instances_of($branches, 'DiffusionBranchInformation'); 9 + assert_instances_of($branches, 'DiffusionRepositoryRef'); 10 10 $this->branches = $branches; 11 11 return $this; 12 12 } 13 13 14 14 public function setCommits(array $commits) { 15 + assert_instances_of($commits, 'PhabricatorRepositoryCommit'); 15 16 $this->commits = mpull($commits, null, 'getCommitIdentifier'); 16 17 return $this; 17 18 } ··· 23 24 $rows = array(); 24 25 $rowc = array(); 25 26 foreach ($this->branches as $branch) { 26 - $commit = idx($this->commits, $branch->getHeadCommitIdentifier()); 27 + $commit = idx($this->commits, $branch->getCommitIdentifier()); 27 28 if ($commit) { 28 29 $details = $commit->getSummary(); 29 30 $datetime = phabricator_datetime($commit->getEpoch(), $this->user); ··· 39 40 'href' => $drequest->generateURI( 40 41 array( 41 42 'action' => 'history', 42 - 'branch' => $branch->getName(), 43 + 'branch' => $branch->getShortName(), 43 44 )) 44 45 ), 45 46 pht('History')), ··· 49 50 'href' => $drequest->generateURI( 50 51 array( 51 52 'action' => 'browse', 52 - 'branch' => $branch->getName(), 53 + 'branch' => $branch->getShortName(), 53 54 )), 54 55 ), 55 - $branch->getName()), 56 + $branch->getShortName()), 56 57 self::linkCommit( 57 58 $drequest->getRepository(), 58 - $branch->getHeadCommitIdentifier()), 59 + $branch->getCommitIdentifier()), 59 60 $datetime, 60 61 AphrontTableView::renderSingleDisplayLine($details), 61 62 ); 62 - if ($branch->getName() == $current_branch) { 63 + if ($branch->getShortName() == $current_branch) { 63 64 $rowc[] = 'highlighted'; 64 65 } else { 65 66 $rowc[] = null;