From 2c9b194d1673cbd215a8becc39a75959c51dd85f Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 27 Apr 2015 03:50:55 -0700 Subject: [PATCH] Simplify Mercurial ref resolution; expose "closed" at top-level Summary: Ref T7100. Ref T6160. Share branch code. Surface "closed". Test Plan: Browsed a mercurial repository and saw consistent ref/cache state. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T6160, T7100 Differential Revision: https://secure.phabricator.com/D12551 --- .../query/DiffusionCachedResolveRefsQuery.php | 3 +- .../DiffusionLowLevelResolveRefsQuery.php | 44 +++++-------------- 2 files changed, 13 insertions(+), 34 deletions(-) diff --git a/src/applications/diffusion/query/DiffusionCachedResolveRefsQuery.php b/src/applications/diffusion/query/DiffusionCachedResolveRefsQuery.php index e09ae4d486..5dbadb3791 100644 --- a/src/applications/diffusion/query/DiffusionCachedResolveRefsQuery.php +++ b/src/applications/diffusion/query/DiffusionCachedResolveRefsQuery.php @@ -96,7 +96,7 @@ final class DiffusionCachedResolveRefsQuery $cursors = queryfx_all( $conn_r, - 'SELECT refNameHash, refType, commitIdentifier FROM %T + 'SELECT refNameHash, refType, commitIdentifier, isClosed FROM %T WHERE repositoryPHID = %s AND refNameHash IN (%Ls)', id(new PhabricatorRepositoryRefCursor())->getTableName(), $repository->getPHID(), @@ -107,6 +107,7 @@ final class DiffusionCachedResolveRefsQuery $results[$name_hashes[$cursor['refNameHash']]][] = array( 'type' => $cursor['refType'], 'identifier' => $cursor['commitIdentifier'], + 'closed' => (bool)$cursor['isClosed'], ); // TODO: In Git, we don't store (and thus don't return) the hash diff --git a/src/applications/diffusion/query/lowlevel/DiffusionLowLevelResolveRefsQuery.php b/src/applications/diffusion/query/lowlevel/DiffusionLowLevelResolveRefsQuery.php index 66ecbb2f2c..7d8c01d890 100644 --- a/src/applications/diffusion/query/lowlevel/DiffusionLowLevelResolveRefsQuery.php +++ b/src/applications/diffusion/query/lowlevel/DiffusionLowLevelResolveRefsQuery.php @@ -143,54 +143,32 @@ final class DiffusionLowLevelResolveRefsQuery // First, pull all of the branch heads in the repository. Doing this in // bulk is much faster than querying each individual head if we're // checking even a small number of refs. - $futures = array(); - $futures['all'] = $repository->getLocalCommandFuture( - 'log --template=%s --rev %s', - '{node} {branch}\\n', - hgsprintf('head()')); - $futures['open'] = $repository->getLocalCommandFuture( - 'log --template=%s --rev %s', - '{node} {branch}\\n', - hgsprintf('head() and not closed()')); + $branches = id(new DiffusionLowLevelMercurialBranchesQuery()) + ->setRepository($repository) + ->executeQuery(); - - $map = array(); - foreach (new FutureIterator($futures) as $key => $future) { - list($stdout) = $future->resolvex(); - $lines = phutil_split_lines($stdout, $retain_endings = false); - foreach ($lines as $idx => $line) { - list($node, $branch) = explode(' ', $line, 2); - $map[$branch]['nodes'][] = $node; - if ($key == 'open') { - $map[$branch]['open'] = true; - } - } - } + $branches = mgroup($branches, 'getShortName'); $results = array(); $unresolved = $this->refs; foreach ($unresolved as $key => $ref) { - if (!isset($map[$ref])) { + if (empty($branches[$ref])) { continue; } - $is_closed = !idx($map[$ref], 'open', false); - foreach ($map[$ref]['nodes'] as $node) { - $results[$ref][$node] = array( + foreach ($branches[$ref] as $branch) { + $fields = $branch->getRawFields(); + + $results[$ref][] = array( 'type' => 'branch', - 'identifier' => $node, - 'closed' => $is_closed, + 'identifier' => $branch->getCommitIdentifier(), + 'closed' => idx($fields, 'closed', false), ); } unset($unresolved[$key]); } - // Strip the node keys off the result list. - foreach ($results as $ref => $result_list) { - $results[$ref] = array_values($result_list); - } - if (!$unresolved) { return $results; }