changeset 37680:e743b8524d60

scmutil: introduce shortesthexnodeidprefix() We have scmutil.resolvehexnodeidprefix() for resolving a prefix to a full nodeid, so it makes sense to have the inverse method next to it. For now it just delegates to changelog.shortest(), but it will soon also make sure it's called on the unfiltered repo, to match resolvehexnodeidprefix(). Note that the change in show.py also makes it so the conversion from revnum to nodeid is done on the filtered repo, but that should be inconsequential since the revs are all from the filtered repo anyway. Differential Revision: https://phab.mercurial-scm.org/D3370
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 13 Apr 2018 22:55:01 -0700
parents ab828755e1ea
children 3942bd8db8b2
files hgext/show.py mercurial/scmutil.py mercurial/templatefuncs.py
diffstat 3 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/show.py	Fri Apr 13 11:00:30 2018 -0700
+++ b/hgext/show.py	Fri Apr 13 22:55:01 2018 -0700
@@ -45,6 +45,7 @@
     registrar,
     revset,
     revsetlang,
+    scmutil,
 )
 
 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
@@ -447,8 +448,10 @@
     if not revs:
         return minlen
     # don't use filtered repo because it's slow. see templater.shortest().
-    cl = repo.unfiltered().changelog
-    return max(len(cl.shortest(hex(cl.node(r)), minlen)) for r in revs)
+    cl = repo.changelog
+    return max(len(scmutil.shortesthexnodeidprefix(repo.unfiltered(),
+                                                   hex(cl.node(r)),
+                                                   minlen)) for r in revs)
 
 # Adjust the docstring of the show command so it shows all registered views.
 # This is a bit hacky because it runs at the end of module load. When moved
--- a/mercurial/scmutil.py	Fri Apr 13 11:00:30 2018 -0700
+++ b/mercurial/scmutil.py	Fri Apr 13 22:55:01 2018 -0700
@@ -443,6 +443,10 @@
     repo.changelog.rev(node)  # make sure node isn't filtered
     return node
 
+def shortesthexnodeidprefix(repo, hexnode, minlength=1):
+    """Find the shortest unambiguous prefix that matches hexnode."""
+    return repo.changelog.shortest(hexnode, minlength)
+
 def isrevsymbol(repo, symbol):
     """Checks if a symbol exists in the repo.
 
--- a/mercurial/templatefuncs.py	Fri Apr 13 11:00:30 2018 -0700
+++ b/mercurial/templatefuncs.py	Fri Apr 13 22:55:01 2018 -0700
@@ -590,8 +590,8 @@
     # _partialmatch() of filtered changelog could take O(len(repo)) time,
     # which would be unacceptably slow. so we look for hash collision in
     # unfiltered space, which means some hashes may be slightly longer.
-    cl = context.resource(mapping, 'ctx')._repo.unfiltered().changelog
-    return cl.shortest(node, minlength)
+    repo = context.resource(mapping, 'ctx')._repo
+    return scmutil.shortesthexnodeidprefix(repo.unfiltered(), node, minlength)
 
 @templatefunc('strip(text[, chars])')
 def strip(context, mapping, args):