##// END OF EJS Templates
revset: optimize building large lists in formatrevspec...
Matt Mackall -
r15898:6902e13d default
parent child Browse files
Show More
@@ -863,6 +863,16 b' def user(repo, subset, x):'
863 863 """
864 864 return author(repo, subset, x)
865 865
866 # for internal use
867 def _list(repo, subset, x):
868 s = getstring(x, "internal error")
869 if not s:
870 return []
871 if not isinstance(subset, set):
872 subset = set(subset)
873 ls = [repo[r].rev() for r in s.split('\0')]
874 return [r for r in ls if r in subset]
875
866 876 symbols = {
867 877 "adds": adds,
868 878 "all": getall,
@@ -910,6 +920,7 b' symbols = {'
910 920 "tag": tag,
911 921 "tagged": tagged,
912 922 "user": user,
923 "_list": _list,
913 924 }
914 925
915 926 methods = {
@@ -1095,7 +1106,7 b' def formatspec(expr, *args):'
1095 1106 >>> formatspec('%d:: and not %d::', 10, 20)
1096 1107 '10:: and not 20::'
1097 1108 >>> formatspec('%ld or %ld', [], [1])
1098 '(0-0) or 1'
1109 "_list('') or 1"
1099 1110 >>> formatspec('keyword(%s)', 'foo\\xe9')
1100 1111 "keyword('foo\\\\xe9')"
1101 1112 >>> b = lambda: 'default'
@@ -1103,7 +1114,7 b' def formatspec(expr, *args):'
1103 1114 >>> formatspec('branch(%b)', b)
1104 1115 "branch('default')"
1105 1116 >>> formatspec('root(%ls)', ['a', 'b', 'c', 'd'])
1106 "root((('a' or 'b') or ('c' or 'd')))"
1117 "root(_list('a\\x00b\\x00c\\x00d'))"
1107 1118 '''
1108 1119
1109 1120 def quote(s):
@@ -1123,12 +1134,20 b' def formatspec(expr, *args):'
1123 1134 return quote(arg.branch())
1124 1135
1125 1136 def listexp(s, t):
1126 "balance a list s of type t to limit parse tree depth"
1127 1137 l = len(s)
1128 1138 if l == 0:
1129 return '(0-0)' # a minimal way to represent an empty set
1130 if l == 1:
1139 return "_list('')"
1140 elif l == 1:
1131 1141 return argtype(t, s[0])
1142 elif t == 'd':
1143 return "_list('%s')" % "\0".join(str(int(a)) for a in s)
1144 elif t == 's':
1145 return "_list('%s')" % "\0".join(s)
1146 elif t == 'n':
1147 return "_list('%s')" % "\0".join(nodemod.hex(a) for a in s)
1148 elif t == 'b':
1149 return "_list('%s')" % "\0".join(a.branch() for a in s)
1150
1132 1151 m = l // 2
1133 1152 return '(%s or %s)' % (listexp(s[:m], t), listexp(s[m:], t))
1134 1153
General Comments 0
You need to be logged in to leave comments. Login now