comparison mercurial/revlog.py @ 7365:ec3aafa84d44

lookup: speed up partial lookup
author Matt Mackall <mpm@selenic.com>
date Wed, 12 Nov 2008 19:11:34 -0600
parents 9d28ff207030
children 08cabecfa8a8
comparison
equal deleted inserted replaced
7364:ad7f736f3214 7365:ec3aafa84d44
871 871
872 def _partialmatch(self, id): 872 def _partialmatch(self, id):
873 if len(id) < 40: 873 if len(id) < 40:
874 try: 874 try:
875 # hex(node)[:...] 875 # hex(node)[:...]
876 bin_id = bin(id[:len(id) & ~1]) # grab an even number of digits 876 l = len(id) / 2 # grab an even number of digits
877 node = None 877 bin_id = bin(id[:l*2])
878 for n in self.nodemap: 878 nl = [n for n in self.nodemap if n[:l] == bin_id]
879 if n.startswith(bin_id) and hex(n).startswith(id): 879 nl = [n for n in nl if hex(n).startswith(id)]
880 if node is not None: 880 if len(nl) > 0:
881 raise LookupError(id, self.indexfile, 881 if len(nl) == 1:
882 _('ambiguous identifier')) 882 return nl[0]
883 node = n 883 raise LookupError(id, self.indexfile,
884 if node is not None: 884 _('ambiguous identifier'))
885 return node 885 return None
886 except TypeError: 886 except TypeError:
887 pass 887 pass
888 888
889 def lookup(self, id): 889 def lookup(self, id):
890 """locate a node based on: 890 """locate a node based on: