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

Yuya Nishihara yuya at tcha.org
Sun Oct 23 02:35:21 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 abbc5e382e1cb550f6d2ac886dfdb16bd95475ab
# Parent  f180a39d749aeacb72936e629a372623b1f88b8c
changectx: do not include hidden revisions on short node lookup (issue4964)

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

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
@@ -3477,6 +3477,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