[PATCH 2 of 2] fileset: add "subrepo" fileset symbol

Angel Ezquerra angel.ezquerra at gmail.com
Wed Apr 11 14:07:09 CDT 2012


# HG changeset patch
# User Angel Ezquerra <angel.ezquerra at gmail.com>
# Date 1332447135 -3600
# Node ID 18653b17ecf26170157bb3eafab9522fd88dd26e
# Parent  2c32ff4561f6594957596cb711fe853c42f9bd38
fileset: add "subrepo" fileset symbol

This new fileset symbol returns a list of subrepos whose paths match a given
pattern. If the argument has no pattern type set, an exact
match is performed.

If no argument is passed, return a list of all subrepos.

diff --git a/mercurial/fileset.py b/mercurial/fileset.py
--- a/mercurial/fileset.py
+++ b/mercurial/fileset.py
@@ -358,6 +358,28 @@
             s.append(f)
     return s
 
+def subrepo(mctx, x):
+    """``subrepo([pattern])``
+    Subrepositories whose paths match the given pattern.
+    """
+    # i18n: "subrepo" is a keyword
+    getargs(x, 0, 1, _("subrepo takes at most one argument"))
+    ctx = mctx.ctx
+    sstate = ctx.substate
+    if x:
+        pat = getstring(x, _("subrepo requires a pattern or no arguments"))
+
+        import match as matchmod # avoid circular import issues
+        fast = not matchmod.patkind(pat)
+        if fast:
+            def m(s):
+                return (s == pat)
+        else:
+            m = matchmod.match(ctx._repo.root, '', [pat], ctx=ctx)
+        return [sub for sub in sstate if m(sub)]
+    else:
+        return [sub for sub in sstate]
+
 symbols = {
     'added': added,
     'binary': binary,
@@ -376,6 +398,7 @@
     'symlink': symlink,
     'unknown': unknown,
     'unresolved': unresolved,
+    'subrepo': subrepo,
 }
 
 methods = {


More information about the Mercurial-devel mailing list