[PATCH 2 of 3 DEFAULT] add: fix subrepo recursion for explicit path handling

David M. Carr david at carrclan.us
Tue Jan 17 18:36:27 CST 2012


# HG changeset patch
# User David M. Carr  <david at carrclan.us>
# Date 1326845458 18000
# Node ID 5a7d51d6a5c1284a9cdceace36d181db5a5dd078
# Parent  d687d007ec1e2eb6f660043b108150cc9b452a0c
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.

diff -r d687d007ec1e -r 5a7d51d6a5c1 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Tue Jan 17 19:10:54 2012 -0500
+++ b/mercurial/cmdutil.py	Tue Jan 17 19:10:58 2012 -0500
@@ -1159,7 +1159,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
@@ -1172,7 +1172,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)
@@ -1184,11 +1184,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))
diff -r d687d007ec1e -r 5a7d51d6a5c1 mercurial/commands.py
--- 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',
diff -r d687d007ec1e -r 5a7d51d6a5c1 mercurial/subrepo.py
--- 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:
diff -r d687d007ec1e -r 5a7d51d6a5c1 tests/test-subrepo-recursion.t
--- 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


More information about the Mercurial-devel mailing list