comparison mercurial/revset.py @ 24115:ff24af40728b

revset: specify fullreposet without using spanset factory The factory function will be removed because the subsequent patches will make fullreposet(repo) not fully compatible with spanset(repo).
author Yuya Nishihara <yuya@tcha.org>
date Thu, 08 Jan 2015 23:46:54 +0900
parents fafd9a1284cf
children 8b90a60181d1
comparison
equal deleted inserted replaced
24114:fafd9a1284cf 24115:ff24af40728b
347 else: 347 else:
348 r = spanset(repo, m, n - 1) 348 r = spanset(repo, m, n - 1)
349 return r & subset 349 return r & subset
350 350
351 def dagrange(repo, subset, x, y): 351 def dagrange(repo, subset, x, y):
352 r = spanset(repo) 352 r = fullreposet(repo)
353 xs = _revsbetween(repo, getset(repo, r, x), getset(repo, r, y)) 353 xs = _revsbetween(repo, getset(repo, r, x), getset(repo, r, y))
354 return xs & subset 354 return xs & subset
355 355
356 def andset(repo, subset, x, y): 356 def andset(repo, subset, x, y):
357 return getset(repo, getset(repo, subset, x), y) 357 return getset(repo, getset(repo, subset, x), y)
394 Will return empty list when passed no args. 394 Will return empty list when passed no args.
395 Greatest common ancestor of a single changeset is that changeset. 395 Greatest common ancestor of a single changeset is that changeset.
396 """ 396 """
397 # i18n: "ancestor" is a keyword 397 # i18n: "ancestor" is a keyword
398 l = getlist(x) 398 l = getlist(x)
399 rl = spanset(repo) 399 rl = fullreposet(repo)
400 anc = None 400 anc = None
401 401
402 # (getset(repo, rl, i) for i in l) generates a list of lists 402 # (getset(repo, rl, i) for i in l) generates a list of lists
403 for revs in (getset(repo, rl, i) for i in l): 403 for revs in (getset(repo, rl, i) for i in l):
404 for r in revs: 404 for r in revs:
410 if anc is not None and anc.rev() in subset: 410 if anc is not None and anc.rev() in subset:
411 return baseset([anc.rev()]) 411 return baseset([anc.rev()])
412 return baseset() 412 return baseset()
413 413
414 def _ancestors(repo, subset, x, followfirst=False): 414 def _ancestors(repo, subset, x, followfirst=False):
415 heads = getset(repo, spanset(repo), x) 415 heads = getset(repo, fullreposet(repo), x)
416 if not heads: 416 if not heads:
417 return baseset() 417 return baseset()
418 s = _revancestors(repo, heads, followfirst) 418 s = _revancestors(repo, heads, followfirst)
419 return subset & s 419 return subset & s
420 420
542 if pattern in repo.branchmap(): 542 if pattern in repo.branchmap():
543 return subset.filter(lambda r: matcher(getbi(ucl, r)[0])) 543 return subset.filter(lambda r: matcher(getbi(ucl, r)[0]))
544 else: 544 else:
545 return subset.filter(lambda r: matcher(getbi(ucl, r)[0])) 545 return subset.filter(lambda r: matcher(getbi(ucl, r)[0]))
546 546
547 s = getset(repo, spanset(repo), x) 547 s = getset(repo, fullreposet(repo), x)
548 b = set() 548 b = set()
549 for r in s: 549 for r in s:
550 b.add(getbi(ucl, r)[0]) 550 b.add(getbi(ucl, r)[0])
551 c = s.__contains__ 551 c = s.__contains__
552 return subset.filter(lambda r: c(r) or getbi(ucl, r)[0] in b) 552 return subset.filter(lambda r: c(r) or getbi(ucl, r)[0] in b)
706 return ds in encoding.lower(c.description()) 706 return ds in encoding.lower(c.description())
707 707
708 return subset.filter(matches) 708 return subset.filter(matches)
709 709
710 def _descendants(repo, subset, x, followfirst=False): 710 def _descendants(repo, subset, x, followfirst=False):
711 roots = getset(repo, spanset(repo), x) 711 roots = getset(repo, fullreposet(repo), x)
712 if not roots: 712 if not roots:
713 return baseset() 713 return baseset()
714 s = _revdescendants(repo, roots, followfirst) 714 s = _revdescendants(repo, roots, followfirst)
715 715
716 # Both sets need to be ascending in order to lazily return the union 716 # Both sets need to be ascending in order to lazily return the union
742 Changesets that were created by a graft, transplant or rebase operation, 742 Changesets that were created by a graft, transplant or rebase operation,
743 with the given revisions specified as the source. Omitting the optional set 743 with the given revisions specified as the source. Omitting the optional set
744 is the same as passing all(). 744 is the same as passing all().
745 """ 745 """
746 if x is not None: 746 if x is not None:
747 sources = getset(repo, spanset(repo), x) 747 sources = getset(repo, fullreposet(repo), x)
748 else: 748 else:
749 sources = getall(repo, spanset(repo), x) 749 sources = getall(repo, fullreposet(repo), x)
750 750
751 dests = set() 751 dests = set()
752 752
753 # subset contains all of the possible destinations that can be returned, so 753 # subset contains all of the possible destinations that can be returned, so
754 # iterate over them and see if their source(s) were provided in the arg set. 754 # iterate over them and see if their source(s) were provided in the arg set.
1143 lim = int(getstring(l[1], _("limit requires a number"))) 1143 lim = int(getstring(l[1], _("limit requires a number")))
1144 except (TypeError, ValueError): 1144 except (TypeError, ValueError):
1145 # i18n: "limit" is a keyword 1145 # i18n: "limit" is a keyword
1146 raise error.ParseError(_("limit expects a number")) 1146 raise error.ParseError(_("limit expects a number"))
1147 ss = subset 1147 ss = subset
1148 os = getset(repo, spanset(repo), l[0]) 1148 os = getset(repo, fullreposet(repo), l[0])
1149 result = [] 1149 result = []
1150 it = iter(os) 1150 it = iter(os)
1151 for x in xrange(lim): 1151 for x in xrange(lim):
1152 try: 1152 try:
1153 y = it.next() 1153 y = it.next()
1170 lim = int(getstring(l[1], _("last requires a number"))) 1170 lim = int(getstring(l[1], _("last requires a number")))
1171 except (TypeError, ValueError): 1171 except (TypeError, ValueError):
1172 # i18n: "last" is a keyword 1172 # i18n: "last" is a keyword
1173 raise error.ParseError(_("last expects a number")) 1173 raise error.ParseError(_("last expects a number"))
1174 ss = subset 1174 ss = subset
1175 os = getset(repo, spanset(repo), l[0]) 1175 os = getset(repo, fullreposet(repo), l[0])
1176 os.reverse() 1176 os.reverse()
1177 result = [] 1177 result = []
1178 it = iter(os) 1178 it = iter(os)
1179 for x in xrange(lim): 1179 for x in xrange(lim):
1180 try: 1180 try:
1187 1187
1188 def maxrev(repo, subset, x): 1188 def maxrev(repo, subset, x):
1189 """``max(set)`` 1189 """``max(set)``
1190 Changeset with highest revision number in set. 1190 Changeset with highest revision number in set.
1191 """ 1191 """
1192 os = getset(repo, spanset(repo), x) 1192 os = getset(repo, fullreposet(repo), x)
1193 if os: 1193 if os:
1194 m = os.max() 1194 m = os.max()
1195 if m in subset: 1195 if m in subset:
1196 return baseset([m]) 1196 return baseset([m])
1197 return baseset() 1197 return baseset()
1224 1224
1225 def minrev(repo, subset, x): 1225 def minrev(repo, subset, x):
1226 """``min(set)`` 1226 """``min(set)``
1227 Changeset with lowest revision number in set. 1227 Changeset with lowest revision number in set.
1228 """ 1228 """
1229 os = getset(repo, spanset(repo), x) 1229 os = getset(repo, fullreposet(repo), x)
1230 if os: 1230 if os:
1231 m = os.min() 1231 m = os.min()
1232 if m in subset: 1232 if m in subset:
1233 return baseset([m]) 1233 return baseset([m])
1234 return baseset() 1234 return baseset()
1319 (i.e. ::<set1> - ::<set2>). 1319 (i.e. ::<set1> - ::<set2>).
1320 """ 1320 """
1321 cl = repo.changelog 1321 cl = repo.changelog
1322 # i18n: "only" is a keyword 1322 # i18n: "only" is a keyword
1323 args = getargs(x, 1, 2, _('only takes one or two arguments')) 1323 args = getargs(x, 1, 2, _('only takes one or two arguments'))
1324 include = getset(repo, spanset(repo), args[0]) 1324 include = getset(repo, fullreposet(repo), args[0])
1325 if len(args) == 1: 1325 if len(args) == 1:
1326 if not include: 1326 if not include:
1327 return baseset() 1327 return baseset()
1328 1328
1329 descendants = set(_revdescendants(repo, include, False)) 1329 descendants = set(_revdescendants(repo, include, False))
1330 exclude = [rev for rev in cl.headrevs() 1330 exclude = [rev for rev in cl.headrevs()
1331 if not rev in descendants and not rev in include] 1331 if not rev in descendants and not rev in include]
1332 else: 1332 else:
1333 exclude = getset(repo, spanset(repo), args[1]) 1333 exclude = getset(repo, fullreposet(repo), args[1])
1334 1334
1335 results = set(cl.findmissingrevs(common=exclude, heads=include)) 1335 results = set(cl.findmissingrevs(common=exclude, heads=include))
1336 return subset & results 1336 return subset & results
1337 1337
1338 def origin(repo, subset, x): 1338 def origin(repo, subset, x):
1342 same as passing all(). If a changeset created by these operations is itself 1342 same as passing all(). If a changeset created by these operations is itself
1343 specified as a source for one of these operations, only the source changeset 1343 specified as a source for one of these operations, only the source changeset
1344 for the first operation is selected. 1344 for the first operation is selected.
1345 """ 1345 """
1346 if x is not None: 1346 if x is not None:
1347 dests = getset(repo, spanset(repo), x) 1347 dests = getset(repo, fullreposet(repo), x)
1348 else: 1348 else:
1349 dests = getall(repo, spanset(repo), x) 1349 dests = getall(repo, fullreposet(repo), x)
1350 1350
1351 def _firstsrc(rev): 1351 def _firstsrc(rev):
1352 src = _getrevsource(repo, rev) 1352 src = _getrevsource(repo, rev)
1353 if src is None: 1353 if src is None:
1354 return None 1354 return None
1397 return subset & baseset([p]) 1397 return subset & baseset([p])
1398 return baseset() 1398 return baseset()
1399 1399
1400 ps = set() 1400 ps = set()
1401 cl = repo.changelog 1401 cl = repo.changelog
1402 for r in getset(repo, spanset(repo), x): 1402 for r in getset(repo, fullreposet(repo), x):
1403 ps.add(cl.parentrevs(r)[0]) 1403 ps.add(cl.parentrevs(r)[0])
1404 ps -= set([node.nullrev]) 1404 ps -= set([node.nullrev])
1405 return subset & ps 1405 return subset & ps
1406 1406
1407 def p2(repo, subset, x): 1407 def p2(repo, subset, x):
1418 except IndexError: 1418 except IndexError:
1419 return baseset() 1419 return baseset()
1420 1420
1421 ps = set() 1421 ps = set()
1422 cl = repo.changelog 1422 cl = repo.changelog
1423 for r in getset(repo, spanset(repo), x): 1423 for r in getset(repo, fullreposet(repo), x):
1424 ps.add(cl.parentrevs(r)[1]) 1424 ps.add(cl.parentrevs(r)[1])
1425 ps -= set([node.nullrev]) 1425 ps -= set([node.nullrev])
1426 return subset & ps 1426 return subset & ps
1427 1427
1428 def parents(repo, subset, x): 1428 def parents(repo, subset, x):
1432 if x is None: 1432 if x is None:
1433 ps = set(p.rev() for p in repo[x].parents()) 1433 ps = set(p.rev() for p in repo[x].parents())
1434 else: 1434 else:
1435 ps = set() 1435 ps = set()
1436 cl = repo.changelog 1436 cl = repo.changelog
1437 for r in getset(repo, spanset(repo), x): 1437 for r in getset(repo, fullreposet(repo), x):
1438 ps.update(cl.parentrevs(r)) 1438 ps.update(cl.parentrevs(r))
1439 ps -= set([node.nullrev]) 1439 ps -= set([node.nullrev])
1440 return subset & ps 1440 return subset & ps
1441 1441
1442 def parentspec(repo, subset, x, n): 1442 def parentspec(repo, subset, x, n):
1673 1673
1674 def roots(repo, subset, x): 1674 def roots(repo, subset, x):
1675 """``roots(set)`` 1675 """``roots(set)``
1676 Changesets in set with no parent changeset in set. 1676 Changesets in set with no parent changeset in set.
1677 """ 1677 """
1678 s = getset(repo, spanset(repo), x) 1678 s = getset(repo, fullreposet(repo), x)
1679 subset = baseset([r for r in s if r in subset]) 1679 subset = baseset([r for r in s if r in subset])
1680 cs = _children(repo, subset, s) 1680 cs = _children(repo, subset, s)
1681 return subset - cs 1681 return subset - cs
1682 1682
1683 def secret(repo, subset, x): 1683 def secret(repo, subset, x):
2448 tree = findaliases(ui, tree, showwarning=ui.warn) 2448 tree = findaliases(ui, tree, showwarning=ui.warn)
2449 tree = foldconcat(tree) 2449 tree = foldconcat(tree)
2450 weight, tree = optimize(tree, True) 2450 weight, tree = optimize(tree, True)
2451 def mfunc(repo, subset=None): 2451 def mfunc(repo, subset=None):
2452 if subset is None: 2452 if subset is None:
2453 subset = spanset(repo) 2453 subset = fullreposet(repo)
2454 if util.safehasattr(subset, 'isascending'): 2454 if util.safehasattr(subset, 'isascending'):
2455 result = getset(repo, subset, tree) 2455 result = getset(repo, subset, tree)
2456 else: 2456 else:
2457 result = getset(repo, baseset(subset), tree) 2457 result = getset(repo, baseset(subset), tree)
2458 return result 2458 return result