comparison 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
comparison
equal deleted inserted replaced
32703:9f840d99054c 32704:af854b1b36f8
24 from .node import ( 24 from .node import (
25 bin, 25 bin,
26 hex, 26 hex,
27 nullid, 27 nullid,
28 nullrev, 28 nullrev,
29 wdirhex,
29 wdirid, 30 wdirid,
30 wdirrev, 31 wdirrev,
31 ) 32 )
32 from .i18n import _ 33 from .i18n import _
33 from . import ( 34 from . import (
1036 return node 1037 return node
1037 except (TypeError, LookupError): 1038 except (TypeError, LookupError):
1038 pass 1039 pass
1039 1040
1040 def _partialmatch(self, id): 1041 def _partialmatch(self, id):
1042 maybewdir = wdirhex.startswith(id)
1041 try: 1043 try:
1042 partial = self.index.partialmatch(id) 1044 partial = self.index.partialmatch(id)
1043 if partial and self.hasnode(partial): 1045 if partial and self.hasnode(partial):
1046 if maybewdir:
1047 # single 'ff...' match in radix tree, ambiguous with wdir
1048 raise RevlogError
1044 return partial 1049 return partial
1050 if maybewdir:
1051 # no 'ff...' match in radix tree, wdir identified
1052 raise error.WdirUnsupported
1045 return None 1053 return None
1046 except RevlogError: 1054 except RevlogError:
1047 # parsers.c radix tree lookup gave multiple matches 1055 # parsers.c radix tree lookup gave multiple matches
1048 # fast path: for unfiltered changelog, radix tree is accurate 1056 # fast path: for unfiltered changelog, radix tree is accurate
1049 if not getattr(self, 'filteredrevs', None): 1057 if not getattr(self, 'filteredrevs', None):
1064 prefix = bin(id[:l * 2]) 1072 prefix = bin(id[:l * 2])
1065 nl = [e[7] for e in self.index if e[7].startswith(prefix)] 1073 nl = [e[7] for e in self.index if e[7].startswith(prefix)]
1066 nl = [n for n in nl if hex(n).startswith(id) and 1074 nl = [n for n in nl if hex(n).startswith(id) and
1067 self.hasnode(n)] 1075 self.hasnode(n)]
1068 if len(nl) > 0: 1076 if len(nl) > 0:
1069 if len(nl) == 1: 1077 if len(nl) == 1 and not maybewdir:
1070 self._pcache[id] = nl[0] 1078 self._pcache[id] = nl[0]
1071 return nl[0] 1079 return nl[0]
1072 raise LookupError(id, self.indexfile, 1080 raise LookupError(id, self.indexfile,
1073 _('ambiguous identifier')) 1081 _('ambiguous identifier'))
1082 if maybewdir:
1083 raise error.WdirUnsupported
1074 return None 1084 return None
1075 except TypeError: 1085 except TypeError:
1076 pass 1086 pass
1077 1087
1078 def lookup(self, id): 1088 def lookup(self, id):