comparison mercurial/revlog.py @ 19471:fd1bb7c1be78 stable

revlog: handle hidden revs in _partialmatch (issue3979) Looking up hidden prefixes could cause a no node exception Looking up unique non-hidden prefixes could be ambiguous
author Matt Mackall <mpm@selenic.com>
date Tue, 23 Jul 2013 17:28:12 -0500
parents 7014526d67a8
children 55749cb14d24 e92650e39f1c
comparison
equal deleted inserted replaced
19470:19ac0d8ee9a2 19471:fd1bb7c1be78
749 except (TypeError, LookupError): 749 except (TypeError, LookupError):
750 pass 750 pass
751 751
752 def _partialmatch(self, id): 752 def _partialmatch(self, id):
753 try: 753 try:
754 return self.index.partialmatch(id) 754 n = self.index.partialmatch(id)
755 if n and self.hasnode(n):
756 return n
757 return None
755 except RevlogError: 758 except RevlogError:
756 # parsers.c radix tree lookup gave multiple matches 759 # parsers.c radix tree lookup gave multiple matches
757 raise LookupError(id, self.indexfile, _("ambiguous identifier")) 760 # fall through to slow path that filters hidden revisions
761 pass
758 except (AttributeError, ValueError): 762 except (AttributeError, ValueError):
759 # we are pure python, or key was too short to search radix tree 763 # we are pure python, or key was too short to search radix tree
760 pass 764 pass
761 765
762 if id in self._pcache: 766 if id in self._pcache:
766 try: 770 try:
767 # hex(node)[:...] 771 # hex(node)[:...]
768 l = len(id) // 2 # grab an even number of digits 772 l = len(id) // 2 # grab an even number of digits
769 prefix = bin(id[:l * 2]) 773 prefix = bin(id[:l * 2])
770 nl = [e[7] for e in self.index if e[7].startswith(prefix)] 774 nl = [e[7] for e in self.index if e[7].startswith(prefix)]
771 nl = [n for n in nl if hex(n).startswith(id)] 775 nl = [n for n in nl if hex(n).startswith(id) and
776 self.hasnode(n)]
772 if len(nl) > 0: 777 if len(nl) > 0:
773 if len(nl) == 1: 778 if len(nl) == 1:
774 self._pcache[id] = nl[0] 779 self._pcache[id] = nl[0]
775 return nl[0] 780 return nl[0]
776 raise LookupError(id, self.indexfile, 781 raise LookupError(id, self.indexfile,