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

Make CommitController more flexible about handling URIs

Summary:
Ref T4245. This adds support for both ID-based and callsign-based routes, although the ID-based routes don't occur anywhere.

Also moves toward simplifying the DiffusionRequest stuff.

Test Plan: Visited normal callsign-based commit pages; visited new ID-based commit pages.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T4245

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

+68 -18
+6 -1
src/applications/diffusion/application/PhabricatorDiffusionApplication.php
··· 47 47 48 48 public function getRoutes() { 49 49 return array( 50 - '/r(?P<callsign>[A-Z]+)(?P<commit>[a-z0-9]+)' 50 + '/(?:'. 51 + 'r(?P<repositoryCallsign>[A-Z]+)'. 52 + '|'. 53 + 'R(?P<repositoryID>[1-9]\d*):'. 54 + ')(?P<commit>[a-f0-9]+)' 51 55 => 'DiffusionCommitController', 56 + 52 57 '/diffusion/' => array( 53 58 '(?:query/(?P<queryKey>[^/]+)/)?' 54 59 => 'DiffusionRepositoryListController',
+7 -11
src/applications/diffusion/controller/DiffusionCommitController.php
··· 17 17 return true; 18 18 } 19 19 20 - protected function shouldLoadDiffusionRequest() { 21 - return false; 22 - } 20 + public function handleRequest(AphrontRequest $request) { 21 + $response = $this->loadDiffusionContext(); 22 + if ($response) { 23 + return $response; 24 + } 23 25 24 - protected function processDiffusionRequest(AphrontRequest $request) { 26 + $drequest = $this->getDiffusionRequest(); 27 + 25 28 $user = $request->getUser(); 26 - 27 - // This controller doesn't use blob/path stuff, just pass the dictionary 28 - // in directly instead of using the AphrontRequest parsing mechanism. 29 - $data = $request->getURIMap(); 30 - $data['user'] = $user; 31 - $drequest = DiffusionRequest::newFromDictionary($data); 32 - $this->diffusionRequest = $drequest; 33 29 34 30 if ($request->getStr('diff')) { 35 31 return $this->buildRawDiffResponse($drequest);
+43 -2
src/applications/diffusion/controller/DiffusionController.php
··· 35 35 return true; 36 36 } 37 37 38 - final public function handleRequest(AphrontRequest $request) { 38 + public function handleRequest(AphrontRequest $request) { 39 39 if ($request->getURIData('callsign') && 40 40 $this->shouldLoadDiffusionRequest()) { 41 41 try { ··· 48 48 } 49 49 $this->setDiffusionRequest($drequest); 50 50 } 51 + 51 52 return $this->processDiffusionRequest($request); 52 53 } 53 54 54 - abstract protected function processDiffusionRequest(AphrontRequest $request); 55 + protected function loadDiffusionContext() { 56 + $request = $this->getRequest(); 57 + $viewer = $this->getViewer(); 58 + 59 + $identifier = $request->getURIData('repositoryCallsign'); 60 + if (!strlen($identifier)) { 61 + $identifier = (int)$request->getURIData('repositoryID'); 62 + } 63 + 64 + $blob = $request->getURIData('dblob'); 65 + if (strlen($blob)) { 66 + $parsed = DiffusionRequest::parseRequestBlob($blob); 67 + } else { 68 + $parsed = array( 69 + 'commit' => $request->getURIData('commit'), 70 + 'path' => $request->getURIData('path'), 71 + 'line' => $request->getURIData('line'), 72 + 'branch' => $request->getURIData('branch'), 73 + 'lint' => $request->getStr('lint'), 74 + ); 75 + } 76 + 77 + $params = array( 78 + 'repository' => $identifier, 79 + 'user' => $viewer, 80 + ) + $parsed; 81 + 82 + $drequest = DiffusionRequest::newFromDictionary($params); 83 + 84 + if (!$drequest) { 85 + return new Aphront404Response(); 86 + } 87 + 88 + $this->diffusionRequest = $drequest; 89 + 90 + return null; 91 + } 92 + 93 + protected function processDiffusionRequest(AphrontRequest $request) { 94 + throw new PhutilMethodNotImplementedException(); 95 + } 55 96 56 97 public function buildCrumbs(array $spec = array()) { 57 98 $crumbs = $this->buildApplicationCrumbs();
+5 -1
src/applications/diffusion/request/DiffusionRequest.php
··· 105 105 $object = self::newFromRepository($repository); 106 106 } 107 107 108 + if (!$object) { 109 + return null; 110 + } 111 + 108 112 $object->initializeFromDictionary($data); 109 113 110 114 return $object; ··· 175 179 ->executeOne(); 176 180 177 181 if (!$repository) { 178 - throw new Exception(pht("No such repository '%s'.", $identifier)); 182 + return null; 179 183 } 180 184 181 185 return self::newFromRepository($repository);
+1 -1
src/applications/repository/query/PhabricatorRepositoryQuery.php
··· 55 55 $monograms = array(); 56 56 57 57 foreach ($identifiers as $identifier) { 58 - if (ctype_digit($identifier)) { 58 + if (ctype_digit((string)$identifier)) { 59 59 $ids[$identifier] = $identifier; 60 60 } else if (preg_match('/^(r[A-Z]+)|(R[1-9]\d*)\z/', $identifier)) { 61 61 $monograms[$identifier] = $identifier;
+6 -2
src/applications/repository/storage/PhabricatorRepositoryCommit.php
··· 252 252 $repository = $this->getRepository(); 253 253 $callsign = $repository->getCallsign(); 254 254 $identifier = $this->getCommitIdentifier(); 255 - 256 - return "r{$callsign}{$identifier}"; 255 + if ($callsign !== null) { 256 + return "r{$callsign}{$identifier}"; 257 + } else { 258 + $id = $repository->getID(); 259 + return "R{$id}:{$identifier}"; 260 + } 257 261 } 258 262 259 263 public function getDisplayName() {