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

Add a "/source/..." URI for Diffusion commits which redirects

Summary:
See PHI112. The install presumably wants to generate links to Diffusion commits from an external tool, but only knows the short name of the repository.

Provide a `/source/phabricator/commit/abcdef908273` URI which redirects to the canonical URI for the commit.

Test Plan:
- Visited `/source/` URI for a commit, got a redirect.
- Visited normal URI for a commit, got a commit page.
- Visited `/branches/` and `/tags/` for a `/source/` repository, got proper pages.

Reviewers: amckinley

Reviewed By: amckinley

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

+18 -7
+5 -4
src/applications/diffusion/application/PhabricatorDiffusionApplication.php
··· 69 69 'branches/(?P<dblob>.*)' => 'DiffusionBranchTableController', 70 70 'refs/(?P<dblob>.*)' => 'DiffusionRefTableController', 71 71 'lint/(?P<dblob>.*)' => 'DiffusionLintController', 72 - 'commit/(?P<commit>[a-z0-9]+)/branches/' 73 - => 'DiffusionCommitBranchesController', 74 - 'commit/(?P<commit>[a-z0-9]+)/tags/' 75 - => 'DiffusionCommitTagsController', 72 + 'commit/(?P<commit>[a-z0-9]+)' => array( 73 + '/?' => 'DiffusionCommitController', 74 + '/branches/' => 'DiffusionCommitBranchesController', 75 + '/tags/' => 'DiffusionCommitTagsController', 76 + ), 76 77 'compare/' => 'DiffusionCompareController', 77 78 'manage/(?:(?P<panel>[^/]+)/)?' 78 79 => 'DiffusionRepositoryManagePanelsController',
+13 -3
src/applications/diffusion/controller/DiffusionCommitController.php
··· 22 22 23 23 $drequest = $this->getDiffusionRequest(); 24 24 $viewer = $request->getUser(); 25 + $repository = $drequest->getRepository(); 26 + $commit_identifier = $drequest->getCommit(); 27 + 28 + // If this page is being accessed via "/source/xyz/commit/...", redirect 29 + // to the canonical URI. 30 + $has_callsign = strlen($request->getURIData('repositoryCallsign')); 31 + $has_id = strlen($request->getURIData('repositoryID')); 32 + if (!$has_callsign && !$has_id) { 33 + $canonical_uri = $repository->getCommitURI($commit_identifier); 34 + return id(new AphrontRedirectResponse()) 35 + ->setURI($canonical_uri); 36 + } 25 37 26 38 if ($request->getStr('diff')) { 27 39 return $this->buildRawDiffResponse($drequest); 28 40 } 29 41 30 - $repository = $drequest->getRepository(); 31 - 32 42 $commit = id(new DiffusionCommitQuery()) 33 43 ->setViewer($viewer) 34 44 ->withRepository($repository) 35 - ->withIdentifiers(array($drequest->getCommit())) 45 + ->withIdentifiers(array($commit_identifier)) 36 46 ->needCommitData(true) 37 47 ->needAuditRequests(true) 38 48 ->executeOne();