Page MenuHomePhabricator

D18717.id.diff
No OneTemporary

D18717.id.diff

diff --git a/src/applications/diffusion/query/lowlevel/DiffusionLowLevelResolveRefsQuery.php b/src/applications/diffusion/query/lowlevel/DiffusionLowLevelResolveRefsQuery.php
--- a/src/applications/diffusion/query/lowlevel/DiffusionLowLevelResolveRefsQuery.php
+++ b/src/applications/diffusion/query/lowlevel/DiffusionLowLevelResolveRefsQuery.php
@@ -256,6 +256,66 @@
return $results;
}
+ // If some of the refs look like hashes, try to bulk resolve them. This
+ // workflow happens via RefEngine and bulk resolution is dramatically
+ // faster than individual resolution. See PHI158.
+
+ $hashlike = array();
+ foreach ($unresolved as $key => $ref) {
+ if (preg_match('/^[a-f0-9]{40}\z/', $ref)) {
+ $hashlike[$key] = $ref;
+ }
+ }
+
+ if (count($hashlike) > 1) {
+ $hashlike_map = array();
+
+ $hashlike_groups = array_chunk($hashlike, 64, true);
+ foreach ($hashlike_groups as $hashlike_group) {
+ $hashlike_arg = array();
+ foreach ($hashlike_group as $hashlike_ref) {
+ $hashlike_arg[] = hgsprintf('%s', $hashlike_ref);
+ }
+ $hashlike_arg = '('.implode(' or ', $hashlike_arg).')';
+
+ list($err, $refs) = $repository->execLocalCommand(
+ 'log --template=%s --rev %s',
+ '{node}\n',
+ $hashlike_arg);
+ if ($err) {
+ // NOTE: If any ref fails to resolve, Mercurial will exit with an
+ // error. We just give up on the whole group and resolve it
+ // individually below. In theory, we could split it into subgroups
+ // but the pathway where this bulk resolution matters rarely tries
+ // to resolve missing refs (see PHI158).
+ continue;
+ }
+
+ $refs = phutil_split_lines($refs, false);
+
+ foreach ($refs as $ref) {
+ $hashlike_map[$ref] = true;
+ }
+ }
+
+ foreach ($unresolved as $key => $ref) {
+ if (!isset($hashlike_map[$ref])) {
+ continue;
+ }
+
+ $results[$ref][] = array(
+ 'type' => 'commit',
+ 'identifier' => $ref,
+ );
+
+ unset($unresolved[$key]);
+ }
+ }
+
+ if (!$unresolved) {
+ return $results;
+ }
+
// If we still have unresolved refs (which might be things like "tip"),
// try to resolve them individually.

File Metadata

Mime Type
text/plain
Expires
Oct 17 2024, 8:11 AM (4 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6714337
Default Alt Text
D18717.id.diff (2 KB)

Event Timeline