comparison mercurial/revset.py @ 24446:582cfcc843c7

revset: add the 'subrepo' symbol This returns the csets where matching subrepos have changed with respect to the containing repo's first parent. The second parent shouldn't matter, because it is either syncing up to the first parent (i.e. it hasn't changed from the current branch's POV), or the merge changed it with respect to the first parent (which already adds it to the set). There's already a 'subrepo' fileset, but it is prefixed with 'set:', so there should be no ambiguity (in code anyway). The only test I see for it is to revert subrepos named by a glob pattern (in test-subrepo.t, line 58). Since it doesn't return a tracked file, neither 'log "set:subrepo()"' nor 'files "set:subrepo()"' print anything. Therefore, it seems useful to have a revset that will return something for log (and can be added to a revsetalias to be chained with 'file' revsets.) It might be nice to be able to filter for added, modified and removed separately, but add/remove should be rare. It might also be nice to be able to do a 'contains' check, in addition to this mutated check. Maybe it is possible to get those with the existing 'adds', 'contains', 'modifies' and 'removes' by teaching them to chase explicit paths into subrepos. I'm not sure if this should be added to the 'modifies adds removes' line in revset.optimize() (since it is doing an AMR check on .hgsubstate), or if it is OK to put into 'safesymbols' (things like 'file' are on the list, and that takes a regex, among other patterns).
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 25 Mar 2015 14:56:54 -0400
parents 0e41f110e69e
children c5022f3579b9
comparison
equal deleted inserted replaced
24445:c71edbafe603 24446:582cfcc843c7
1753 e.append(r) 1753 e.append(r)
1754 l.append(e) 1754 l.append(e)
1755 l.sort() 1755 l.sort()
1756 return baseset([e[-1] for e in l]) 1756 return baseset([e[-1] for e in l])
1757 1757
1758 def subrepo(repo, subset, x):
1759 """``subrepo([pattern])``
1760 Changesets that add, modify or remove the given subrepo. If no subrepo
1761 pattern is named, any subrepo changes are returned.
1762 """
1763 # i18n: "subrepo" is a keyword
1764 args = getargs(x, 0, 1, _('subrepo takes at most one argument'))
1765 if len(args) != 0:
1766 pat = getstring(args[0], _("subrepo requires a pattern"))
1767
1768 m = matchmod.exact(repo.root, repo.root, ['.hgsubstate'])
1769
1770 def submatches(names):
1771 k, p, m = _stringmatcher(pat)
1772 for name in names:
1773 if m(name):
1774 yield name
1775
1776 def matches(x):
1777 c = repo[x]
1778 s = repo.status(c.p1().node(), c.node(), match=m)
1779
1780 if len(args) == 0:
1781 return s.added or s.modified or s.removed
1782
1783 if s.added:
1784 return util.any(submatches(c.substate.keys()))
1785
1786 if s.modified:
1787 subs = set(c.p1().substate.keys())
1788 subs.update(c.substate.keys())
1789
1790 for path in submatches(subs):
1791 if c.p1().substate.get(path) != c.substate.get(path):
1792 return True
1793
1794 if s.removed:
1795 return util.any(submatches(c.p1().substate.keys()))
1796
1797 return False
1798
1799 return subset.filter(matches)
1800
1758 def _stringmatcher(pattern): 1801 def _stringmatcher(pattern):
1759 """ 1802 """
1760 accepts a string, possibly starting with 're:' or 'literal:' prefix. 1803 accepts a string, possibly starting with 're:' or 'literal:' prefix.
1761 returns the matcher name, pattern, and matcher function. 1804 returns the matcher name, pattern, and matcher function.
1762 missing or unknown prefixes are treated as literal matches. 1805 missing or unknown prefixes are treated as literal matches.
1950 "rev": rev, 1993 "rev": rev,
1951 "reverse": reverse, 1994 "reverse": reverse,
1952 "roots": roots, 1995 "roots": roots,
1953 "sort": sort, 1996 "sort": sort,
1954 "secret": secret, 1997 "secret": secret,
1998 "subrepo": subrepo,
1955 "matching": matching, 1999 "matching": matching,
1956 "tag": tag, 2000 "tag": tag,
1957 "tagged": tagged, 2001 "tagged": tagged,
1958 "user": user, 2002 "user": user,
1959 "unstable": unstable, 2003 "unstable": unstable,