Mercurial > public > mercurial-scm > hg
comparison mercurial/revset.py @ 45942:89a2afe31e82
formating: upgrade to black 20.8b1
This required a couple of small tweaks to un-confuse black, but now it
works. Big formatting changes come from:
* Dramatically improved collection-splitting logic upstream
* Black having a strong (correct IMO) opinion that """ is better than '''
Differential Revision: https://phab.mercurial-scm.org/D9430
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Fri, 27 Nov 2020 17:03:29 -0500 |
parents | c00595736595 |
children | 59fa3890d40a |
comparison
equal
deleted
inserted
replaced
45941:346af7687c6f | 45942:89a2afe31e82 |
---|---|
527 return subset & ps | 527 return subset & ps |
528 | 528 |
529 | 529 |
530 @predicate(b'author(string)', safe=True, weight=10) | 530 @predicate(b'author(string)', safe=True, weight=10) |
531 def author(repo, subset, x): | 531 def author(repo, subset, x): |
532 """Alias for ``user(string)``. | 532 """Alias for ``user(string)``.""" |
533 """ | |
534 # i18n: "author" is a keyword | 533 # i18n: "author" is a keyword |
535 n = getstring(x, _(b"author requires a string")) | 534 n = getstring(x, _(b"author requires a string")) |
536 kind, pattern, matcher = _substringmatcher(n, casesensitive=False) | 535 kind, pattern, matcher = _substringmatcher(n, casesensitive=False) |
537 return subset.filter( | 536 return subset.filter( |
538 lambda x: matcher(repo[x].user()), condrepr=(b'<user %r>', n) | 537 lambda x: matcher(repo[x].user()), condrepr=(b'<user %r>', n) |
735 return baseset(cs) | 734 return baseset(cs) |
736 | 735 |
737 | 736 |
738 @predicate(b'children(set)', safe=True) | 737 @predicate(b'children(set)', safe=True) |
739 def children(repo, subset, x): | 738 def children(repo, subset, x): |
740 """Child changesets of changesets in set. | 739 """Child changesets of changesets in set.""" |
741 """ | |
742 s = getset(repo, fullreposet(repo), x) | 740 s = getset(repo, fullreposet(repo), x) |
743 cs = _children(repo, subset, s) | 741 cs = _children(repo, subset, s) |
744 return subset & cs | 742 return subset & cs |
745 | 743 |
746 | 744 |
747 @predicate(b'closed()', safe=True, weight=10) | 745 @predicate(b'closed()', safe=True, weight=10) |
748 def closed(repo, subset, x): | 746 def closed(repo, subset, x): |
749 """Changeset is closed. | 747 """Changeset is closed.""" |
750 """ | |
751 # i18n: "closed" is a keyword | 748 # i18n: "closed" is a keyword |
752 getargs(x, 0, 0, _(b"closed takes no arguments")) | 749 getargs(x, 0, 0, _(b"closed takes no arguments")) |
753 return subset.filter( | 750 return subset.filter( |
754 lambda r: repo[r].closesbranch(), condrepr=b'<branch closed>' | 751 lambda r: repo[r].closesbranch(), condrepr=b'<branch closed>' |
755 ) | 752 ) |
769 return subset & baseset(ancs) | 766 return subset & baseset(ancs) |
770 | 767 |
771 | 768 |
772 @predicate(b'commonancestors(set)', safe=True) | 769 @predicate(b'commonancestors(set)', safe=True) |
773 def commonancestors(repo, subset, x): | 770 def commonancestors(repo, subset, x): |
774 """Changesets that are ancestors of every changeset in set. | 771 """Changesets that are ancestors of every changeset in set.""" |
775 """ | |
776 startrevs = getset(repo, fullreposet(repo), x, order=anyorder) | 772 startrevs = getset(repo, fullreposet(repo), x, order=anyorder) |
777 if not startrevs: | 773 if not startrevs: |
778 return baseset() | 774 return baseset() |
779 for r in startrevs: | 775 for r in startrevs: |
780 subset &= dagop.revancestors(repo, baseset([r])) | 776 subset &= dagop.revancestors(repo, baseset([r])) |
866 ) | 862 ) |
867 | 863 |
868 | 864 |
869 @predicate(b'date(interval)', safe=True, weight=10) | 865 @predicate(b'date(interval)', safe=True, weight=10) |
870 def date(repo, subset, x): | 866 def date(repo, subset, x): |
871 """Changesets within the interval, see :hg:`help dates`. | 867 """Changesets within the interval, see :hg:`help dates`.""" |
872 """ | |
873 # i18n: "date" is a keyword | 868 # i18n: "date" is a keyword |
874 ds = getstring(x, _(b"date requires a string")) | 869 ds = getstring(x, _(b"date requires a string")) |
875 dm = dateutil.matchdate(ds) | 870 dm = dateutil.matchdate(ds) |
876 return subset.filter( | 871 return subset.filter( |
877 lambda x: dm(repo[x].date()[0]), condrepr=(b'<date %r>', ds) | 872 lambda x: dm(repo[x].date()[0]), condrepr=(b'<date %r>', ds) |
1106 return subset & baseset(data) | 1101 return subset & baseset(data) |
1107 | 1102 |
1108 | 1103 |
1109 @predicate(b'extinct()', safe=True) | 1104 @predicate(b'extinct()', safe=True) |
1110 def extinct(repo, subset, x): | 1105 def extinct(repo, subset, x): |
1111 """Obsolete changesets with obsolete descendants only. (EXPERIMENTAL) | 1106 """Obsolete changesets with obsolete descendants only. (EXPERIMENTAL)""" |
1112 """ | |
1113 # i18n: "extinct" is a keyword | 1107 # i18n: "extinct" is a keyword |
1114 getargs(x, 0, 0, _(b"extinct takes no arguments")) | 1108 getargs(x, 0, 0, _(b"extinct takes no arguments")) |
1115 extincts = obsmod.getrevs(repo, b'extinct') | 1109 extincts = obsmod.getrevs(repo, b'extinct') |
1116 return subset & extincts | 1110 return subset & extincts |
1117 | 1111 |
1214 return subset & s | 1208 return subset & s |
1215 | 1209 |
1216 | 1210 |
1217 @predicate(b'first(set, [n])', safe=True, takeorder=True, weight=0) | 1211 @predicate(b'first(set, [n])', safe=True, takeorder=True, weight=0) |
1218 def first(repo, subset, x, order): | 1212 def first(repo, subset, x, order): |
1219 """An alias for limit(). | 1213 """An alias for limit().""" |
1220 """ | |
1221 return limit(repo, subset, x, order) | 1214 return limit(repo, subset, x, order) |
1222 | 1215 |
1223 | 1216 |
1224 def _follow(repo, subset, x, name, followfirst=False): | 1217 def _follow(repo, subset, x, name, followfirst=False): |
1225 args = getargsdict(x, name, b'file startrev') | 1218 args = getargsdict(x, name, b'file startrev') |
1339 return subset & rs | 1332 return subset & rs |
1340 | 1333 |
1341 | 1334 |
1342 @predicate(b'all()', safe=True) | 1335 @predicate(b'all()', safe=True) |
1343 def getall(repo, subset, x): | 1336 def getall(repo, subset, x): |
1344 """All changesets, the same as ``0:tip``. | 1337 """All changesets, the same as ``0:tip``.""" |
1345 """ | |
1346 # i18n: "all" is a keyword | 1338 # i18n: "all" is a keyword |
1347 getargs(x, 0, 0, _(b"all takes no arguments")) | 1339 getargs(x, 0, 0, _(b"all takes no arguments")) |
1348 return subset & spanset(repo) # drop "null" if any | 1340 return subset & spanset(repo) # drop "null" if any |
1349 | 1341 |
1350 | 1342 |
1478 return _matchfiles(repo, subset, (b'string', b'p:' + pat)) | 1470 return _matchfiles(repo, subset, (b'string', b'p:' + pat)) |
1479 | 1471 |
1480 | 1472 |
1481 @predicate(b'head()', safe=True) | 1473 @predicate(b'head()', safe=True) |
1482 def head(repo, subset, x): | 1474 def head(repo, subset, x): |
1483 """Changeset is a named branch head. | 1475 """Changeset is a named branch head.""" |
1484 """ | |
1485 # i18n: "head" is a keyword | 1476 # i18n: "head" is a keyword |
1486 getargs(x, 0, 0, _(b"head takes no arguments")) | 1477 getargs(x, 0, 0, _(b"head takes no arguments")) |
1487 hs = set() | 1478 hs = set() |
1488 cl = repo.changelog | 1479 cl = repo.changelog |
1489 for ls in repo.branchmap().iterheads(): | 1480 for ls in repo.branchmap().iterheads(): |
1491 return subset & baseset(hs) | 1482 return subset & baseset(hs) |
1492 | 1483 |
1493 | 1484 |
1494 @predicate(b'heads(set)', safe=True, takeorder=True) | 1485 @predicate(b'heads(set)', safe=True, takeorder=True) |
1495 def heads(repo, subset, x, order): | 1486 def heads(repo, subset, x, order): |
1496 """Members of set with no children in set. | 1487 """Members of set with no children in set.""" |
1497 """ | |
1498 # argument set should never define order | 1488 # argument set should never define order |
1499 if order == defineorder: | 1489 if order == defineorder: |
1500 order = followorder | 1490 order = followorder |
1501 inputset = getset(repo, fullreposet(repo), x, order=order) | 1491 inputset = getset(repo, fullreposet(repo), x, order=order) |
1502 wdirparents = None | 1492 wdirparents = None |
1513 return subset & heads | 1503 return subset & heads |
1514 | 1504 |
1515 | 1505 |
1516 @predicate(b'hidden()', safe=True) | 1506 @predicate(b'hidden()', safe=True) |
1517 def hidden(repo, subset, x): | 1507 def hidden(repo, subset, x): |
1518 """Hidden changesets. | 1508 """Hidden changesets.""" |
1519 """ | |
1520 # i18n: "hidden" is a keyword | 1509 # i18n: "hidden" is a keyword |
1521 getargs(x, 0, 0, _(b"hidden takes no arguments")) | 1510 getargs(x, 0, 0, _(b"hidden takes no arguments")) |
1522 hiddenrevs = repoview.filterrevs(repo, b'visible') | 1511 hiddenrevs = repoview.filterrevs(repo, b'visible') |
1523 return subset & hiddenrevs | 1512 return subset & hiddenrevs |
1524 | 1513 |
1544 return subset.filter(matches, condrepr=(b'<keyword %r>', kw)) | 1533 return subset.filter(matches, condrepr=(b'<keyword %r>', kw)) |
1545 | 1534 |
1546 | 1535 |
1547 @predicate(b'limit(set[, n[, offset]])', safe=True, takeorder=True, weight=0) | 1536 @predicate(b'limit(set[, n[, offset]])', safe=True, takeorder=True, weight=0) |
1548 def limit(repo, subset, x, order): | 1537 def limit(repo, subset, x, order): |
1549 """First n members of set, defaulting to 1, starting from offset. | 1538 """First n members of set, defaulting to 1, starting from offset.""" |
1550 """ | |
1551 args = getargsdict(x, b'limit', b'set n offset') | 1539 args = getargsdict(x, b'limit', b'set n offset') |
1552 if b'set' not in args: | 1540 if b'set' not in args: |
1553 # i18n: "limit" is a keyword | 1541 # i18n: "limit" is a keyword |
1554 raise error.ParseError(_(b"limit requires one to three arguments")) | 1542 raise error.ParseError(_(b"limit requires one to three arguments")) |
1555 # i18n: "limit" is a keyword | 1543 # i18n: "limit" is a keyword |
1569 return ls & subset | 1557 return ls & subset |
1570 | 1558 |
1571 | 1559 |
1572 @predicate(b'last(set, [n])', safe=True, takeorder=True) | 1560 @predicate(b'last(set, [n])', safe=True, takeorder=True) |
1573 def last(repo, subset, x, order): | 1561 def last(repo, subset, x, order): |
1574 """Last n members of set, defaulting to 1. | 1562 """Last n members of set, defaulting to 1.""" |
1575 """ | |
1576 # i18n: "last" is a keyword | 1563 # i18n: "last" is a keyword |
1577 l = getargs(x, 1, 2, _(b"last requires one or two arguments")) | 1564 l = getargs(x, 1, 2, _(b"last requires one or two arguments")) |
1578 lim = 1 | 1565 lim = 1 |
1579 if len(l) == 2: | 1566 if len(l) == 2: |
1580 # i18n: "last" is a keyword | 1567 # i18n: "last" is a keyword |
1590 return ls & subset | 1577 return ls & subset |
1591 | 1578 |
1592 | 1579 |
1593 @predicate(b'max(set)', safe=True) | 1580 @predicate(b'max(set)', safe=True) |
1594 def maxrev(repo, subset, x): | 1581 def maxrev(repo, subset, x): |
1595 """Changeset with highest revision number in set. | 1582 """Changeset with highest revision number in set.""" |
1596 """ | |
1597 os = getset(repo, fullreposet(repo), x) | 1583 os = getset(repo, fullreposet(repo), x) |
1598 try: | 1584 try: |
1599 m = os.max() | 1585 m = os.max() |
1600 if m in subset: | 1586 if m in subset: |
1601 return baseset([m], datarepr=(b'<max %r, %r>', subset, os)) | 1587 return baseset([m], datarepr=(b'<max %r, %r>', subset, os)) |
1606 return baseset(datarepr=(b'<max %r, %r>', subset, os)) | 1592 return baseset(datarepr=(b'<max %r, %r>', subset, os)) |
1607 | 1593 |
1608 | 1594 |
1609 @predicate(b'merge()', safe=True) | 1595 @predicate(b'merge()', safe=True) |
1610 def merge(repo, subset, x): | 1596 def merge(repo, subset, x): |
1611 """Changeset is a merge changeset. | 1597 """Changeset is a merge changeset.""" |
1612 """ | |
1613 # i18n: "merge" is a keyword | 1598 # i18n: "merge" is a keyword |
1614 getargs(x, 0, 0, _(b"merge takes no arguments")) | 1599 getargs(x, 0, 0, _(b"merge takes no arguments")) |
1615 cl = repo.changelog | 1600 cl = repo.changelog |
1616 nullrev = node.nullrev | 1601 nullrev = node.nullrev |
1617 | 1602 |
1624 return subset.filter(ismerge, condrepr=b'<merge>') | 1609 return subset.filter(ismerge, condrepr=b'<merge>') |
1625 | 1610 |
1626 | 1611 |
1627 @predicate(b'branchpoint()', safe=True) | 1612 @predicate(b'branchpoint()', safe=True) |
1628 def branchpoint(repo, subset, x): | 1613 def branchpoint(repo, subset, x): |
1629 """Changesets with more than one child. | 1614 """Changesets with more than one child.""" |
1630 """ | |
1631 # i18n: "branchpoint" is a keyword | 1615 # i18n: "branchpoint" is a keyword |
1632 getargs(x, 0, 0, _(b"branchpoint takes no arguments")) | 1616 getargs(x, 0, 0, _(b"branchpoint takes no arguments")) |
1633 cl = repo.changelog | 1617 cl = repo.changelog |
1634 if not subset: | 1618 if not subset: |
1635 return baseset() | 1619 return baseset() |
1646 ) | 1630 ) |
1647 | 1631 |
1648 | 1632 |
1649 @predicate(b'min(set)', safe=True) | 1633 @predicate(b'min(set)', safe=True) |
1650 def minrev(repo, subset, x): | 1634 def minrev(repo, subset, x): |
1651 """Changeset with lowest revision number in set. | 1635 """Changeset with lowest revision number in set.""" |
1652 """ | |
1653 os = getset(repo, fullreposet(repo), x) | 1636 os = getset(repo, fullreposet(repo), x) |
1654 try: | 1637 try: |
1655 m = os.min() | 1638 m = os.min() |
1656 if m in subset: | 1639 if m in subset: |
1657 return baseset([m], datarepr=(b'<min %r, %r>', subset, os)) | 1640 return baseset([m], datarepr=(b'<min %r, %r>', subset, os)) |
1713 return subset & names | 1696 return subset & names |
1714 | 1697 |
1715 | 1698 |
1716 @predicate(b'id(string)', safe=True) | 1699 @predicate(b'id(string)', safe=True) |
1717 def node_(repo, subset, x): | 1700 def node_(repo, subset, x): |
1718 """Revision non-ambiguously specified by the given hex string prefix. | 1701 """Revision non-ambiguously specified by the given hex string prefix.""" |
1719 """ | |
1720 # i18n: "id" is a keyword | 1702 # i18n: "id" is a keyword |
1721 l = getargs(x, 1, 1, _(b"id requires one argument")) | 1703 l = getargs(x, 1, 1, _(b"id requires one argument")) |
1722 # i18n: "id" is a keyword | 1704 # i18n: "id" is a keyword |
1723 n = getstring(l[0], _(b"id requires a string")) | 1705 n = getstring(l[0], _(b"id requires a string")) |
1724 if len(n) == 40: | 1706 if len(n) == 40: |
1745 return result & subset | 1727 return result & subset |
1746 | 1728 |
1747 | 1729 |
1748 @predicate(b'none()', safe=True) | 1730 @predicate(b'none()', safe=True) |
1749 def none(repo, subset, x): | 1731 def none(repo, subset, x): |
1750 """No changesets. | 1732 """No changesets.""" |
1751 """ | |
1752 # i18n: "none" is a keyword | 1733 # i18n: "none" is a keyword |
1753 getargs(x, 0, 0, _(b"none takes no arguments")) | 1734 getargs(x, 0, 0, _(b"none takes no arguments")) |
1754 return baseset() | 1735 return baseset() |
1755 | 1736 |
1756 | 1737 |
1867 return subset & o | 1848 return subset & o |
1868 | 1849 |
1869 | 1850 |
1870 @predicate(b'p1([set])', safe=True) | 1851 @predicate(b'p1([set])', safe=True) |
1871 def p1(repo, subset, x): | 1852 def p1(repo, subset, x): |
1872 """First parent of changesets in set, or the working directory. | 1853 """First parent of changesets in set, or the working directory.""" |
1873 """ | |
1874 if x is None: | 1854 if x is None: |
1875 p = repo[x].p1().rev() | 1855 p = repo[x].p1().rev() |
1876 if p >= 0: | 1856 if p >= 0: |
1877 return subset & baseset([p]) | 1857 return subset & baseset([p]) |
1878 return baseset() | 1858 return baseset() |
1890 return subset & ps | 1870 return subset & ps |
1891 | 1871 |
1892 | 1872 |
1893 @predicate(b'p2([set])', safe=True) | 1873 @predicate(b'p2([set])', safe=True) |
1894 def p2(repo, subset, x): | 1874 def p2(repo, subset, x): |
1895 """Second parent of changesets in set, or the working directory. | 1875 """Second parent of changesets in set, or the working directory.""" |
1896 """ | |
1897 if x is None: | 1876 if x is None: |
1898 ps = repo[x].parents() | 1877 ps = repo[x].parents() |
1899 try: | 1878 try: |
1900 p = ps[1].rev() | 1879 p = ps[1].rev() |
1901 if p >= 0: | 1880 if p >= 0: |
2303 return subset.filter(matches, condrepr=(b'<matching%r %r>', fields, revs)) | 2282 return subset.filter(matches, condrepr=(b'<matching%r %r>', fields, revs)) |
2304 | 2283 |
2305 | 2284 |
2306 @predicate(b'reverse(set)', safe=True, takeorder=True, weight=0) | 2285 @predicate(b'reverse(set)', safe=True, takeorder=True, weight=0) |
2307 def reverse(repo, subset, x, order): | 2286 def reverse(repo, subset, x, order): |
2308 """Reverse order of set. | 2287 """Reverse order of set.""" |
2309 """ | |
2310 l = getset(repo, subset, x, order) | 2288 l = getset(repo, subset, x, order) |
2311 if order == defineorder: | 2289 if order == defineorder: |
2312 l.reverse() | 2290 l.reverse() |
2313 return l | 2291 return l |
2314 | 2292 |
2315 | 2293 |
2316 @predicate(b'roots(set)', safe=True) | 2294 @predicate(b'roots(set)', safe=True) |
2317 def roots(repo, subset, x): | 2295 def roots(repo, subset, x): |
2318 """Changesets in set with no parent changeset in set. | 2296 """Changesets in set with no parent changeset in set.""" |
2319 """ | |
2320 s = getset(repo, fullreposet(repo), x) | 2297 s = getset(repo, fullreposet(repo), x) |
2321 parents = repo.changelog.parentrevs | 2298 parents = repo.changelog.parentrevs |
2322 | 2299 |
2323 def filter(r): | 2300 def filter(r): |
2324 for p in parents(r): | 2301 for p in parents(r): |
2554 return tag(repo, subset, x) | 2531 return tag(repo, subset, x) |
2555 | 2532 |
2556 | 2533 |
2557 @predicate(b'orphan()', safe=True) | 2534 @predicate(b'orphan()', safe=True) |
2558 def orphan(repo, subset, x): | 2535 def orphan(repo, subset, x): |
2559 """Non-obsolete changesets with obsolete ancestors. (EXPERIMENTAL) | 2536 """Non-obsolete changesets with obsolete ancestors. (EXPERIMENTAL)""" |
2560 """ | |
2561 # i18n: "orphan" is a keyword | 2537 # i18n: "orphan" is a keyword |
2562 getargs(x, 0, 0, _(b"orphan takes no arguments")) | 2538 getargs(x, 0, 0, _(b"orphan takes no arguments")) |
2563 orphan = obsmod.getrevs(repo, b'orphan') | 2539 orphan = obsmod.getrevs(repo, b'orphan') |
2564 return subset & orphan | 2540 return subset & orphan |
2565 | 2541 |
2566 | 2542 |
2567 @predicate(b'unstable()', safe=True) | 2543 @predicate(b'unstable()', safe=True) |
2568 def unstable(repo, subset, x): | 2544 def unstable(repo, subset, x): |
2569 """Changesets with instabilities. (EXPERIMENTAL) | 2545 """Changesets with instabilities. (EXPERIMENTAL)""" |
2570 """ | |
2571 # i18n: "unstable" is a keyword | 2546 # i18n: "unstable" is a keyword |
2572 getargs(x, 0, 0, b'unstable takes no arguments') | 2547 getargs(x, 0, 0, b'unstable takes no arguments') |
2573 _unstable = set() | 2548 _unstable = set() |
2574 _unstable.update(obsmod.getrevs(repo, b'orphan')) | 2549 _unstable.update(obsmod.getrevs(repo, b'orphan')) |
2575 _unstable.update(obsmod.getrevs(repo, b'phasedivergent')) | 2550 _unstable.update(obsmod.getrevs(repo, b'phasedivergent')) |
2779 | 2754 |
2780 return mfunc | 2755 return mfunc |
2781 | 2756 |
2782 | 2757 |
2783 def loadpredicate(ui, extname, registrarobj): | 2758 def loadpredicate(ui, extname, registrarobj): |
2784 """Load revset predicates from specified registrarobj | 2759 """Load revset predicates from specified registrarobj""" |
2785 """ | |
2786 for name, func in pycompat.iteritems(registrarobj._table): | 2760 for name, func in pycompat.iteritems(registrarobj._table): |
2787 symbols[name] = func | 2761 symbols[name] = func |
2788 if func._safe: | 2762 if func._safe: |
2789 safesymbols.add(name) | 2763 safesymbols.add(name) |
2790 | 2764 |