Mercurial > hg
changeset 7365:ec3aafa84d44
lookup: speed up partial lookup
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 12 Nov 2008 19:11:34 -0600 |
parents | ad7f736f3214 |
children | eb240755386d |
files | mercurial/revlog.py |
diffstat | 1 files changed, 10 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/revlog.py Wed Nov 12 19:11:09 2008 -0600 +++ b/mercurial/revlog.py Wed Nov 12 19:11:34 2008 -0600 @@ -873,16 +873,16 @@ if len(id) < 40: try: # hex(node)[:...] - bin_id = bin(id[:len(id) & ~1]) # grab an even number of digits - node = None - for n in self.nodemap: - if n.startswith(bin_id) and hex(n).startswith(id): - if node is not None: - raise LookupError(id, self.indexfile, - _('ambiguous identifier')) - node = n - if node is not None: - return node + l = len(id) / 2 # grab an even number of digits + bin_id = bin(id[:l*2]) + nl = [n for n in self.nodemap if n[:l] == bin_id] + nl = [n for n in nl if hex(n).startswith(id)] + if len(nl) > 0: + if len(nl) == 1: + return nl[0] + raise LookupError(id, self.indexfile, + _('ambiguous identifier')) + return None except TypeError: pass