changeset 37504:901e749ca0e1

context: extract partial nodeid lookup method to scmutil We will add another caller soon, and there's a non-obvious reason to use the unfiltered repo that we don't want to copy across the code base. Differential Revision: https://phab.mercurial-scm.org/D3189
author Martin von Zweigbergk <martinvonz@google.com>
date Sun, 08 Apr 2018 08:06:34 -0700
parents 49a8c2cc7978
children 966061b8826d
files mercurial/context.py mercurial/scmutil.py
diffstat 2 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/context.py	Mon Mar 19 20:23:27 2018 +0900
+++ b/mercurial/context.py	Sun Apr 08 08:06:34 2018 -0700
@@ -450,7 +450,7 @@
             except KeyError:
                 pass
 
-            self._node = repo.unfiltered().changelog._partialmatch(changeid)
+            self._node = scmutil.resolvepartialhexnodeid(repo, changeid)
             if self._node is not None:
                 self._rev = repo.changelog.rev(self._node)
                 return
--- a/mercurial/scmutil.py	Mon Mar 19 20:23:27 2018 +0900
+++ b/mercurial/scmutil.py	Sun Apr 08 08:06:34 2018 -0700
@@ -433,6 +433,15 @@
         hexfunc = short
     return '%d:%s' % (rev, hexfunc(node))
 
+def resolvepartialhexnodeid(repo, prefix):
+    # Uses unfiltered repo because it's faster when then prefix is ambiguous/
+    # This matches the "shortest" template function.
+    node = repo.unfiltered().changelog._partialmatch(prefix)
+    if node is None:
+        return
+    repo.changelog.rev(node)  # make sure node isn't filtered
+    return node
+
 def isrevsymbol(repo, symbol):
     try:
         revsymbol(repo, symbol)