comparison mercurial/revset.py @ 17675:8575f4a2126e

clfilter: remove usage of `range` in favor of iteration over changelog If we want to apply filtering at changelog level, we need to iterate over it. See previous changeset description for details.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Thu, 20 Sep 2012 19:01:53 +0200
parents 31f32a96e1e3
children 69d5078d760d
comparison
equal deleted inserted replaced
17674:e69274f8d444 17675:8575f4a2126e
213 return stringset(repo, subset, x) 213 return stringset(repo, subset, x)
214 214
215 def rangeset(repo, subset, x, y): 215 def rangeset(repo, subset, x, y):
216 m = getset(repo, subset, x) 216 m = getset(repo, subset, x)
217 if not m: 217 if not m:
218 m = getset(repo, range(len(repo)), x) 218 m = getset(repo, list(repo), x)
219 219
220 n = getset(repo, subset, y) 220 n = getset(repo, subset, y)
221 if not n: 221 if not n:
222 n = getset(repo, range(len(repo)), y) 222 n = getset(repo, list(repo), y)
223 223
224 if not m or not n: 224 if not m or not n:
225 return [] 225 return []
226 m, n = m[0], n[-1] 226 m, n = m[0], n[-1]
227 227
232 s = set(subset) 232 s = set(subset)
233 return [x for x in r if x in s] 233 return [x for x in r if x in s]
234 234
235 def dagrange(repo, subset, x, y): 235 def dagrange(repo, subset, x, y):
236 if subset: 236 if subset:
237 r = range(len(repo)) 237 r = list(repo)
238 xs = _revsbetween(repo, getset(repo, r, x), getset(repo, r, y)) 238 xs = _revsbetween(repo, getset(repo, r, x), getset(repo, r, y))
239 s = set(subset) 239 s = set(subset)
240 return [r for r in xs if r in s] 240 return [r for r in xs if r in s]
241 return [] 241 return []
242 242
275 """``ancestor(single, single)`` 275 """``ancestor(single, single)``
276 Greatest common ancestor of the two changesets. 276 Greatest common ancestor of the two changesets.
277 """ 277 """
278 # i18n: "ancestor" is a keyword 278 # i18n: "ancestor" is a keyword
279 l = getargs(x, 2, 2, _("ancestor requires two arguments")) 279 l = getargs(x, 2, 2, _("ancestor requires two arguments"))
280 r = range(len(repo)) 280 r = list(repo)
281 a = getset(repo, r, l[0]) 281 a = getset(repo, r, l[0])
282 b = getset(repo, r, l[1]) 282 b = getset(repo, r, l[1])
283 if len(a) != 1 or len(b) != 1: 283 if len(a) != 1 or len(b) != 1:
284 # i18n: "ancestor" is a keyword 284 # i18n: "ancestor" is a keyword
285 raise error.ParseError(_("ancestor arguments must be single revisions")) 285 raise error.ParseError(_("ancestor arguments must be single revisions"))
286 an = [repo[a[0]].ancestor(repo[b[0]]).rev()] 286 an = [repo[a[0]].ancestor(repo[b[0]]).rev()]
287 287
288 return [r for r in an if r in subset] 288 return [r for r in an if r in subset]
289 289
290 def _ancestors(repo, subset, x, followfirst=False): 290 def _ancestors(repo, subset, x, followfirst=False):
291 args = getset(repo, range(len(repo)), x) 291 args = getset(repo, list(repo), x)
292 if not args: 292 if not args:
293 return [] 293 return []
294 s = set(_revancestors(repo, args, followfirst)) | set(args) 294 s = set(_revancestors(repo, args, followfirst)) | set(args)
295 return [r for r in subset if r in s] 295 return [r for r in subset if r in s]
296 296
413 if pattern in repo.branchmap(): 413 if pattern in repo.branchmap():
414 return [r for r in subset if matcher(repo[r].branch())] 414 return [r for r in subset if matcher(repo[r].branch())]
415 else: 415 else:
416 return [r for r in subset if matcher(repo[r].branch())] 416 return [r for r in subset if matcher(repo[r].branch())]
417 417
418 s = getset(repo, range(len(repo)), x) 418 s = getset(repo, list(repo), x)
419 b = set() 419 b = set()
420 for r in s: 420 for r in s:
421 b.add(repo[r].branch()) 421 b.add(repo[r].branch())
422 s = set(s) 422 s = set(s)
423 return [r for r in subset if r in s or repo[r].branch() in b] 423 return [r for r in subset if r in s or repo[r].branch() in b]
464 464
465 def children(repo, subset, x): 465 def children(repo, subset, x):
466 """``children(set)`` 466 """``children(set)``
467 Child changesets of changesets in set. 467 Child changesets of changesets in set.
468 """ 468 """
469 s = set(getset(repo, range(len(repo)), x)) 469 s = set(getset(repo, list(repo), x))
470 cs = _children(repo, subset, s) 470 cs = _children(repo, subset, s)
471 return [r for r in subset if r in cs] 471 return [r for r in subset if r in cs]
472 472
473 def closed(repo, subset, x): 473 def closed(repo, subset, x):
474 """``closed()`` 474 """``closed()``
545 if ds in encoding.lower(c.description()): 545 if ds in encoding.lower(c.description()):
546 l.append(r) 546 l.append(r)
547 return l 547 return l
548 548
549 def _descendants(repo, subset, x, followfirst=False): 549 def _descendants(repo, subset, x, followfirst=False):
550 args = getset(repo, range(len(repo)), x) 550 args = getset(repo, list(repo), x)
551 if not args: 551 if not args:
552 return [] 552 return []
553 s = set(_revdescendants(repo, args, followfirst)) | set(args) 553 s = set(_revdescendants(repo, args, followfirst)) | set(args)
554 return [r for r in subset if r in s] 554 return [r for r in subset if r in s]
555 555
569 Changesets that were created by a graft, transplant or rebase operation, 569 Changesets that were created by a graft, transplant or rebase operation,
570 with the given revisions specified as the source. Omitting the optional set 570 with the given revisions specified as the source. Omitting the optional set
571 is the same as passing all(). 571 is the same as passing all().
572 """ 572 """
573 if x is not None: 573 if x is not None:
574 args = set(getset(repo, range(len(repo)), x)) 574 args = set(getset(repo, list(repo), x))
575 else: 575 else:
576 args = set(getall(repo, range(len(repo)), x)) 576 args = set(getall(repo, list(repo), x))
577 577
578 dests = set() 578 dests = set()
579 579
580 # subset contains all of the possible destinations that can be returned, so 580 # subset contains all of the possible destinations that can be returned, so
581 # iterate over them and see if their source(s) were provided in the args. 581 # iterate over them and see if their source(s) were provided in the args.
875 lim = int(getstring(l[1], _("limit requires a number"))) 875 lim = int(getstring(l[1], _("limit requires a number")))
876 except (TypeError, ValueError): 876 except (TypeError, ValueError):
877 # i18n: "limit" is a keyword 877 # i18n: "limit" is a keyword
878 raise error.ParseError(_("limit expects a number")) 878 raise error.ParseError(_("limit expects a number"))
879 ss = set(subset) 879 ss = set(subset)
880 os = getset(repo, range(len(repo)), l[0])[:lim] 880 os = getset(repo, list(repo), l[0])[:lim]
881 return [r for r in os if r in ss] 881 return [r for r in os if r in ss]
882 882
883 def last(repo, subset, x): 883 def last(repo, subset, x):
884 """``last(set, [n])`` 884 """``last(set, [n])``
885 Last n members of set, defaulting to 1. 885 Last n members of set, defaulting to 1.
893 lim = int(getstring(l[1], _("last requires a number"))) 893 lim = int(getstring(l[1], _("last requires a number")))
894 except (TypeError, ValueError): 894 except (TypeError, ValueError):
895 # i18n: "last" is a keyword 895 # i18n: "last" is a keyword
896 raise error.ParseError(_("last expects a number")) 896 raise error.ParseError(_("last expects a number"))
897 ss = set(subset) 897 ss = set(subset)
898 os = getset(repo, range(len(repo)), l[0])[-lim:] 898 os = getset(repo, list(repo), l[0])[-lim:]
899 return [r for r in os if r in ss] 899 return [r for r in os if r in ss]
900 900
901 def maxrev(repo, subset, x): 901 def maxrev(repo, subset, x):
902 """``max(set)`` 902 """``max(set)``
903 Changeset with highest revision number in set. 903 Changeset with highest revision number in set.
904 """ 904 """
905 os = getset(repo, range(len(repo)), x) 905 os = getset(repo, list(repo), x)
906 if os: 906 if os:
907 m = max(os) 907 m = max(os)
908 if m in subset: 908 if m in subset:
909 return [m] 909 return [m]
910 return [] 910 return []
920 920
921 def minrev(repo, subset, x): 921 def minrev(repo, subset, x):
922 """``min(set)`` 922 """``min(set)``
923 Changeset with lowest revision number in set. 923 Changeset with lowest revision number in set.
924 """ 924 """
925 os = getset(repo, range(len(repo)), x) 925 os = getset(repo, list(repo), x)
926 if os: 926 if os:
927 m = min(os) 927 m = min(os)
928 if m in subset: 928 if m in subset:
929 return [m] 929 return [m]
930 return [] 930 return []
970 same as passing all(). If a changeset created by these operations is itself 970 same as passing all(). If a changeset created by these operations is itself
971 specified as a source for one of these operations, only the source changeset 971 specified as a source for one of these operations, only the source changeset
972 for the first operation is selected. 972 for the first operation is selected.
973 """ 973 """
974 if x is not None: 974 if x is not None:
975 args = set(getset(repo, range(len(repo)), x)) 975 args = set(getset(repo, list(repo), x))
976 else: 976 else:
977 args = set(getall(repo, range(len(repo)), x)) 977 args = set(getall(repo, list(repo), x))
978 978
979 def _firstsrc(rev): 979 def _firstsrc(rev):
980 src = _getrevsource(repo, rev) 980 src = _getrevsource(repo, rev)
981 if src is None: 981 if src is None:
982 return None 982 return None
1022 p = repo[x].p1().rev() 1022 p = repo[x].p1().rev()
1023 return [r for r in subset if r == p] 1023 return [r for r in subset if r == p]
1024 1024
1025 ps = set() 1025 ps = set()
1026 cl = repo.changelog 1026 cl = repo.changelog
1027 for r in getset(repo, range(len(repo)), x): 1027 for r in getset(repo, list(repo), x):
1028 ps.add(cl.parentrevs(r)[0]) 1028 ps.add(cl.parentrevs(r)[0])
1029 return [r for r in subset if r in ps] 1029 return [r for r in subset if r in ps]
1030 1030
1031 def p2(repo, subset, x): 1031 def p2(repo, subset, x):
1032 """``p2([set])`` 1032 """``p2([set])``
1040 except IndexError: 1040 except IndexError:
1041 return [] 1041 return []
1042 1042
1043 ps = set() 1043 ps = set()
1044 cl = repo.changelog 1044 cl = repo.changelog
1045 for r in getset(repo, range(len(repo)), x): 1045 for r in getset(repo, list(repo), x):
1046 ps.add(cl.parentrevs(r)[1]) 1046 ps.add(cl.parentrevs(r)[1])
1047 return [r for r in subset if r in ps] 1047 return [r for r in subset if r in ps]
1048 1048
1049 def parents(repo, subset, x): 1049 def parents(repo, subset, x):
1050 """``parents([set])`` 1050 """``parents([set])``
1054 ps = tuple(p.rev() for p in repo[x].parents()) 1054 ps = tuple(p.rev() for p in repo[x].parents())
1055 return [r for r in subset if r in ps] 1055 return [r for r in subset if r in ps]
1056 1056
1057 ps = set() 1057 ps = set()
1058 cl = repo.changelog 1058 cl = repo.changelog
1059 for r in getset(repo, range(len(repo)), x): 1059 for r in getset(repo, list(repo), x):
1060 ps.update(cl.parentrevs(r)) 1060 ps.update(cl.parentrevs(r))
1061 return [r for r in subset if r in ps] 1061 return [r for r in subset if r in ps]
1062 1062
1063 def parentspec(repo, subset, x, n): 1063 def parentspec(repo, subset, x, n):
1064 """``set^0`` 1064 """``set^0``