# HG changeset patch # User Martin von Zweigbergk # Date 2018-05-03 22:01:33 # Node ID 0db7fe7c34d36cf341e8c260b641b19377759ef8 # Parent 0304f22497fafcfeedf80fb0698d888ee41a2135 shortest: make pure code also disambigute against revnums at end This makes the pure code more similar to the native code in that it first finds a prefix that's unambiguous among nodeids and then adds hex digits until it no longer looks like a revnum. It will allow us to even better separate the disambiguation with revnums in a later patch. With this patch `hg log -r 0::50 -T '{shortest(node,1)}'` with no native code goes from 25s to 43s. It wasn't exactly usable to begin with, so I don't feel too bad about it. Differential Revision: https://phab.mercurial-scm.org/D3500 diff --git a/mercurial/revlog.py b/mercurial/revlog.py --- a/mercurial/revlog.py +++ b/mercurial/revlog.py @@ -1542,31 +1542,22 @@ class revlog(object): length = max(self.index.shortest(node), minlength) return disambiguate(hexnode, length) except RevlogError: - if node == wdirid: - for length in range(minlength, 41): - prefix = hexnode[:length] - if isvalid(prefix): - return prefix - else: + if node != wdirid: raise LookupError(node, self.indexfile, _('no node')) except AttributeError: # Fall through to pure code pass - shortest = hexnode - startlength = max(6, minlength) - length = startlength - while True: + if node == wdirid: + for length in range(minlength, 41): + prefix = hexnode[:length] + if isvalid(prefix): + return prefix + + for length in range(minlength, 41): prefix = hexnode[:length] if isvalid(prefix): - shortest = prefix - if length == minlength or length > startlength: - return shortest - length -= 1 - else: - length += 1 - if len(shortest) <= length: - return shortest + return disambiguate(hexnode, length) def cmp(self, node, text): """compare text with a given file revision