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

David M. Carr david at carrclan.us
Mon Oct 31 20:56:47 CDT 2011


# HG changeset patch
# User David M. Carr  <david at carrclan.us>
# Date 1320027122 14400
# Branch stable
# Node ID 5e4b658f6f60adff3cc39ef20ea2753ca9a29db5
# Parent  7ea4f7ac5854aa6e301dd2ef19667b3b5c4bb796
add: support adding explicit files in subrepos

Change the behavior of the add command such that matched paths in
subrepos are always added.  Effectively, this makes "hg add" always
work like "hg add -S" did before this change.  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.  This also gets us one step closer to the goal of having
subrepos "Just Work".

diff -r 7ea4f7ac5854 -r 5e4b658f6f60 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Sun Oct 30 22:11:56 2011 -0400
+++ b/mercurial/cmdutil.py	Sun Oct 30 22:12:02 2011 -0400
@@ -1145,7 +1145,7 @@
                 yield change(rev)
     return iterate()
 
-def add(ui, repo, match, dryrun, listsubrepos, prefix):
+def add(ui, repo, match, dryrun, prefix):
     join = lambda f: os.path.join(prefix, f)
     bad = []
     oldbad = match.bad
@@ -1165,15 +1165,14 @@
             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)
-                bad.extend(sub.add(ui, submatch, dryrun, prefix))
-            except error.LookupError:
-                ui.status(_("skipping missing subrepository: %s\n")
-                               % join(subpath))
+    for subpath in wctx.substate:
+        sub = wctx.sub(subpath)
+        try:
+            submatch = matchmod.narrowmatcher(subpath, match)
+            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 7ea4f7ac5854 -r 5e4b658f6f60 mercurial/commands.py
--- a/mercurial/commands.py	Sun Oct 30 22:11:56 2011 -0400
+++ b/mercurial/commands.py	Sun Oct 30 22:12:02 2011 -0400
@@ -168,7 +168,7 @@
 
     m = scmutil.match(repo[None], pats, opts)
     rejected = cmdutil.add(ui, repo, m, opts.get('dry_run'),
-                           opts.get('subrepos'), prefix="")
+                           prefix="")
     return rejected and 1 or 0
 
 @command('addremove',
diff -r 7ea4f7ac5854 -r 5e4b658f6f60 mercurial/subrepo.py
--- a/mercurial/subrepo.py	Sun Oct 30 22:11:56 2011 -0400
+++ b/mercurial/subrepo.py	Sun Oct 30 22:12:02 2011 -0400
@@ -388,7 +388,7 @@
             fp.close()
 
     def add(self, ui, match, dryrun, prefix):
-        return cmdutil.add(ui, self._repo, match, dryrun, True,
+        return cmdutil.add(ui, self._repo, match, dryrun,
                            os.path.join(prefix, self._path))
 
     def status(self, rev2, **opts):
diff -r 7ea4f7ac5854 -r 5e4b658f6f60 tests/test-subrepo.t
--- a/tests/test-subrepo.t	Sun Oct 30 22:11:56 2011 -0400
+++ b/tests/test-subrepo.t	Sun Oct 30 22:12:02 2011 -0400
@@ -897,11 +897,17 @@
   ? s/a
   $ hg add s/a
   $ hg st -S
-  ? s/a
-  $ hg add -S s/a
-  $ hg st -S
   A s/a
   $ hg ci -R s -ms0
   $ hg ci -ma1
   committing subrepository s
+  $ echo b > s/b
+  $ hg st -S
+  ? s/b
+  $ hg add -S s/b
+  $ hg st -S
+  A s/b
+  $ hg ci -R s -ms1
+  $ hg ci -ma2
+  committing subrepository s
   $ cd ..


More information about the Mercurial-devel mailing list