# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1431745985 14400
#      Fri May 15 23:13:05 2015 -0400
# Node ID df63d4843581c790c2be51910f164b0eee2f2b94
# Parent  a7701001c829838e01f5317ea494c54c981a50a4
subrepo: introduce getfileset()

This will be used in the next patch to help matchers resolve filesets in
subrepos.  The default implementation returns an empty set (for git and svn).

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -500,6 +500,10 @@
         """return file flags"""
         return ''
 
+    def getfileset(self, expr):
+        """Resolve the fileset expression for this repo"""
+        return set()
+
     def printfiles(self, ui, m, fm, fmt):
         """handle the files command for this subrepo"""
         return 1
@@ -917,6 +921,26 @@
             ctx = self._repo[rev]
         return cmdutil.files(ui, ctx, m, fm, fmt, True)
 
+    @annotatesubrepoerror
+    def getfileset(self, expr):
+        if self._ctx.rev() is None:
+            ctx = self._repo[None]
+        else:
+            rev = self._state[1]
+            ctx = self._repo[rev]
+
+        files = ctx.getfileset(expr)
+
+        for subpath in ctx.substate:
+            sub = ctx.sub(subpath)
+
+            try:
+                files.extend(subpath + '/' + f for f in sub.getfileset(expr))
+            except error.LookupError:
+                self.ui.status(_("skipping missing subrepository: %s\n")
+                               % self.wvfs.reljoin(reporelpath(self), subpath))
+        return files
+
     def walk(self, match):
         ctx = self._repo[None]
         return ctx.walk(match)