[PATCH 3 of 3 STABLE V2] changectx: do not include hidden revisions on short node lookup (issue4964)

Yuya Nishihara yuya at tcha.org
Tue Oct 25 10:17:14 EDT 2016


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1477199774 -32400
#      Sun Oct 23 14:16:14 2016 +0900
# Branch stable
# Node ID 242b7a856495179795ee5662f298029c4b492563
# Parent  ecbce2fe4dea116c925a2fecd1b7b50df0a62589
changectx: do not include hidden revisions on short node lookup (issue4964)

It was changed at dc25ed84bee8, but which seems wrong since we filtered out
hidden nodes by _partialmatch() before that change. This patch makes
changectx() be consistent with the filtered changelog, and detect a hidden
short node only if it has no unique match in the filtered changelog.

Though we've made shortest(node) use unfiltered changelog, I think this is
a separate issue worth fixing.

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -481,11 +481,16 @@ class changectx(basectx):
             except error.RepoLookupError:
                 pass
 
-            self._node = repo.unfiltered().changelog._partialmatch(changeid)
+            self._node = repo.changelog._partialmatch(changeid)
             if self._node is not None:
                 self._rev = repo.changelog.rev(self._node)
                 return
 
+            # lookup hidden node to provide a better error indication
+            n = repo.unfiltered().changelog._partialmatch(changeid)
+            if n is not None:
+                repo.changelog.rev(n)  # must raise FilteredLookupError
+
             # lookup failed
             # check if it might have come from damaged dirstate
             #
diff --git a/tests/test-command-template.t b/tests/test-command-template.t
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -3478,6 +3478,15 @@ Test shortest(node) with the repo having
   9:c5623
   10:c562d
 
+ since 'c562' is unique, it should be usable as an revision identifier
+ if the other 'c562' nodes are hidden
+
+  $ hg log -r c562 -T '{rev}:{node}\n'
+  8:c56256a09cd28e5764f32e8e2810d0f01e2e357a
+  $ hg log -r c562 -T '{rev}:{node}\n' --hidden
+  abort: 00changelog.i at c562: ambiguous identifier!
+  [255]
+
   $ cd ..
 
 Test pad function


More information about the Mercurial-devel mailing list