Mercurial > hg-stable
changeset 47305:93a0abe098e7
revlog: avoid raising no-arg RevlogError for internal flow control
I'm about to make RevlogError require a `message` argument and this
code was failing. This patch refactors it to not raise an exception
for intra-function flow control.
Differential Revision: https://phab.mercurial-scm.org/D10740
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Tue, 18 May 2021 19:33:09 -0700 |
parents | 7a769ac49637 |
children | dd339191f2dc |
files | mercurial/revlog.py |
diffstat | 1 files changed, 12 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/revlog.py Tue May 18 21:45:59 2021 -0700 +++ b/mercurial/revlog.py Tue May 18 19:33:09 2021 -0700 @@ -1538,28 +1538,33 @@ def _partialmatch(self, id): # we don't care wdirfilenodeids as they should be always full hash maybewdir = self.nodeconstants.wdirhex.startswith(id) + ambiguous = False try: partial = self.index.partialmatch(id) if partial and self.hasnode(partial): if maybewdir: # single 'ff...' match in radix tree, ambiguous with wdir - raise error.RevlogError - return partial - if maybewdir: + ambiguous = True + else: + return partial + elif maybewdir: # no 'ff...' match in radix tree, wdir identified raise error.WdirUnsupported - return None + else: + return None except error.RevlogError: # parsers.c radix tree lookup gave multiple matches # fast path: for unfiltered changelog, radix tree is accurate if not getattr(self, 'filteredrevs', None): - raise error.AmbiguousPrefixLookupError( - id, self.display_id, _(b'ambiguous identifier') - ) + ambiguous = True # 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 pass + if ambiguous: + raise error.AmbiguousPrefixLookupError( + id, self.display_id, _(b'ambiguous identifier') + ) if id in self._pcache: return self._pcache[id]