add: fix subrepo recursion for explicit path handling
authorDavid M. Carr <david@carrclan.us>
Tue, 17 Jan 2012 19:10:58 -0500
changeset 15911 c654eac03452
parent 15910 2b8d5c55ae67
child 15912 2bd54ffaa27e
add: fix subrepo recursion for explicit path handling When support for handling explicit paths in subrepos was added to the add command (9e99d2bbb1b1), subrepo recursion wasn't taken into account. This change adds an explicitonly argument to cmdutil.add to allow controlling which levels of recursion should include only explicit paths versus all matched paths.
mercurial/cmdutil.py
mercurial/commands.py
mercurial/subrepo.py
tests/test-subrepo-recursion.t
--- a/mercurial/cmdutil.py	Tue Jan 17 19:10:54 2012 -0500
+++ b/mercurial/cmdutil.py	Tue Jan 17 19:10:58 2012 -0500
@@ -1162,7 +1162,7 @@
                 yield change(rev)
     return iterate()
 
-def add(ui, repo, match, dryrun, listsubrepos, prefix):
+def add(ui, repo, match, dryrun, listsubrepos, prefix, explicitonly):
     join = lambda f: os.path.join(prefix, f)
     bad = []
     oldbad = match.bad
@@ -1175,7 +1175,7 @@
         cca = scmutil.casecollisionauditor(ui, abort, wctx)
     for f in repo.walk(match):
         exact = match.exact(f)
-        if exact or f not in repo.dirstate:
+        if exact or not explicitonly and f not in repo.dirstate:
             if cca:
                 cca(f)
             names.append(f)
@@ -1187,11 +1187,11 @@
         try:
             submatch = matchmod.narrowmatcher(subpath, match)
             if listsubrepos:
-                bad.extend(sub.add(ui, submatch, dryrun, prefix))
+                bad.extend(sub.add(ui, submatch, dryrun, listsubrepos, prefix,
+                                   False))
             else:
-                for f in sub.walk(submatch):
-                    if submatch.exact(f):
-                        bad.extend(sub.add(ui, submatch, dryrun, prefix))
+                bad.extend(sub.add(ui, submatch, dryrun, listsubrepos, prefix,
+                                   True))
         except error.LookupError:
             ui.status(_("skipping missing subrepository: %s\n")
                            % join(subpath))
--- a/mercurial/commands.py	Tue Jan 17 19:10:54 2012 -0500
+++ b/mercurial/commands.py	Tue Jan 17 19:10:58 2012 -0500
@@ -174,7 +174,7 @@
 
     m = scmutil.match(repo[None], pats, opts)
     rejected = cmdutil.add(ui, repo, m, opts.get('dry_run'),
-                           opts.get('subrepos'), prefix="")
+                           opts.get('subrepos'), prefix="", explicitonly=False)
     return rejected and 1 or 0
 
 @command('addremove',
--- a/mercurial/subrepo.py	Tue Jan 17 19:10:54 2012 -0500
+++ b/mercurial/subrepo.py	Tue Jan 17 19:10:58 2012 -0500
@@ -310,7 +310,7 @@
         """
         raise NotImplementedError
 
-    def add(self, ui, match, dryrun, prefix):
+    def add(self, ui, match, dryrun, listsubrepos, prefix, explicitonly):
         return []
 
     def status(self, rev2, **opts):
@@ -396,9 +396,9 @@
                 addpathconfig('default-push', defpushpath)
             fp.close()
 
-    def add(self, ui, match, dryrun, prefix):
-        return cmdutil.add(ui, self._repo, match, dryrun, True,
-                           os.path.join(prefix, self._path))
+    def add(self, ui, match, dryrun, listsubrepos, prefix, explicitonly):
+        return cmdutil.add(ui, self._repo, match, dryrun, listsubrepos,
+                           os.path.join(prefix, self._path), explicitonly)
 
     def status(self, rev2, **opts):
         try:
--- a/tests/test-subrepo-recursion.t	Tue Jan 17 19:10:54 2012 -0500
+++ b/tests/test-subrepo-recursion.t	Tue Jan 17 19:10:58 2012 -0500
@@ -193,11 +193,6 @@
   $ hg status -S
   ? foo/bar/z2.txt
   $ hg add foo/bar/z2.txt
-This is expected to add the file, but is currently broken
-  $ hg status -S
-  ? foo/bar/z2.txt
-When fixed, remove the next two commands
-  $ hg add -R foo/bar foo/bar/z2.txt
   $ hg status -S
   A foo/bar/z2.txt
 This is expected to forget the file, but is currently broken