files: recurse into subrepos automatically with an explicit path
authorMatt Harbison <matt_harbison@yahoo.com>
Sun, 17 May 2015 22:42:47 -0400
changeset 25228 63a57a2727b6
parent 25227 fd0f919170d2
child 25229 451df92cec49
files: recurse into subrepos automatically with an explicit path
mercurial/cmdutil.py
mercurial/help/subrepos.txt
mercurial/subrepo.py
tests/test-subrepo-deep-nested-change.t
--- a/mercurial/cmdutil.py	Wed May 20 01:06:09 2015 +0900
+++ b/mercurial/cmdutil.py	Sun May 17 22:42:47 2015 -0400
@@ -2297,12 +2297,16 @@
         fm.write('path', fmt, m.rel(f))
         ret = 0
 
-    if subrepos:
-        for subpath in sorted(ctx.substate):
+    for subpath in sorted(ctx.substate):
+        def matchessubrepo(subpath):
+            return (m.always() or m.exact(subpath)
+                    or any(f.startswith(subpath + '/') for f in m.files()))
+
+        if subrepos or matchessubrepo(subpath):
             sub = ctx.sub(subpath)
             try:
                 submatch = matchmod.narrowmatcher(subpath, m)
-                if sub.printfiles(ui, submatch, fm, fmt) == 0:
+                if sub.printfiles(ui, submatch, fm, fmt, subrepos) == 0:
                     ret = 0
             except error.LookupError:
                 ui.status(_("skipping missing subrepository: %s\n")
--- a/mercurial/help/subrepos.txt	Wed May 20 01:06:09 2015 +0900
+++ b/mercurial/help/subrepos.txt	Sun May 17 22:42:47 2015 -0400
@@ -109,8 +109,10 @@
     elements. Subversion subrepositories are currently silently ignored.
 
 :files: files does not recurse into subrepos unless -S/--subrepos is
-    specified.  Git and Subversion subrepositories are currently
-    silently ignored.
+    specified.  However, if you specify the full path of a file or
+    directory in a subrepo, it will be displayed even without
+    -S/--subrepos being specified.  Git and Subversion subrepositories
+    are currently silently ignored.
 
 :forget: forget currently only handles exact file matches in subrepos.
     Git and Subversion subrepositories are currently silently ignored.
--- a/mercurial/subrepo.py	Wed May 20 01:06:09 2015 +0900
+++ b/mercurial/subrepo.py	Sun May 17 22:42:47 2015 -0400
@@ -504,7 +504,7 @@
         """Resolve the fileset expression for this repo"""
         return set()
 
-    def printfiles(self, ui, m, fm, fmt):
+    def printfiles(self, ui, m, fm, fmt, subrepos):
         """handle the files command for this subrepo"""
         return 1
 
@@ -904,7 +904,7 @@
         return ctx.flags(name)
 
     @annotatesubrepoerror
-    def printfiles(self, ui, m, fm, fmt):
+    def printfiles(self, ui, m, fm, fmt, subrepos):
         # If the parent context is a workingctx, use the workingctx here for
         # consistency.
         if self._ctx.rev() is None:
@@ -912,7 +912,7 @@
         else:
             rev = self._state[1]
             ctx = self._repo[rev]
-        return cmdutil.files(ui, ctx, m, fm, fmt, True)
+        return cmdutil.files(ui, ctx, m, fm, fmt, subrepos)
 
     @annotatesubrepoerror
     def getfileset(self, expr):
--- a/tests/test-subrepo-deep-nested-change.t	Wed May 20 01:06:09 2015 +0900
+++ b/tests/test-subrepo-deep-nested-change.t	Sun May 17 22:42:47 2015 -0400
@@ -232,6 +232,18 @@
   sub1/sub2/sub2 (glob)
   sub1/sub2/test.txt (glob)
 
+  $ hg files sub1
+  sub1/.hgsub (glob)
+  sub1/.hgsubstate (glob)
+  sub1/foo (glob)
+  sub1/sub1 (glob)
+  sub1/sub2/folder/bar (glob)
+  sub1/sub2/x.txt (glob)
+
+  $ hg files sub1/sub2
+  sub1/sub2/folder/bar (glob)
+  sub1/sub2/x.txt (glob)
+
   $ hg files -S -r '.^' sub1/sub2/folder
   sub1/sub2/folder/test.txt (glob)
 
@@ -239,7 +251,7 @@
   sub1/sub2/missing: no such file in rev 78026e779ea6 (glob)
   [1]
 
-  $ hg files -S -r '.^' sub1/
+  $ hg files -r '.^' sub1/
   sub1/.hgsub (glob)
   sub1/.hgsubstate (glob)
   sub1/sub1 (glob)
@@ -247,7 +259,7 @@
   sub1/sub2/sub2 (glob)
   sub1/sub2/test.txt (glob)
 
-  $ hg files -S -r '.^' sub1/sub2
+  $ hg files -r '.^' sub1/sub2
   sub1/sub2/folder/test.txt (glob)
   sub1/sub2/sub2 (glob)
   sub1/sub2/test.txt (glob)