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); }