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

Fix all remaining weird Diffusion request processing

Summary: Ref T4245. This is the last of it, and covers the clone/push stuff.

Test Plan:
- Cloned git.
- Pushed git.
- Cloned mercurial.
- Pushed mercurial.
- Visited a `blah.git` URL in my browser just because; got redirected to a human-facing UI.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T4245

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

+26 -97
+3 -2
src/applications/diffusion/application/PhabricatorDiffusionApplication.php
··· 64 64 '(?:query/(?P<queryKey>[^/]+)/)?' => 'DiffusionPushLogListController', 65 65 'view/(?P<id>\d+)/' => 'DiffusionPushEventViewController', 66 66 ), 67 - '(?P<repositoryCallsign>(?P<callsign>[A-Z]+))/' => array( 67 + '(?P<repositoryCallsign>[A-Z]+)/' => array( 68 68 '' => 'DiffusionRepositoryController', 69 69 70 70 'repository/(?P<dblob>.*)' => 'DiffusionRepositoryController', ··· 115 115 // catch-all for serving repositories over HTTP. We must accept 116 116 // requests without the trailing "/" because SVN commands don't 117 117 // necessarily include it. 118 - '(?P<callsign>[A-Z]+)(/|$).*' => 'DiffusionRepositoryDefaultController', 118 + '(?P<repositoryCallsign>[A-Z]+)(?:/.*)?' => 119 + 'DiffusionRepositoryDefaultController', 119 120 120 121 'inline/' => array( 121 122 'edit/(?P<phid>[^/]+)/' => 'DiffusionInlineCommentController',
+14 -35
src/applications/diffusion/controller/DiffusionController.php
··· 2 2 3 3 abstract class DiffusionController extends PhabricatorController { 4 4 5 - protected $diffusionRequest; 6 - 7 - public function setDiffusionRequest(DiffusionRequest $request) { 8 - $this->diffusionRequest = $request; 9 - return $this; 10 - } 5 + private $diffusionRequest; 11 6 12 7 protected function getDiffusionRequest() { 13 8 if (!$this->diffusionRequest) { 14 - throw new Exception(pht('No Diffusion request object!')); 9 + throw new PhutilInvalidStateException('loadDiffusionContext'); 15 10 } 16 11 return $this->diffusionRequest; 17 12 } 18 13 14 + protected function hasDiffusionRequest() { 15 + return (bool)$this->diffusionRequest; 16 + } 17 + 19 18 public function willBeginExecution() { 20 19 $request = $this->getRequest(); 21 20 22 21 // Check if this is a VCS request, e.g. from "git clone", "hg clone", or 23 22 // "svn checkout". If it is, we jump off into repository serving code to 24 23 // process the request. 25 - if (DiffusionServeController::isVCSRequest($request)) { 26 - $serve_controller = id(new DiffusionServeController()) 27 - ->setCurrentApplication($this->getCurrentApplication()); 24 + 25 + $serve_controller = new DiffusionServeController(); 26 + if ($serve_controller->isVCSRequest($request)) { 28 27 return $this->delegateToController($serve_controller); 29 28 } 30 29 31 30 return parent::willBeginExecution(); 32 - } 33 - 34 - protected function shouldLoadDiffusionRequest() { 35 - return true; 36 - } 37 - 38 - public function handleRequest(AphrontRequest $request) { 39 - if ($request->getURIData('callsign') && 40 - $this->shouldLoadDiffusionRequest()) { 41 - try { 42 - $drequest = DiffusionRequest::newFromAphrontRequestDictionary( 43 - $request->getURIMap(), 44 - $request); 45 - } catch (Exception $ex) { 46 - return id(new Aphront404Response()) 47 - ->setRequest($request); 48 - } 49 - $this->setDiffusionRequest($drequest); 50 - } 51 - 52 - return $this->processDiffusionRequest($request); 53 31 } 54 32 55 33 protected function loadDiffusionContextForEdit() { ··· 103 81 return $identifier; 104 82 } 105 83 106 - return (int)$request->getURIData('repositoryID'); 107 - } 84 + $id = $request->getURIData('repositoryID'); 85 + if (strlen($id)) { 86 + return (int)$id; 87 + } 108 88 109 - protected function processDiffusionRequest(AphrontRequest $request) { 110 - throw new PhutilMethodNotImplementedException(); 89 + return null; 111 90 } 112 91 113 92 public function buildCrumbs(array $spec = array()) {
+3 -2
src/applications/diffusion/controller/DiffusionRepositoryEditController.php
··· 6 6 protected function buildApplicationCrumbs($is_main = false) { 7 7 $crumbs = parent::buildApplicationCrumbs(); 8 8 9 - if ($this->diffusionRequest) { 10 - $repository = $this->getDiffusionRequest()->getRepository(); 9 + if ($this->hasDiffusionRequest()) { 10 + $drequest = $this->getDiffusionRequest(); 11 + $repository = $drequest->getRepository(); 11 12 $repo_uri = $repository->getURI(); 12 13 $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); 13 14
+6 -21
src/applications/diffusion/controller/DiffusionServeController.php
··· 2 2 3 3 final class DiffusionServeController extends DiffusionController { 4 4 5 - protected function shouldLoadDiffusionRequest() { 6 - return false; 7 - } 8 - 9 - public static function isVCSRequest(AphrontRequest $request) { 10 - if (!self::getCallsign($request)) { 5 + public function isVCSRequest(AphrontRequest $request) { 6 + $identifier = $this->getRepositoryIdentifierFromRequest($request); 7 + if ($identifier === null) { 11 8 return null; 12 9 } 13 10 ··· 47 44 return $vcs; 48 45 } 49 46 50 - private static function getCallsign(AphrontRequest $request) { 51 - $uri = $request->getRequestURI(); 52 - 53 - $regex = '@^/diffusion/(?P<callsign>[A-Z]+)(/|$)@'; 54 - $matches = null; 55 - if (!preg_match($regex, (string)$uri, $matches)) { 56 - return null; 57 - } 58 - 59 - return $matches['callsign']; 60 - } 61 - 62 - protected function processDiffusionRequest(AphrontRequest $request) { 63 - $callsign = self::getCallsign($request); 47 + public function handleRequest(AphrontRequest $request) { 48 + $identifier = $this->getRepositoryIdentifierFromRequest($request); 64 49 65 50 // If authentication credentials have been provided, try to find a user 66 51 // that actually matches those credentials. ··· 99 84 try { 100 85 $repository = id(new PhabricatorRepositoryQuery()) 101 86 ->setViewer($viewer) 102 - ->withCallsigns(array($callsign)) 87 + ->withIdentifiers(array($identifier)) 103 88 ->executeOne(); 104 89 if (!$repository) { 105 90 return new PhabricatorVCSResponse(
-37
src/applications/diffusion/request/DiffusionRequest.php
··· 117 117 return $object; 118 118 } 119 119 120 - 121 - /** 122 - * Create a new request from an Aphront request dictionary. This is an 123 - * internal method that you generally should not call directly; instead, 124 - * call @{method:newFromDictionary}. 125 - * 126 - * @param map Map of Aphront request data. 127 - * @return DiffusionRequest New request object. 128 - * @task new 129 - */ 130 - final public static function newFromAphrontRequestDictionary( 131 - array $data, 132 - AphrontRequest $request) { 133 - 134 - $identifier = phutil_unescape_uri_path_component(idx($data, 'callsign')); 135 - $object = self::newFromIdentifier($identifier, $request->getUser()); 136 - 137 - $use_branches = $object->supportsBranches(); 138 - 139 - if (isset($data['dblob'])) { 140 - $parsed = self::parseRequestBlob(idx($data, 'dblob'), $use_branches); 141 - } else { 142 - $parsed = array( 143 - 'commit' => idx($data, 'commit'), 144 - 'path' => idx($data, 'path'), 145 - 'line' => idx($data, 'line'), 146 - 'branch' => idx($data, 'branch'), 147 - ); 148 - } 149 - 150 - $object->setUser($request->getUser()); 151 - $object->initializeFromDictionary($parsed); 152 - $object->lint = $request->getStr('lint'); 153 - return $object; 154 - } 155 - 156 - 157 120 /** 158 121 * Internal. 159 122 *