comparison mercurial/revset.py @ 32801:348b491c0934

revset: fix order of first/last members in compound expression (BC) Suppose len(subset) >> len(ls) in common cases, 'subset & ls' should be avoided whenever possible.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 10 Jun 2017 19:48:48 +0900
parents 3e6f9bff7e3f
children 4710cc4dac99
comparison
equal deleted inserted replaced
32800:3e6f9bff7e3f 32801:348b491c0934
882 # deletion in changelog 882 # deletion in changelog
883 continue 883 continue
884 884
885 return subset & s 885 return subset & s
886 886
887 @predicate('first(set, [n])', safe=True) 887 @predicate('first(set, [n])', safe=True, takeorder=True)
888 def first(repo, subset, x): 888 def first(repo, subset, x, order):
889 """An alias for limit(). 889 """An alias for limit().
890 """ 890 """
891 return limit(repo, subset, x) 891 return limit(repo, subset, x, order)
892 892
893 def _follow(repo, subset, x, name, followfirst=False): 893 def _follow(repo, subset, x, name, followfirst=False):
894 l = getargs(x, 0, 2, _("%s takes no arguments or a pattern " 894 l = getargs(x, 0, 2, _("%s takes no arguments or a pattern "
895 "and an optional revset") % name) 895 "and an optional revset") % name)
896 c = repo['.'] 896 c = repo['.']
1150 return any(kw in encoding.lower(t) 1150 return any(kw in encoding.lower(t)
1151 for t in c.files() + [c.user(), c.description()]) 1151 for t in c.files() + [c.user(), c.description()])
1152 1152
1153 return subset.filter(matches, condrepr=('<keyword %r>', kw)) 1153 return subset.filter(matches, condrepr=('<keyword %r>', kw))
1154 1154
1155 @predicate('limit(set[, n[, offset]])', safe=True) 1155 @predicate('limit(set[, n[, offset]])', safe=True, takeorder=True)
1156 def limit(repo, subset, x): 1156 def limit(repo, subset, x, order):
1157 """First n members of set, defaulting to 1, starting from offset. 1157 """First n members of set, defaulting to 1, starting from offset.
1158 """ 1158 """
1159 args = getargsdict(x, 'limit', 'set n offset') 1159 args = getargsdict(x, 'limit', 'set n offset')
1160 if 'set' not in args: 1160 if 'set' not in args:
1161 # i18n: "limit" is a keyword 1161 # i18n: "limit" is a keyword
1179 y = next(it, None) 1179 y = next(it, None)
1180 if y is None: 1180 if y is None:
1181 break 1181 break
1182 result.append(y) 1182 result.append(y)
1183 ls = baseset(result, datarepr=('<limit n=%d, offset=%d, %r>', lim, ofs, os)) 1183 ls = baseset(result, datarepr=('<limit n=%d, offset=%d, %r>', lim, ofs, os))
1184 if order == followorder and lim > 1:
1185 return subset & ls
1184 return ls & subset 1186 return ls & subset
1185 1187
1186 @predicate('last(set, [n])', safe=True) 1188 @predicate('last(set, [n])', safe=True, takeorder=True)
1187 def last(repo, subset, x): 1189 def last(repo, subset, x, order):
1188 """Last n members of set, defaulting to 1. 1190 """Last n members of set, defaulting to 1.
1189 """ 1191 """
1190 # i18n: "last" is a keyword 1192 # i18n: "last" is a keyword
1191 l = getargs(x, 1, 2, _("last requires one or two arguments")) 1193 l = getargs(x, 1, 2, _("last requires one or two arguments"))
1192 lim = 1 1194 lim = 1
1203 y = next(it, None) 1205 y = next(it, None)
1204 if y is None: 1206 if y is None:
1205 break 1207 break
1206 result.append(y) 1208 result.append(y)
1207 ls = baseset(result, datarepr=('<last n=%d, %r>', lim, os)) 1209 ls = baseset(result, datarepr=('<last n=%d, %r>', lim, os))
1210 if order == followorder and lim > 1:
1211 return subset & ls
1208 ls.reverse() 1212 ls.reverse()
1209 return ls & subset 1213 return ls & subset
1210 1214
1211 @predicate('max(set)', safe=True) 1215 @predicate('max(set)', safe=True)
1212 def maxrev(repo, subset, x): 1216 def maxrev(repo, subset, x):