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

Improve clarity of commit and symbol handling in DiffusionRequest

Summary:
Ref T2683. Currently, DiffusionRequest has four different "commitey" things:

- `commit`
- `rawCommit`
- `symbolicCommit`
- `stableCommit`

Of these, only two are actually distinct, useful values: `symbolicCommit` (which holds the value the request originally contained, if one existed) and `stableCommit` (which resolves that value, or the value implied by its omission, into a stable, permanent commit identifier).

- `rawCommit` is equivalent to `symbolicCommit` and can be simply removed.
- `commit` has some sketchy magic around it that needs to be pulled out before it can be jettisoned.

Test Plan: Viewed SVN, Git, and Mercurial repositories. Viewed brwose/history/change/tag/branch/etc views.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T2683

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

+112 -114
+1 -1
src/applications/diffusion/conduit/ConduitAPI_diffusion_tagsquery_Method.php
··· 24 24 protected function getGitResult(ConduitAPIRequest $request) { 25 25 $drequest = $this->getDiffusionRequest(); 26 26 $repository = $drequest->getRepository(); 27 - $commit = $drequest->getRawCommit(); 27 + $commit = $drequest->getSymbolicCommit(); 28 28 29 29 $commit_filter = null; 30 30 if ($commit) {
+1 -1
src/applications/diffusion/controller/DiffusionBrowseController.php
··· 96 96 ->setHref($history_uri) 97 97 ->setIcon('fa-list')); 98 98 99 - $behind_head = $drequest->getRawCommit(); 99 + $behind_head = $drequest->getSymbolicCommit(); 100 100 $head_uri = $drequest->generateURI( 101 101 array( 102 102 'commit' => '',
+2 -2
src/applications/diffusion/controller/DiffusionChangeController.php
··· 31 31 32 32 $repository = $drequest->getRepository(); 33 33 $callsign = $repository->getCallsign(); 34 - $commit = $drequest->getRawCommit(); 34 + $commit = $drequest->getSymbolicCommit(); 35 35 $changesets = array( 36 36 0 => $changeset, 37 37 ); ··· 53 53 ); 54 54 55 55 $right_uri = $drequest->generateURI($raw_params); 56 - $raw_params['params']['before'] = $drequest->getRawCommit(); 56 + $raw_params['params']['before'] = $drequest->getStableCommit(); 57 57 $left_uri = $drequest->generateURI($raw_params); 58 58 $changeset_view->setRawFileURIs($left_uri, $right_uri); 59 59
+1 -1
src/applications/diffusion/controller/DiffusionCommitController.php
··· 21 21 22 22 public function processRequest() { 23 23 $drequest = $this->getDiffusionRequest(); 24 + 24 25 $request = $this->getRequest(); 25 26 $user = $request->getUser(); 26 27 ··· 32 33 $callsign = $repository->getCallsign(); 33 34 34 35 $content = array(); 35 - 36 36 $commit = id(new DiffusionCommitQuery()) 37 37 ->setViewer($request->getUser()) 38 38 ->withRepository($repository)
+5 -5
src/applications/diffusion/controller/DiffusionController.php
··· 98 98 ))); 99 99 $crumb_list[] = $crumb; 100 100 101 - $raw_commit = $drequest->getRawCommit(); 101 + $stable_commit = $drequest->getStableCommit(); 102 102 103 103 if ($spec['tags']) { 104 104 $crumb = new PhabricatorCrumbView(); 105 105 if ($spec['commit']) { 106 106 $crumb->setName( 107 - pht("Tags for %s", 'r'.$callsign.$raw_commit)); 107 + pht("Tags for %s", 'r'.$callsign.$stable_commit)); 108 108 $crumb->setHref($drequest->generateURI( 109 109 array( 110 110 'action' => 'commit', 111 - 'commit' => $raw_commit, 111 + 'commit' => $drequest->getStableCommit(), 112 112 ))); 113 113 } else { 114 114 $crumb->setName(pht('Tags')); ··· 126 126 127 127 if ($spec['commit']) { 128 128 $crumb = id(new PhabricatorCrumbView()) 129 - ->setName("r{$callsign}{$raw_commit}") 130 - ->setHref("r{$callsign}{$raw_commit}"); 129 + ->setName("r{$callsign}{$stable_commit}") 130 + ->setHref("r{$callsign}{$stable_commit}"); 131 131 $crumb_list[] = $crumb; 132 132 return $crumb_list; 133 133 }
+1 -1
src/applications/diffusion/controller/DiffusionHistoryController.php
··· 152 152 ->setUser($viewer) 153 153 ->setActionList($actions); 154 154 155 - $stable_commit = $drequest->getStableCommit(); 155 + $stable_commit = $drequest->getStableCommitName(); 156 156 $callsign = $drequest->getRepository()->getCallsign(); 157 157 158 158 $view->addProperty(
+4 -3
src/applications/diffusion/controller/DiffusionTagListController.php
··· 20 20 $params = array( 21 21 'limit' => $pager->getPageSize() + 1, 22 22 'offset' => $pager->getOffset()); 23 - if ($drequest->getRawCommit()) { 23 + 24 + if ($drequest->getSymbolicCommit()) { 24 25 $is_commit = true; 25 - $params['commit'] = $drequest->getRawCommit(); 26 + $params['commit'] = $drequest->getSymbolicCommit(); 26 27 } else { 27 28 $is_commit = false; 28 29 } ··· 76 77 $crumbs = $this->buildCrumbs( 77 78 array( 78 79 'tags' => true, 79 - 'commit' => $drequest->getRawCommit(), 80 + 'commit' => $drequest->getSymbolicCommit(), 80 81 )); 81 82 82 83 return $this->buildApplicationPage(
+2 -17
src/applications/diffusion/request/DiffusionGitRequest.php
··· 1 1 <?php 2 2 3 - /** 4 - * @group diffusion 5 - */ 6 3 final class DiffusionGitRequest extends DiffusionRequest { 7 4 8 5 protected function getSupportsBranches() { 9 6 return true; 10 7 } 11 8 12 - protected function didInitialize() { 13 - if (!$this->commit) { 14 - return; 15 - } 16 - 17 - $this->expandCommitName(); 9 + protected function isStableCommit($symbol) { 10 + return preg_match('/^[a-f0-9]{40}\z/', $symbol); 18 11 } 19 12 20 13 public function getBranch() { ··· 25 18 return $this->repository->getDefaultBranch(); 26 19 } 27 20 throw new Exception("Unable to determine branch!"); 28 - } 29 - 30 - public function getCommit() { 31 - if ($this->commit) { 32 - return $this->commit; 33 - } 34 - 35 - return $this->getResolvableBranchName($this->getBranch()); 36 21 } 37 22 38 23 protected function getResolvableBranchName($branch) {
+3 -23
src/applications/diffusion/request/DiffusionMercurialRequest.php
··· 1 1 <?php 2 2 3 - /** 4 - * @group diffusion 5 - */ 6 3 final class DiffusionMercurialRequest extends DiffusionRequest { 7 4 8 5 protected function getSupportsBranches() { 9 6 return true; 10 7 } 11 8 12 - protected function didInitialize() { 13 - // Expand abbreviated hashes to full hashes so "/rXnnnn" (i.e., fewer than 14 - // 40 characters) works correctly. 15 - if (!$this->commit) { 16 - return; 17 - } 18 - 19 - if (strlen($this->commit) == 40) { 20 - return; 21 - } 22 - 23 - $this->expandCommitName(); 24 - } 9 + protected function isStableCommit($symbol) { 10 + return preg_match('/^[a-f0-9]{40}\z/', $symbol); 11 + } 25 12 26 13 public function getBranch() { 27 14 if ($this->branch) { ··· 33 20 } 34 21 35 22 throw new Exception("Unable to determine branch!"); 36 - } 37 - 38 - public function getCommit() { 39 - if ($this->commit) { 40 - return $this->commit; 41 - } 42 - return $this->getBranch(); 43 23 } 44 24 45 25 }
+88 -49
src/applications/diffusion/request/DiffusionRequest.php
··· 29 29 private $user; 30 30 31 31 abstract protected function getSupportsBranches(); 32 - abstract protected function didInitialize(); 32 + abstract protected function isStableCommit($symbol); 33 + 34 + protected function didInitialize() { 35 + return null; 36 + } 33 37 34 38 35 39 /* -( Creating Requests )-------------------------------------------------- */ ··· 130 134 ->setViewer($viewer) 131 135 ->withCallsigns(array($callsign)) 132 136 ->executeOne(); 137 + 133 138 if (!$repository) { 134 139 throw new Exception("No such repository '{$callsign}'."); 135 140 } ··· 179 184 */ 180 185 final private function initializeFromDictionary(array $data) { 181 186 $this->path = idx($data, 'path'); 182 - $this->symbolicCommit = idx($data, 'commit'); 183 - $this->commit = idx($data, 'commit'); 184 187 $this->line = idx($data, 'line'); 185 188 $this->initFromConduit = idx($data, 'initFromConduit', true); 186 189 190 + $this->symbolicCommit = idx($data, 'commit'); 187 191 if ($this->getSupportsBranches()) { 188 192 $this->branch = idx($data, 'branch'); 189 193 } ··· 234 238 } 235 239 236 240 public function getCommit() { 237 - return $this->commit; 241 + 242 + // TODO: Probably remove all of this. 243 + 244 + // Required for sketchy sins that `diffusion.diffquery` commits. 245 + if ($this->commit) { 246 + return $this->commit; 247 + } 248 + 249 + if ($this->getSymbolicCommit() !== null) { 250 + return $this->getSymbolicCommit(); 251 + } 252 + 253 + return $this->getStableCommit(); 238 254 } 239 255 256 + /** 257 + * Get the symbolic commit associated with this request. 258 + * 259 + * A symbolic commit may be a commit hash, an abbreviated commit hash, a 260 + * branch name, a tag name, or an expression like "HEAD^^^". The symbolic 261 + * commit may also be absent. 262 + * 263 + * This method always returns the symbol present in the original request, 264 + * in unmodified form. 265 + * 266 + * See also @{method:getStableCommit}. 267 + * 268 + * @return string|null Symbolic commit, if one was present in the request. 269 + */ 240 270 public function getSymbolicCommit() { 241 271 return $this->symbolicCommit; 242 272 } 243 273 274 + 275 + /** 276 + * Get the ref type (`commit` or `tag`) of the location associated with this 277 + * request. 278 + * 279 + * If a symbolic commit is present in the request, this method identifies 280 + * the type of the symbol. Otherwise, it identifies the type of symbol of 281 + * the location the request is implicitly associated with. This will probably 282 + * always be `commit`. 283 + * 284 + * @return string Symbolic commit type (`commit` or `tag`). 285 + */ 244 286 public function getSymbolicType() { 287 + if ($this->symbolicType === null) { 288 + // As a side effect, this resolves the symbolic type. 289 + $this->getStableCommit(); 290 + } 245 291 return $this->symbolicType; 246 292 } 247 293 294 + 295 + /** 296 + * Retrieve the stable, permanent commit name identifying the repository 297 + * location associated with this request. 298 + * 299 + * This returns a non-symbolic identifier for the current commit: in Git and 300 + * Mercurial, a 40-character SHA1; in SVN, a revision number. 301 + * 302 + * See also @{method:getSymbolicCommit}. 303 + * 304 + * @return string Stable commit name, like a git hash or SVN revision. Not 305 + * a symbolic commit reference. 306 + */ 307 + public function getStableCommit() { 308 + if (!$this->stableCommit) { 309 + if ($this->isStableCommit($this->symbolicCommit)) { 310 + $this->stableCommit = $this->symbolicCommit; 311 + $this->symbolicType = 'commit'; 312 + } else { 313 + $this->queryStableCommit(); 314 + } 315 + } 316 + return $this->stableCommit; 317 + } 318 + 319 + 248 320 public function getBranch() { 249 321 return $this->branch; 250 322 } ··· 308 380 return $this->repositoryCommitData; 309 381 } 310 382 311 - /** 312 - * Retrieve a stable, permanent commit name. This returns a non-symbolic 313 - * identifier for the current commit: e.g., a specific commit hash in git 314 - * (NOT a symbolic name like "origin/master") or a specific revision number 315 - * in SVN (NOT a symbolic name like "HEAD"). 316 - * 317 - * @return string Stable commit name, like a git hash or SVN revision. Not 318 - * a symbolic commit reference. 319 - */ 320 - public function getStableCommit() { 321 - if (!$this->stableCommit) { 322 - $this->queryStableCommit(); 323 - } 324 - return $this->stableCommit; 325 - } 326 - 327 - final public function getRawCommit() { 328 - return $this->commit; 329 - } 330 - 331 383 public function setCommit($commit) { 332 384 $this->commit = $commit; 333 385 return $this; ··· 347 399 */ 348 400 public function generateURI(array $params) { 349 401 if (empty($params['stable'])) { 350 - $default_commit = $this->getRawCommit(); 402 + $default_commit = $this->getSymbolicCommit(); 351 403 } else { 352 404 $default_commit = $this->getStableCommit(); 353 405 } ··· 620 672 "Guide' in the documentation for help setting up repositories."); 621 673 } 622 674 623 - final protected function expandCommitName() { 624 - $results = $this->resolveRefs(array($this->commit)); 625 - $matches = idx($results, $this->commit, array()); 626 - if (count($results) !== 1) { 627 - throw new Exception( 628 - pht('Ref "%s" is ambiguous or does not exist.', $this->commit)); 629 - } 630 - 631 - $match = head($matches); 632 - 633 - $this->commit = $match['identifier']; 634 - $this->symbolicType = $match['type']; 635 - } 636 - 637 675 private function queryStableCommit() { 638 - if ($this->commit) { 639 - $this->stableCommit = $this->commit; 640 - return $this->stableCommit; 641 - } 642 - 643 - if ($this->getSupportsBranches()) { 644 - $ref = $this->getResolvableBranchName($this->getBranch()); 676 + if ($this->symbolicCommit) { 677 + $ref = $this->symbolicCommit; 645 678 } else { 646 - $ref = 'HEAD'; 679 + if ($this->getSupportsBranches()) { 680 + $ref = $this->getResolvableBranchName($this->getBranch()); 681 + } else { 682 + $ref = 'HEAD'; 683 + } 647 684 } 648 685 649 686 $results = $this->resolveRefs(array($ref)); ··· 655 692 ->setRef($ref); 656 693 } 657 694 658 - $this->stableCommit = idx(head($matches), 'identifier'); 659 - return $this->stableCommit; 695 + $match = head($matches); 696 + 697 + $this->stableCommit = $match['identifier']; 698 + $this->symbolicType = $match['type']; 660 699 } 661 700 662 701 protected function getResolvableBranchName($branch) {
+4 -11
src/applications/diffusion/request/DiffusionSvnRequest.php
··· 1 1 <?php 2 2 3 - /** 4 - * @group diffusion 5 - */ 6 3 final class DiffusionSvnRequest extends DiffusionRequest { 7 4 8 5 protected function getSupportsBranches() { 9 6 return false; 7 + } 8 + 9 + protected function isStableCommit($symbol) { 10 + return preg_match('/^[1-9]\d*\z/', $symbol); 10 11 } 11 12 12 13 protected function didInitialize() { ··· 20 21 21 22 protected function getArcanistBranch() { 22 23 return 'svn'; 23 - } 24 - 25 - public function getCommit() { 26 - if ($this->commit) { 27 - return $this->commit; 28 - } 29 - 30 - return $this->getStableCommit(); 31 24 } 32 25 33 26 }