Mercurial > hg
comparison mercurial/revset.py @ 32291:bd872f64a8ba
cleanup: use set literals
We no longer support Python 2.6, so we can now use set literals.
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 10 Feb 2017 16:56:29 -0800 |
parents | 2a2744dffecf |
children | e8c043375b53 |
comparison
equal
deleted
inserted
replaced
32290:2959c3e986e0 | 32291:bd872f64a8ba |
---|---|
449 raise error.RepoLookupError(_("no bookmarks exist" | 449 raise error.RepoLookupError(_("no bookmarks exist" |
450 " that match '%s'") % pattern) | 450 " that match '%s'") % pattern) |
451 for bmrev in matchrevs: | 451 for bmrev in matchrevs: |
452 bms.add(repo[bmrev].rev()) | 452 bms.add(repo[bmrev].rev()) |
453 else: | 453 else: |
454 bms = set([repo[r].rev() | 454 bms = {repo[r].rev() for r in repo._bookmarks.values()} |
455 for r in repo._bookmarks.values()]) | 455 bms -= {node.nullrev} |
456 bms -= set([node.nullrev]) | |
457 return subset & bms | 456 return subset & bms |
458 | 457 |
459 @predicate('branch(string or set)', safe=True) | 458 @predicate('branch(string or set)', safe=True) |
460 def branch(repo, subset, x): | 459 def branch(repo, subset, x): |
461 """ | 460 """ |
1274 for ns in namespaces: | 1273 for ns in namespaces: |
1275 for name in ns.listnames(repo): | 1274 for name in ns.listnames(repo): |
1276 if name not in ns.deprecated: | 1275 if name not in ns.deprecated: |
1277 names.update(repo[n].rev() for n in ns.nodes(repo, name)) | 1276 names.update(repo[n].rev() for n in ns.nodes(repo, name)) |
1278 | 1277 |
1279 names -= set([node.nullrev]) | 1278 names -= {node.nullrev} |
1280 return subset & names | 1279 return subset & names |
1281 | 1280 |
1282 @predicate('id(string)', safe=True) | 1281 @predicate('id(string)', safe=True) |
1283 def node_(repo, subset, x): | 1282 def node_(repo, subset, x): |
1284 """Revision non-ambiguously specified by the given hex string prefix. | 1283 """Revision non-ambiguously specified by the given hex string prefix. |
1361 | 1360 |
1362 if prev is None: | 1361 if prev is None: |
1363 return src | 1362 return src |
1364 src = prev | 1363 src = prev |
1365 | 1364 |
1366 o = set([_firstsrc(r) for r in dests]) | 1365 o = {_firstsrc(r) for r in dests} |
1367 o -= set([None]) | 1366 o -= {None} |
1368 # XXX we should turn this into a baseset instead of a set, smartset may do | 1367 # XXX we should turn this into a baseset instead of a set, smartset may do |
1369 # some optimizations from the fact this is a baseset. | 1368 # some optimizations from the fact this is a baseset. |
1370 return subset & o | 1369 return subset & o |
1371 | 1370 |
1372 @predicate('outgoing([path])', safe=False) | 1371 @predicate('outgoing([path])', safe=False) |
1391 other = hg.peer(repo, {}, dest) | 1390 other = hg.peer(repo, {}, dest) |
1392 repo.ui.pushbuffer() | 1391 repo.ui.pushbuffer() |
1393 outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs) | 1392 outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs) |
1394 repo.ui.popbuffer() | 1393 repo.ui.popbuffer() |
1395 cl = repo.changelog | 1394 cl = repo.changelog |
1396 o = set([cl.rev(r) for r in outgoing.missing]) | 1395 o = {cl.rev(r) for r in outgoing.missing} |
1397 return subset & o | 1396 return subset & o |
1398 | 1397 |
1399 @predicate('p1([set])', safe=True) | 1398 @predicate('p1([set])', safe=True) |
1400 def p1(repo, subset, x): | 1399 def p1(repo, subset, x): |
1401 """First parent of changesets in set, or the working directory. | 1400 """First parent of changesets in set, or the working directory. |
1408 | 1407 |
1409 ps = set() | 1408 ps = set() |
1410 cl = repo.changelog | 1409 cl = repo.changelog |
1411 for r in getset(repo, fullreposet(repo), x): | 1410 for r in getset(repo, fullreposet(repo), x): |
1412 ps.add(cl.parentrevs(r)[0]) | 1411 ps.add(cl.parentrevs(r)[0]) |
1413 ps -= set([node.nullrev]) | 1412 ps -= {node.nullrev} |
1414 # XXX we should turn this into a baseset instead of a set, smartset may do | 1413 # XXX we should turn this into a baseset instead of a set, smartset may do |
1415 # some optimizations from the fact this is a baseset. | 1414 # some optimizations from the fact this is a baseset. |
1416 return subset & ps | 1415 return subset & ps |
1417 | 1416 |
1418 @predicate('p2([set])', safe=True) | 1417 @predicate('p2([set])', safe=True) |
1431 | 1430 |
1432 ps = set() | 1431 ps = set() |
1433 cl = repo.changelog | 1432 cl = repo.changelog |
1434 for r in getset(repo, fullreposet(repo), x): | 1433 for r in getset(repo, fullreposet(repo), x): |
1435 ps.add(cl.parentrevs(r)[1]) | 1434 ps.add(cl.parentrevs(r)[1]) |
1436 ps -= set([node.nullrev]) | 1435 ps -= {node.nullrev} |
1437 # XXX we should turn this into a baseset instead of a set, smartset may do | 1436 # XXX we should turn this into a baseset instead of a set, smartset may do |
1438 # some optimizations from the fact this is a baseset. | 1437 # some optimizations from the fact this is a baseset. |
1439 return subset & ps | 1438 return subset & ps |
1440 | 1439 |
1441 def parentpost(repo, subset, x, order): | 1440 def parentpost(repo, subset, x, order): |
1456 for r in getset(repo, fullreposet(repo), x): | 1455 for r in getset(repo, fullreposet(repo), x): |
1457 if r == node.wdirrev: | 1456 if r == node.wdirrev: |
1458 up(p.rev() for p in repo[r].parents()) | 1457 up(p.rev() for p in repo[r].parents()) |
1459 else: | 1458 else: |
1460 up(parentrevs(r)) | 1459 up(parentrevs(r)) |
1461 ps -= set([node.nullrev]) | 1460 ps -= {node.nullrev} |
1462 return subset & ps | 1461 return subset & ps |
1463 | 1462 |
1464 def _phase(repo, subset, *targets): | 1463 def _phase(repo, subset, *targets): |
1465 """helper to select all rev in <targets> phases""" | 1464 """helper to select all rev in <targets> phases""" |
1466 s = repo._phasecache.getrevset(repo, targets) | 1465 s = repo._phasecache.getrevset(repo, targets) |
1963 for i in reversed(matching): | 1962 for i in reversed(matching): |
1964 del groups[i] | 1963 del groups[i] |
1965 else: | 1964 else: |
1966 # This is a new head. We create a new subgroup for it. | 1965 # This is a new head. We create a new subgroup for it. |
1967 targetidx = len(groups) | 1966 targetidx = len(groups) |
1968 groups.append(([], set([rev]))) | 1967 groups.append(([], {rev})) |
1969 | 1968 |
1970 gr = groups[targetidx] | 1969 gr = groups[targetidx] |
1971 | 1970 |
1972 # We now add the current nodes to this subgroups. This is done | 1971 # We now add the current nodes to this subgroups. This is done |
1973 # after the subgroup merging because all elements from a subgroup | 1972 # after the subgroup merging because all elements from a subgroup |
2096 # avoid resolving all tags | 2095 # avoid resolving all tags |
2097 tn = repo._tagscache.tags.get(pattern, None) | 2096 tn = repo._tagscache.tags.get(pattern, None) |
2098 if tn is None: | 2097 if tn is None: |
2099 raise error.RepoLookupError(_("tag '%s' does not exist") | 2098 raise error.RepoLookupError(_("tag '%s' does not exist") |
2100 % pattern) | 2099 % pattern) |
2101 s = set([repo[tn].rev()]) | 2100 s = {repo[tn].rev()} |
2102 else: | 2101 else: |
2103 s = set([cl.rev(n) for t, n in repo.tagslist() if matcher(t)]) | 2102 s = {cl.rev(n) for t, n in repo.tagslist() if matcher(t)} |
2104 else: | 2103 else: |
2105 s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip']) | 2104 s = {cl.rev(n) for t, n in repo.tagslist() if t != 'tip'} |
2106 return subset & s | 2105 return subset & s |
2107 | 2106 |
2108 @predicate('tagged', safe=True) | 2107 @predicate('tagged', safe=True) |
2109 def tagged(repo, subset, x): | 2108 def tagged(repo, subset, x): |
2110 return tag(repo, subset, x) | 2109 return tag(repo, subset, x) |