[PATCH 2 of 2 DEFAULT V2] add: support adding explicit files in subrepos

David M. Carr david at carrclan.us
Wed Nov 2 00:33:52 CDT 2011


# HG changeset patch
# User David M. Carr  <david at carrclan.us>
# Date 1320211031 14400
# Node ID 4ca7a090b1ab042488c6458f93b5db28df48c3a6
# Parent  5736a8e0f9a933853e233bd91af15a905b4c509f
add: support adding explicit files in subrepos

Change the behavior of the add command such that explicit paths in
subrepos are always added.  This eliminates the previous behavior
where if you called "hg add" for an explicit path in a subrepo
without specifying the -S option, it would be silently ignored.
If you specify patterns, or no arguments at all, the -S option
will still be needed to activate recursion into subrepos.

diff -r 5736a8e0f9a9 -r 4ca7a090b1ab mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Tue Nov 01 23:53:29 2011 -0400
+++ b/mercurial/cmdutil.py	Wed Nov 02 01:17:11 2011 -0400
@@ -1165,15 +1165,19 @@
             if ui.verbose or not exact:
                 ui.status(_('adding %s\n') % match.rel(join(f)))
 
-    if listsubrepos:
-        for subpath in wctx.substate:
-            sub = wctx.sub(subpath)
-            try:
-                submatch = matchmod.narrowmatcher(subpath, match)
+    for subpath in wctx.substate:
+        sub = wctx.sub(subpath)
+        try:
+            submatch = matchmod.narrowmatcher(subpath, match)
+            if listsubrepos:
                 bad.extend(sub.add(ui, submatch, dryrun, prefix))
-            except error.LookupError:
-                ui.status(_("skipping missing subrepository: %s\n")
-                               % join(subpath))
+            else:
+                for f in sub.walk(submatch):
+                    if submatch.exact(f):
+                        bad.extend(sub.add(ui, submatch, dryrun, prefix))                
+        except error.LookupError:
+            ui.status(_("skipping missing subrepository: %s\n")
+                           % join(subpath))
 
     if not dryrun:
         rejected = wctx.add(names, prefix)
diff -r 5736a8e0f9a9 -r 4ca7a090b1ab mercurial/help/subrepos.txt
--- a/mercurial/help/subrepos.txt	Tue Nov 01 23:53:29 2011 -0400
+++ b/mercurial/help/subrepos.txt	Wed Nov 02 01:17:11 2011 -0400
@@ -73,7 +73,9 @@
 -----------------------------------
 
 :add: add does not recurse in subrepos unless -S/--subrepos is
-    specified. Subversion subrepositories are currently silently
+    specified.  However, if you specify the full path of a file in a
+    subrepo, it will be added even without -S/--subrepos specified.
+    Subversion subrepositories are currently silently
     ignored.
 
 :archive: archive does not recurse in subrepositories unless
diff -r 5736a8e0f9a9 -r 4ca7a090b1ab mercurial/subrepo.py
--- a/mercurial/subrepo.py	Tue Nov 01 23:53:29 2011 -0400
+++ b/mercurial/subrepo.py	Wed Nov 02 01:17:11 2011 -0400
@@ -353,6 +353,12 @@
                         unit=_('files'), total=total)
         ui.progress(_('archiving (%s)') % relpath, None)
 
+    def walk(self, match):
+        '''
+        walk recursively through the directory tree, finding all files
+        matched by the match function
+        '''
+        pass
 
 class hgsubrepo(abstractsubrepo):
     def __init__(self, ctx, path, state):
@@ -542,6 +548,10 @@
         rev = self._state[1]
         ctx = self._repo[rev]
         return ctx.flags(name)
+    
+    def walk(self, match):
+        ctx = self._repo[None]
+        return ctx.walk(match)
 
 
 class svnsubrepo(abstractsubrepo):
diff -r 5736a8e0f9a9 -r 4ca7a090b1ab tests/test-subrepo.t
--- a/tests/test-subrepo.t	Tue Nov 01 23:53:29 2011 -0400
+++ b/tests/test-subrepo.t	Wed Nov 02 01:17:11 2011 -0400
@@ -892,7 +892,7 @@
   $ hg init s
   $ hg ci -m0
   committing subrepository s
-Adding with an explicit path in a subrepo currently fails silently
+Adding with an explicit path in a subrepo adds the file
   $ echo c1 > f1
   $ echo c2 > s/f2
   $ hg st -S
@@ -900,14 +900,13 @@
   ? s/f2
   $ hg add s/f2
   $ hg st -S
+  A s/f2
   ? f1
-  ? s/f2
-  $ hg ci -R s -Am0
-  adding f2
+  $ hg ci -R s -m0
   $ hg ci -Am1
   adding f1
   committing subrepository s
-Adding with an explicit path in a subrepo with -S adds the file
+Adding with an explicit path in a subrepo with -S has the same behavior
   $ echo c3 > f3
   $ echo c4 > s/f4
   $ hg st -S


More information about the Mercurial-devel mailing list