Mercurial > hg-stable
changeset 38880: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 | 794afa91f0a5 |
children | 503f936489dd |
files | mercurial/error.py mercurial/localrepo.py mercurial/revlog.py mercurial/scmutil.py |
diffstat | 4 files changed, 12 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/error.py Thu Aug 02 22:44:41 2018 +0300 +++ b/mercurial/error.py Fri Apr 13 23:37:53 2018 -0700 @@ -58,6 +58,9 @@ def __str__(self): return RevlogError.__str__(self) +class AmbiguousPrefixLookupError(LookupError): + pass + class FilteredLookupError(LookupError): pass
--- a/mercurial/localrepo.py Thu Aug 02 22:44:41 2018 +0300 +++ b/mercurial/localrepo.py Fri Apr 13 23:37:53 2018 -0700 @@ -860,7 +860,8 @@ def __contains__(self, changeid): """True if the given changeid exists - error.LookupError is raised if an ambiguous node specified. + error.AmbiguousPrefixLookupError is raised if an ambiguous node + specified. """ try: self[changeid]
--- a/mercurial/revlog.py Thu Aug 02 22:44:41 2018 +0300 +++ b/mercurial/revlog.py Fri Apr 13 23:37:53 2018 -0700 @@ -91,6 +91,7 @@ RevlogError = error.RevlogError LookupError = error.LookupError +AmbiguousPrefixLookupError = error.AmbiguousPrefixLookupError CensoredNodeError = error.CensoredNodeError ProgrammingError = error.ProgrammingError @@ -1788,8 +1789,8 @@ # parsers.c radix tree lookup gave multiple matches # fast path: for unfiltered changelog, radix tree is accurate if not getattr(self, 'filteredrevs', None): - raise LookupError(id, self.indexfile, - _('ambiguous identifier')) + raise AmbiguousPrefixLookupError(id, self.indexfile, + _('ambiguous identifier')) # fall through to slow path that filters hidden revisions except (AttributeError, ValueError): # we are pure python, or key was too short to search radix tree @@ -1810,8 +1811,8 @@ if len(nl) == 1 and not maybewdir: self._pcache[id] = nl[0] return nl[0] - raise LookupError(id, self.indexfile, - _('ambiguous identifier')) + raise AmbiguousPrefixLookupError(id, self.indexfile, + _('ambiguous identifier')) if maybewdir: raise error.WdirUnsupported return None
--- a/mercurial/scmutil.py Thu Aug 02 22:44:41 2018 +0300 +++ b/mercurial/scmutil.py Fri Apr 13 23:37:53 2018 -0700 @@ -480,8 +480,8 @@ def isrevsymbol(repo, symbol): """Checks if a symbol exists in the repo. - See revsymbol() for details. Raises error.LookupError if the symbol is an - ambiguous nodeid prefix. + See revsymbol() for details. Raises error.AmbiguousPrefixLookupError if the + symbol is an ambiguous nodeid prefix. """ try: revsymbol(repo, symbol)