changeset 37708:8e8541610d85

scmutil: make shortesthexnodeidprefix() use unfiltered repo Both callers were doing this, and resolvehexnodeidprefix() was also working on the unfiltered repo, so it makes more sense to have it all in one place. Differential Revision: https://phab.mercurial-scm.org/D3313
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 13 Apr 2018 10:36:03 -0700
parents 24fee31fda05
children 7b2955624777
files hgext/show.py mercurial/scmutil.py mercurial/templatefuncs.py
diffstat 3 files changed, 7 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/show.py	Sun Apr 15 19:41:34 2018 +0800
+++ b/hgext/show.py	Fri Apr 13 10:36:03 2018 -0700
@@ -447,10 +447,8 @@
     """
     if not revs:
         return minlen
-    # don't use filtered repo because it's slow. see templater.shortest().
     cl = repo.changelog
-    return max(len(scmutil.shortesthexnodeidprefix(repo.unfiltered(),
-                                                   hex(cl.node(r)),
+    return max(len(scmutil.shortesthexnodeidprefix(repo, hex(cl.node(r)),
                                                    minlen)) for r in revs)
 
 # Adjust the docstring of the show command so it shows all registered views.
--- a/mercurial/scmutil.py	Sun Apr 15 19:41:34 2018 +0800
+++ b/mercurial/scmutil.py	Fri Apr 13 10:36:03 2018 -0700
@@ -436,7 +436,7 @@
 
 def resolvehexnodeidprefix(repo, prefix):
     # Uses unfiltered repo because it's faster when prefix is ambiguous/
-    # This matches the "shortest" template function.
+    # This matches the shortesthexnodeidprefix() function below.
     node = repo.unfiltered().changelog._partialmatch(prefix)
     if node is None:
         return
@@ -445,7 +445,10 @@
 
 def shortesthexnodeidprefix(repo, hexnode, minlength=1):
     """Find the shortest unambiguous prefix that matches hexnode."""
-    return repo.changelog.shortest(hexnode, minlength)
+    # _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.
+    return repo.unfiltered().changelog.shortest(hexnode, minlength)
 
 def isrevsymbol(repo, symbol):
     """Checks if a symbol exists in the repo.
--- a/mercurial/templatefuncs.py	Sun Apr 15 19:41:34 2018 +0800
+++ b/mercurial/templatefuncs.py	Fri Apr 13 10:36:03 2018 -0700
@@ -587,11 +587,8 @@
                                 # i18n: "shortest" is a keyword
                                 _("shortest() expects an integer minlength"))
 
-    # _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.
     repo = context.resource(mapping, 'ctx')._repo
-    return scmutil.shortesthexnodeidprefix(repo.unfiltered(), node, minlength)
+    return scmutil.shortesthexnodeidprefix(repo, node, minlength)
 
 @templatefunc('strip(text[, chars])')
 def strip(context, mapping, args):