D3370: scmutil: introduce shortesthexnodeidprefix()

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Sat Apr 14 04:12:41 EDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHGe743b8524d60: scmutil: introduce shortesthexnodeidprefix() (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3370?vs=8254&id=8262

REVISION DETAIL
  https://phab.mercurial-scm.org/D3370

AFFECTED FILES
  hgext/show.py
  mercurial/scmutil.py
  mercurial/templatefuncs.py

CHANGE DETAILS

diff --git a/mercurial/templatefuncs.py b/mercurial/templatefuncs.py
--- a/mercurial/templatefuncs.py
+++ b/mercurial/templatefuncs.py
@@ -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):
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -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.
 
diff --git a/hgext/show.py b/hgext/show.py
--- a/hgext/show.py
+++ b/hgext/show.py
@@ -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



To: martinvonz, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list