comparison mercurial/revlog.py @ 38841:df0873ab5c14

revlog: use specialized exception for ambiguous prefix lookup It's useful to be able to catch a specific exception for this case. We'll use it soon. Differential Revision: https://phab.mercurial-scm.org/D4036
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 13 Apr 2018 23:37:53 -0700
parents e7aa113b14f7
children 119d14f41cb2
comparison
equal deleted inserted replaced
38840:794afa91f0a5 38841:df0873ab5c14
89 _maxinline = 131072 89 _maxinline = 131072
90 _chunksize = 1048576 90 _chunksize = 1048576
91 91
92 RevlogError = error.RevlogError 92 RevlogError = error.RevlogError
93 LookupError = error.LookupError 93 LookupError = error.LookupError
94 AmbiguousPrefixLookupError = error.AmbiguousPrefixLookupError
94 CensoredNodeError = error.CensoredNodeError 95 CensoredNodeError = error.CensoredNodeError
95 ProgrammingError = error.ProgrammingError 96 ProgrammingError = error.ProgrammingError
96 97
97 # Store flag processors (cf. 'addflagprocessor()' to register) 98 # Store flag processors (cf. 'addflagprocessor()' to register)
98 _flagprocessors = { 99 _flagprocessors = {
1786 return None 1787 return None
1787 except RevlogError: 1788 except RevlogError:
1788 # parsers.c radix tree lookup gave multiple matches 1789 # parsers.c radix tree lookup gave multiple matches
1789 # fast path: for unfiltered changelog, radix tree is accurate 1790 # fast path: for unfiltered changelog, radix tree is accurate
1790 if not getattr(self, 'filteredrevs', None): 1791 if not getattr(self, 'filteredrevs', None):
1791 raise LookupError(id, self.indexfile, 1792 raise AmbiguousPrefixLookupError(id, self.indexfile,
1792 _('ambiguous identifier')) 1793 _('ambiguous identifier'))
1793 # fall through to slow path that filters hidden revisions 1794 # fall through to slow path that filters hidden revisions
1794 except (AttributeError, ValueError): 1795 except (AttributeError, ValueError):
1795 # we are pure python, or key was too short to search radix tree 1796 # we are pure python, or key was too short to search radix tree
1796 pass 1797 pass
1797 1798
1808 self.hasnode(n)] 1809 self.hasnode(n)]
1809 if len(nl) > 0: 1810 if len(nl) > 0:
1810 if len(nl) == 1 and not maybewdir: 1811 if len(nl) == 1 and not maybewdir:
1811 self._pcache[id] = nl[0] 1812 self._pcache[id] = nl[0]
1812 return nl[0] 1813 return nl[0]
1813 raise LookupError(id, self.indexfile, 1814 raise AmbiguousPrefixLookupError(id, self.indexfile,
1814 _('ambiguous identifier')) 1815 _('ambiguous identifier'))
1815 if maybewdir: 1816 if maybewdir:
1816 raise error.WdirUnsupported 1817 raise error.WdirUnsupported
1817 return None 1818 return None
1818 except TypeError: 1819 except TypeError:
1819 pass 1820 pass