##// END OF EJS Templates
templater: extract shortest() logic from template function...
Martin von Zweigbergk -
r34247:448725a2 default
parent child Browse files
Show More
@@ -1128,6 +1128,44 b' class revlog(object):'
1128
1128
1129 raise LookupError(id, self.indexfile, _('no match found'))
1129 raise LookupError(id, self.indexfile, _('no match found'))
1130
1130
1131 def shortest(self, hexnode, minlength=1):
1132 """Find the shortest unambiguous prefix that matches hexnode."""
1133 def isvalid(test):
1134 try:
1135 if self._partialmatch(test) is None:
1136 return False
1137
1138 try:
1139 i = int(test)
1140 # if we are a pure int, then starting with zero will not be
1141 # confused as a rev; or, obviously, if the int is larger
1142 # than the value of the tip rev
1143 if test[0] == '0' or i > len(self):
1144 return True
1145 return False
1146 except ValueError:
1147 return True
1148 except error.RevlogError:
1149 return False
1150 except error.WdirUnsupported:
1151 # single 'ff...' match
1152 return True
1153
1154 shortest = hexnode
1155 startlength = max(6, minlength)
1156 length = startlength
1157 while True:
1158 test = hexnode[:length]
1159 if isvalid(test):
1160 shortest = test
1161 if length == minlength or length > startlength:
1162 return shortest
1163 length -= 1
1164 else:
1165 length += 1
1166 if len(shortest) <= length:
1167 return shortest
1168
1131 def cmp(self, node, text):
1169 def cmp(self, node, text):
1132 """compare text with a given file revision
1170 """compare text with a given file revision
1133
1171
@@ -1023,41 +1023,7 b' def shortest(context, mapping, args):'
1023 # which would be unacceptably slow. so we look for hash collision in
1023 # which would be unacceptably slow. so we look for hash collision in
1024 # unfiltered space, which means some hashes may be slightly longer.
1024 # unfiltered space, which means some hashes may be slightly longer.
1025 cl = mapping['ctx']._repo.unfiltered().changelog
1025 cl = mapping['ctx']._repo.unfiltered().changelog
1026 def isvalid(test):
1026 return cl.shortest(node, minlength)
1027 try:
1028 if cl._partialmatch(test) is None:
1029 return False
1030
1031 try:
1032 i = int(test)
1033 # if we are a pure int, then starting with zero will not be
1034 # confused as a rev; or, obviously, if the int is larger than
1035 # the value of the tip rev
1036 if test[0] == '0' or i > len(cl):
1037 return True
1038 return False
1039 except ValueError:
1040 return True
1041 except error.RevlogError:
1042 return False
1043 except error.WdirUnsupported:
1044 # single 'ff...' match
1045 return True
1046
1047 shortest = node
1048 startlength = max(6, minlength)
1049 length = startlength
1050 while True:
1051 test = node[:length]
1052 if isvalid(test):
1053 shortest = test
1054 if length == minlength or length > startlength:
1055 return shortest
1056 length -= 1
1057 else:
1058 length += 1
1059 if len(shortest) <= length:
1060 return shortest
1061
1027
1062 @templatefunc('strip(text[, chars])')
1028 @templatefunc('strip(text[, chars])')
1063 def strip(context, mapping, args):
1029 def strip(context, mapping, args):
General Comments 0
You need to be logged in to leave comments. Login now