Mercurial > hg
changeset 37969:0db7fe7c34d3
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
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 03 May 2018 15:01:33 -0700 |
parents | 0304f22497fa |
children | 76e933e0ccc9 |
files | mercurial/revlog.py |
diffstat | 1 files changed, 9 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/revlog.py Wed May 02 23:17:58 2018 -0700 +++ b/mercurial/revlog.py Thu May 03 15:01:33 2018 -0700 @@ -1542,31 +1542,22 @@ 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