diff 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
line wrap: on
line diff
--- a/mercurial/revset.py	Tue Mar 24 20:28:39 2015 -0700
+++ b/mercurial/revset.py	Wed Mar 25 14:56:54 2015 -0400
@@ -1755,6 +1755,49 @@
     l.sort()
     return baseset([e[-1] for e in l])
 
+def subrepo(repo, subset, x):
+    """``subrepo([pattern])``
+    Changesets that add, modify or remove the given subrepo.  If no subrepo
+    pattern is named, any subrepo changes are returned.
+    """
+    # i18n: "subrepo" is a keyword
+    args = getargs(x, 0, 1, _('subrepo takes at most one argument'))
+    if len(args) != 0:
+        pat = getstring(args[0], _("subrepo requires a pattern"))
+
+    m = matchmod.exact(repo.root, repo.root, ['.hgsubstate'])
+
+    def submatches(names):
+        k, p, m = _stringmatcher(pat)
+        for name in names:
+            if m(name):
+                yield name
+
+    def matches(x):
+        c = repo[x]
+        s = repo.status(c.p1().node(), c.node(), match=m)
+
+        if len(args) == 0:
+            return s.added or s.modified or s.removed
+
+        if s.added:
+            return util.any(submatches(c.substate.keys()))
+
+        if s.modified:
+            subs = set(c.p1().substate.keys())
+            subs.update(c.substate.keys())
+
+            for path in submatches(subs):
+                if c.p1().substate.get(path) != c.substate.get(path):
+                    return True
+
+        if s.removed:
+            return util.any(submatches(c.p1().substate.keys()))
+
+        return False
+
+    return subset.filter(matches)
+
 def _stringmatcher(pattern):
     """
     accepts a string, possibly starting with 're:' or 'literal:' prefix.
@@ -1952,6 +1995,7 @@
     "roots": roots,
     "sort": sort,
     "secret": secret,
+    "subrepo": subrepo,
     "matching": matching,
     "tag": tag,
     "tagged": tagged,