From 07ad4d154cf4fca380fd7e10f567c43fad976409 Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Fri, 17 May 2013 14:13:48 -0700 Subject: [PATCH] Diffusion - move build refs to occur over Conduit Summary: Ref T2784. Test Plan: loaded up a git commit with refs and they showed up! loaded up a git commit without revs and nothing showed up. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2784 Differential Revision: https://secure.phabricator.com/D5957 --- src/__phutil_library_map__.php | 2 + .../ConduitAPI_diffusion_refsquery_Method.php | 57 +++++++++++++++++++ .../controller/DiffusionCommitController.php | 39 +++---------- 3 files changed, 68 insertions(+), 30 deletions(-) create mode 100644 src/applications/diffusion/conduit/ConduitAPI_diffusion_refsquery_Method.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index ed8b931414..5b3f65e4ea 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -157,6 +157,7 @@ phutil_register_library_map(array( 'ConduitAPI_diffusion_getrecentcommitsbypath_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_getrecentcommitsbypath_Method.php', 'ConduitAPI_diffusion_lastmodifiedquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_lastmodifiedquery_Method.php', 'ConduitAPI_diffusion_rawdiffquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_rawdiffquery_Method.php', + 'ConduitAPI_diffusion_refsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_refsquery_Method.php', 'ConduitAPI_diffusion_searchquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_searchquery_Method.php', 'ConduitAPI_diffusion_stablecommitnamequery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_stablecommitnamequery_Method.php', 'ConduitAPI_diffusion_tagsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_tagsquery_Method.php', @@ -1961,6 +1962,7 @@ phutil_register_library_map(array( 'ConduitAPI_diffusion_getrecentcommitsbypath_Method' => 'ConduitAPI_diffusion_Method', 'ConduitAPI_diffusion_lastmodifiedquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 'ConduitAPI_diffusion_rawdiffquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', + 'ConduitAPI_diffusion_refsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 'ConduitAPI_diffusion_searchquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 'ConduitAPI_diffusion_stablecommitnamequery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 'ConduitAPI_diffusion_tagsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', diff --git a/src/applications/diffusion/conduit/ConduitAPI_diffusion_refsquery_Method.php b/src/applications/diffusion/conduit/ConduitAPI_diffusion_refsquery_Method.php new file mode 100644 index 0000000000..f9ef561468 --- /dev/null +++ b/src/applications/diffusion/conduit/ConduitAPI_diffusion_refsquery_Method.php @@ -0,0 +1,57 @@ + 'required string', + ); + } + + protected function getGitResult(ConduitAPIRequest $request) { + $drequest = $this->getDiffusionRequest(); + $repository = $drequest->getRepository(); + $commit = $request->getValue('commit'); + + list($stdout) = $repository->execxLocalCommand( + 'log --format=%s -n 1 %s --', + '%d', + $commit); + + // %d, gives a weird output format + // similar to (remote/one, remote/two, remote/three) + $refs = trim($stdout, "() \n"); + if (!$refs) { + return null; + } + $refs = explode(',', $refs); + $refs = array_map('trim', $refs); + + $ref_links = array(); + foreach ($refs as $ref) { + $ref_links[] = array( + 'ref' => $ref, + 'href' => $drequest->generateURI( + array( + 'action' => 'browse', + 'branch' => $ref, + ))); + } + + return $ref_links; + } + +} diff --git a/src/applications/diffusion/controller/DiffusionCommitController.php b/src/applications/diffusion/controller/DiffusionCommitController.php index 24c8bc0d8c..f11eceecba 100644 --- a/src/applications/diffusion/controller/DiffusionCommitController.php +++ b/src/applications/diffusion/controller/DiffusionCommitController.php @@ -902,44 +902,23 @@ final class DiffusionCommitController extends DiffusionController { } private function buildRefs(DiffusionRequest $request) { - // Not turning this into a proper Query class since it's pretty simple, - // one-off, and Git-specific. - + // this is git-only, so save a conduit round trip and just get out of + // here if the repository isn't git $type_git = PhabricatorRepositoryType::REPOSITORY_TYPE_GIT; - $repository = $request->getRepository(); if ($repository->getVersionControlSystem() != $type_git) { return null; } - list($stdout) = $repository->execxLocalCommand( - 'log --format=%s -n 1 %s --', - '%d', - $request->getCommit()); - - // %d, gives a weird output format - // similar to (remote/one, remote/two, remote/three) - $refs = trim($stdout, "() \n"); - if (!$refs) { - return null; - } - $refs = explode(',', $refs); - $refs = array_map('trim', $refs); - + $results = $this->callConduitWithDiffusionRequest( + 'diffusion.refsquery', + array('commit' => $request->getCommit())); $ref_links = array(); - foreach ($refs as $ref) { - $ref_links[] = phutil_tag( - 'a', - array( - 'href' => $request->generateURI( - array( - 'action' => 'browse', - 'branch' => $ref, - )), - ), - $ref); + foreach ($results as $ref_data) { + $ref_links[] = phutil_tag('a', + array('href' => $ref_data['href']), + $ref_data['ref']); } - return phutil_implode_html(', ', $ref_links); }