Mercurial > hg-stable
diff hgext/show.py @ 35502:dfaf9f10e2e5
show: use revlog function to compute length of the longest shortest node
As the core part of shortest() was extracted at 448725a2ef73, we no logner
need a templater.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 25 Dec 2017 22:56:59 +0900 |
parents | f1c54d003327 |
children | c8e2d6ed1f9e |
line wrap: on
line diff
--- a/hgext/show.py Tue Dec 19 11:20:35 2017 +0530 +++ b/hgext/show.py Mon Dec 25 22:56:59 2017 +0900 @@ -28,7 +28,10 @@ from __future__ import absolute_import from mercurial.i18n import _ -from mercurial.node import nullrev +from mercurial.node import ( + hex, + nullrev, +) from mercurial import ( cmdutil, commands, @@ -440,17 +443,11 @@ If we fail to do this, a value of e.g. ``10023`` could mean either revision 10023 or node ``10023abc...``. """ - tres = formatter.templateresources(repo.ui, repo) - tmpl = formatter.maketemplater(repo.ui, '{shortest(node, %d)}' % minlen, - resources=tres) - - lens = [minlen] - for rev in revs: - ctx = repo[rev] - shortest = tmpl.render({'ctx': ctx, 'node': ctx.hex()}) - lens.append(len(shortest)) - - return max(lens) + 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) # 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