Mercurial > public > mercurial-scm > hg-stable
diff mercurial/revlog.py @ 32704:af854b1b36f8
revlog: add support for partial matching of wdir node id
The idea is simple. If the given node id prefix is 'ff...f', add +1 to the
number of matches (e.g. ambiguous if partial + maybewdir > 1).
This patch also fixes id() revset and shortest() template since _partialmatch()
can raise WdirUnsupported exception.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Fri, 19 Aug 2016 18:26:04 +0900 |
parents | 7b17f9de6d3e |
children | 19b9fc40cc51 |
line wrap: on
line diff
--- a/mercurial/revlog.py Sat Aug 20 18:15:19 2016 +0900 +++ b/mercurial/revlog.py Fri Aug 19 18:26:04 2016 +0900 @@ -26,6 +26,7 @@ hex, nullid, nullrev, + wdirhex, wdirid, wdirrev, ) @@ -1038,10 +1039,17 @@ pass def _partialmatch(self, id): + maybewdir = wdirhex.startswith(id) try: partial = self.index.partialmatch(id) if partial and self.hasnode(partial): + if maybewdir: + # single 'ff...' match in radix tree, ambiguous with wdir + raise RevlogError return partial + if maybewdir: + # no 'ff...' match in radix tree, wdir identified + raise error.WdirUnsupported return None except RevlogError: # parsers.c radix tree lookup gave multiple matches @@ -1066,11 +1074,13 @@ nl = [n for n in nl if hex(n).startswith(id) and self.hasnode(n)] if len(nl) > 0: - if len(nl) == 1: + if len(nl) == 1 and not maybewdir: self._pcache[id] = nl[0] return nl[0] raise LookupError(id, self.indexfile, _('ambiguous identifier')) + if maybewdir: + raise error.WdirUnsupported return None except TypeError: pass