1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 05:12:41 +01:00

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
This commit is contained in:
epriestley 2015-04-27 03:50:55 -07:00
parent 946ea3bffa
commit 2c9b194d16
2 changed files with 13 additions and 34 deletions

View file

@ -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

View file

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