From d1936711a07724761c8862e404764ecf718c5df9 Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Thu, 28 Aug 2014 13:08:42 -0700 Subject: [PATCH] Diffusion - replace last `hg manifest` call with `hg locate` Summary: Fixes T4387. Test Plan: Setup a mercurial repository for rabbitmq-server. Browsed around it and things looked good. Reviewers: epriestley Reviewed By: epriestley Subscribers: epriestley, Korvin Maniphest Tasks: T4387 Differential Revision: https://secure.phabricator.com/D10380 --- src/__phutil_library_map__.php | 2 ++ .../DiffusionBrowseQueryConduitAPIMethod.php | 14 ++++---- .../DiffusionQueryPathsConduitAPIMethod.php | 10 +++--- .../DiffusionLowLevelMercurialPathsQuery.php | 36 +++++++++++++++++++ 4 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 src/applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialPathsQuery.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 3c4b3d25a7..c0ce4d8ee1 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -425,6 +425,7 @@ phutil_register_library_map(array( 'DiffusionLowLevelCommitQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelCommitQuery.php', 'DiffusionLowLevelGitRefQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelGitRefQuery.php', 'DiffusionLowLevelMercurialBranchesQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialBranchesQuery.php', + 'DiffusionLowLevelMercurialPathsQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialPathsQuery.php', 'DiffusionLowLevelParentsQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelParentsQuery.php', 'DiffusionLowLevelQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelQuery.php', 'DiffusionLowLevelResolveRefsQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelResolveRefsQuery.php', @@ -3182,6 +3183,7 @@ phutil_register_library_map(array( 'DiffusionLowLevelCommitQuery' => 'DiffusionLowLevelQuery', 'DiffusionLowLevelGitRefQuery' => 'DiffusionLowLevelQuery', 'DiffusionLowLevelMercurialBranchesQuery' => 'DiffusionLowLevelQuery', + 'DiffusionLowLevelMercurialPathsQuery' => 'DiffusionLowLevelQuery', 'DiffusionLowLevelParentsQuery' => 'DiffusionLowLevelQuery', 'DiffusionLowLevelQuery' => 'Phobject', 'DiffusionLowLevelResolveRefsQuery' => 'DiffusionLowLevelQuery', diff --git a/src/applications/diffusion/conduit/DiffusionBrowseQueryConduitAPIMethod.php b/src/applications/diffusion/conduit/DiffusionBrowseQueryConduitAPIMethod.php index d4a5c70abb..ab20f13d02 100644 --- a/src/applications/diffusion/conduit/DiffusionBrowseQueryConduitAPIMethod.php +++ b/src/applications/diffusion/conduit/DiffusionBrowseQueryConduitAPIMethod.php @@ -198,18 +198,16 @@ final class DiffusionBrowseQueryConduitAPIMethod $commit = $request->getValue('commit'); $result = $this->getEmptyResultSet(); - $match_against = trim($path, '/'); - $prefix = trim('./'.$match_against, '/'); - - list($entire_manifest) = $repository->execxLocalCommand( - 'locate --print0 --rev %s -I %s', - hgsprintf('%s', $commit), - $prefix); - $entire_manifest = explode("\0", $entire_manifest); + $entire_manifest = id(new DiffusionLowLevelMercurialPathsQuery()) + ->setRepository($repository) + ->withCommit($commit) + ->withPath($path) + ->execute(); $results = array(); + $match_against = trim($path, '/'); $match_len = strlen($match_against); // For the root, don't trim. For other paths, trim the "/" after we match. diff --git a/src/applications/diffusion/conduit/DiffusionQueryPathsConduitAPIMethod.php b/src/applications/diffusion/conduit/DiffusionQueryPathsConduitAPIMethod.php index 757c5116b5..c25d71aeb4 100644 --- a/src/applications/diffusion/conduit/DiffusionQueryPathsConduitAPIMethod.php +++ b/src/applications/diffusion/conduit/DiffusionQueryPathsConduitAPIMethod.php @@ -55,11 +55,11 @@ final class DiffusionQueryPathsConduitAPIMethod $path = $request->getValue('path'); $commit = $request->getValue('commit'); - // Adapted from diffusion.browsequery. - list($entire_manifest) = $repository->execxLocalCommand( - 'manifest --rev %s', - hgsprintf('%s', $commit)); - $entire_manifest = explode("\n", $entire_manifest); + $entire_manifest = id(new DiffusionLowLevelMercurialPathsQuery()) + ->setRepository($repository) + ->withCommit($commit) + ->withPath($path) + ->execute(); $match_against = trim($path, '/'); $match_len = strlen($match_against); diff --git a/src/applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialPathsQuery.php b/src/applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialPathsQuery.php new file mode 100644 index 0000000000..aca82df79f --- /dev/null +++ b/src/applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialPathsQuery.php @@ -0,0 +1,36 @@ +commit = $commit; + return $this; + } + + public function withPath($path) { + $this->path = $path; + return $this; + } + + protected function executeQuery() { + $repository = $this->getRepository(); + $path = $this->path; + $commit = $this->commit; + + $match_against = trim($path, '/'); + $prefix = trim('./'.$match_against, '/'); + list($entire_manifest) = $repository->execxLocalCommand( + 'locate --print0 --rev %s -I %s', + hgsprintf('%s', $commit), + $prefix); + return explode("\0", $entire_manifest); + } + +}