From 89fe84f9789629bbd7166965811e6d33c635f51b Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 3 Oct 2017 12:50:01 -0700 Subject: [PATCH] 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 --- .../PhabricatorDiffusionApplication.php | 9 +++++---- .../controller/DiffusionCommitController.php | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/applications/diffusion/application/PhabricatorDiffusionApplication.php b/src/applications/diffusion/application/PhabricatorDiffusionApplication.php index cf9c14aa8b..5a426ec299 100644 --- a/src/applications/diffusion/application/PhabricatorDiffusionApplication.php +++ b/src/applications/diffusion/application/PhabricatorDiffusionApplication.php @@ -69,10 +69,11 @@ final class PhabricatorDiffusionApplication extends PhabricatorApplication { 'branches/(?P.*)' => 'DiffusionBranchTableController', 'refs/(?P.*)' => 'DiffusionRefTableController', 'lint/(?P.*)' => 'DiffusionLintController', - 'commit/(?P[a-z0-9]+)/branches/' - => 'DiffusionCommitBranchesController', - 'commit/(?P[a-z0-9]+)/tags/' - => 'DiffusionCommitTagsController', + 'commit/(?P[a-z0-9]+)' => array( + '/?' => 'DiffusionCommitController', + '/branches/' => 'DiffusionCommitBranchesController', + '/tags/' => 'DiffusionCommitTagsController', + ), 'compare/' => 'DiffusionCompareController', 'manage/(?:(?P[^/]+)/)?' => 'DiffusionRepositoryManagePanelsController', diff --git a/src/applications/diffusion/controller/DiffusionCommitController.php b/src/applications/diffusion/controller/DiffusionCommitController.php index 59a132b17d..38c94e8a92 100644 --- a/src/applications/diffusion/controller/DiffusionCommitController.php +++ b/src/applications/diffusion/controller/DiffusionCommitController.php @@ -22,17 +22,27 @@ final class DiffusionCommitController extends DiffusionController { $drequest = $this->getDiffusionRequest(); $viewer = $request->getUser(); + $repository = $drequest->getRepository(); + $commit_identifier = $drequest->getCommit(); + + // If this page is being accessed via "/source/xyz/commit/...", redirect + // to the canonical URI. + $has_callsign = strlen($request->getURIData('repositoryCallsign')); + $has_id = strlen($request->getURIData('repositoryID')); + if (!$has_callsign && !$has_id) { + $canonical_uri = $repository->getCommitURI($commit_identifier); + return id(new AphrontRedirectResponse()) + ->setURI($canonical_uri); + } if ($request->getStr('diff')) { return $this->buildRawDiffResponse($drequest); } - $repository = $drequest->getRepository(); - $commit = id(new DiffusionCommitQuery()) ->setViewer($viewer) ->withRepository($repository) - ->withIdentifiers(array($drequest->getCommit())) + ->withIdentifiers(array($commit_identifier)) ->needCommitData(true) ->needAuditRequests(true) ->executeOne();