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:
parent
946ea3bffa
commit
2c9b194d16
2 changed files with 13 additions and 34 deletions
|
@ -96,7 +96,7 @@ final class DiffusionCachedResolveRefsQuery
|
||||||
|
|
||||||
$cursors = queryfx_all(
|
$cursors = queryfx_all(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
'SELECT refNameHash, refType, commitIdentifier FROM %T
|
'SELECT refNameHash, refType, commitIdentifier, isClosed FROM %T
|
||||||
WHERE repositoryPHID = %s AND refNameHash IN (%Ls)',
|
WHERE repositoryPHID = %s AND refNameHash IN (%Ls)',
|
||||||
id(new PhabricatorRepositoryRefCursor())->getTableName(),
|
id(new PhabricatorRepositoryRefCursor())->getTableName(),
|
||||||
$repository->getPHID(),
|
$repository->getPHID(),
|
||||||
|
@ -107,6 +107,7 @@ final class DiffusionCachedResolveRefsQuery
|
||||||
$results[$name_hashes[$cursor['refNameHash']]][] = array(
|
$results[$name_hashes[$cursor['refNameHash']]][] = array(
|
||||||
'type' => $cursor['refType'],
|
'type' => $cursor['refType'],
|
||||||
'identifier' => $cursor['commitIdentifier'],
|
'identifier' => $cursor['commitIdentifier'],
|
||||||
|
'closed' => (bool)$cursor['isClosed'],
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: In Git, we don't store (and thus don't return) the hash
|
// TODO: In Git, we don't store (and thus don't return) the hash
|
||||||
|
|
|
@ -143,54 +143,32 @@ final class DiffusionLowLevelResolveRefsQuery
|
||||||
// First, pull all of the branch heads in the repository. Doing this in
|
// 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
|
// bulk is much faster than querying each individual head if we're
|
||||||
// checking even a small number of refs.
|
// checking even a small number of refs.
|
||||||
$futures = array();
|
$branches = id(new DiffusionLowLevelMercurialBranchesQuery())
|
||||||
$futures['all'] = $repository->getLocalCommandFuture(
|
->setRepository($repository)
|
||||||
'log --template=%s --rev %s',
|
->executeQuery();
|
||||||
'{node} {branch}\\n',
|
|
||||||
hgsprintf('head()'));
|
|
||||||
$futures['open'] = $repository->getLocalCommandFuture(
|
|
||||||
'log --template=%s --rev %s',
|
|
||||||
'{node} {branch}\\n',
|
|
||||||
hgsprintf('head() and not closed()'));
|
|
||||||
|
|
||||||
|
$branches = mgroup($branches, 'getShortName');
|
||||||
$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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$results = array();
|
$results = array();
|
||||||
$unresolved = $this->refs;
|
$unresolved = $this->refs;
|
||||||
foreach ($unresolved as $key => $ref) {
|
foreach ($unresolved as $key => $ref) {
|
||||||
if (!isset($map[$ref])) {
|
if (empty($branches[$ref])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$is_closed = !idx($map[$ref], 'open', false);
|
foreach ($branches[$ref] as $branch) {
|
||||||
foreach ($map[$ref]['nodes'] as $node) {
|
$fields = $branch->getRawFields();
|
||||||
$results[$ref][$node] = array(
|
|
||||||
|
$results[$ref][] = array(
|
||||||
'type' => 'branch',
|
'type' => 'branch',
|
||||||
'identifier' => $node,
|
'identifier' => $branch->getCommitIdentifier(),
|
||||||
'closed' => $is_closed,
|
'closed' => idx($fields, 'closed', false),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($unresolved[$key]);
|
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) {
|
if (!$unresolved) {
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue