[PATCH] subrepos: add ui.recursesubrepos option

Martin Geisler mg at aragost.com
Thu Sep 22 09:14:50 CDT 2011


# HG changeset patch
# User Martin Geisler <mg at aragost.com>
# Date 1308244309 -7200
# Node ID 558d09d8ff5b3ab6f812530e0e77c8b54aa397ec
# Parent  91dc8878f88857f01b86a99ad047400704b5fd7e
subrepos: add ui.recursesubrepos option

This option can be used to make commit, status, diff consistent with
each other. If unset, the current behavior is kept unchanged:

          | recurses   | recurses
          | by default | with --subrepos
  --------+------------+----------------
  commit: | True       | n/a
  status: | False      | True
  diff:   | False      | True

If ui.recursesubrepos is set to a boolean B, then we have:

          | recurses   | recurses
          | by default | with --subrepos
  --------+------------+----------------
  commit: | B          | True
  status: | B          | True
  diff:   | B          | True

The new --subrepos flag for commit is there to let the user override a
ui.recursesubrepos=False setting and thus make the table complete.

The ui.recursesubrepos option takes precedence over ui.commitsubrepos
which is now deprecated.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1110,7 +1110,7 @@
      _('mark new/missing files as added/removed before committing')),
     ('', 'close-branch', None,
      _('mark a branch as closed, hiding it from the branch list')),
-    ] + walkopts + commitopts + commitopts2,
+    ] + walkopts + commitopts + commitopts2 + subrepoopts,
     _('[OPTION]... [FILE]...'))
 def commit(ui, repo, *pats, **opts):
     """commit the specified files or all outstanding changes
@@ -1134,6 +1134,15 @@
 
     Returns 0 on success, 1 if nothing changed.
     """
+    # Subrepo recursion: --subrepos overwrite config settings and
+    # ui.commitsubrepos is used for backwards compatibility if
+    # ui.recursesubrepos is not also set.
+    if opts.get('subrepos'):
+        ui.setconfig('ui', 'recursesubrepos', True)
+    elif ui.config('ui', 'recursesubrepos') is None:
+        ui.setconfig('ui', 'recursesubrepos',
+                     ui.configbool('ui', 'commitsubrepos', True))
+
     extra = {}
     if opts.get('close_branch'):
         if repo['.'].node() not in repo.branchheads():
@@ -2262,6 +2271,8 @@
 
     Returns 0 on success.
     """
+    if ui.configbool('ui', 'recursesubrepos'):
+        opts['subrepos'] = True
 
     revs = opts.get('rev')
     change = opts.get('change')
@@ -4874,6 +4885,8 @@
 
     Returns 0 on success.
     """
+    if ui.configbool('ui', 'recursesubrepos'):
+        opts['subrepos'] = True
 
     revs = opts.get('rev')
     change = opts.get('change')
diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
--- a/mercurial/help/config.txt
+++ b/mercurial/help/config.txt
@@ -1007,10 +1007,22 @@
     Default is False.
 
 ``commitsubrepos``
-    Whether to commit modified subrepositories when committing the
-    parent repository. If False and one subrepository has uncommitted
-    changes, abort the commit.
-    Default is True.
+    (DEPRECATED Whether to commit modified subrepositories when
+    committing the parent repository. If False and one subrepository
+    has uncommitted changes, abort the commit. See also
+    ``recursesubrepos``. Default is True.
+
+``recursesubrepos``
+
+    Whether to recurse into subrepositories for :hg:`commit`,
+    :hg:`status`, and :hg:`diff`. Takes precedence over
+    ``commitsubrepos``. The default is True for :hg:`commit` and False
+    for :hg:`status` and :hg:`diff`.
+
+    Set this to True or False to make the three commands consistent
+    with each other. Setting it to False will let you override the
+    behavior as necessary with the ``--subrepo`` flag on the command
+    line, but there is no command line flag to override a True value.
 
 ``debug``
     Print debugging information. True or False. Default is False.
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1052,7 +1052,7 @@
                     '.hgsubstate' not in changes[0] + changes[1] + changes[2]):
                     changes[2].insert(0, '.hgsubstate')
 
-            if subs and not self.ui.configbool('ui', 'commitsubrepos', True):
+            if subs and not self.ui.configbool('ui', 'recursesubrepos', True):
                 changedsubs = [s for s in subs if wctx.sub(s).dirty(True)]
                 if changedsubs:
                     raise util.Abort(_("uncommitted changes in subrepo %s")
diff --git a/tests/test-debugcomplete.t b/tests/test-debugcomplete.t
--- a/tests/test-debugcomplete.t
+++ b/tests/test-debugcomplete.t
@@ -190,7 +190,7 @@
   add: include, exclude, subrepos, dry-run
   annotate: rev, follow, no-follow, text, user, file, date, number, changeset, line-number, include, exclude
   clone: noupdate, updaterev, rev, branch, pull, uncompressed, ssh, remotecmd, insecure
-  commit: addremove, close-branch, include, exclude, message, logfile, date, user
+  commit: addremove, close-branch, include, exclude, message, logfile, date, user, subrepos
   diff: rev, change, text, git, nodates, show-function, reverse, ignore-all-space, ignore-space-change, ignore-blank-lines, unified, stat, include, exclude, subrepos
   export: output, switch-parent, rev, text, git, nodates
   forget: include, exclude
diff --git a/tests/test-qrecord.t b/tests/test-qrecord.t
--- a/tests/test-qrecord.t
+++ b/tests/test-qrecord.t
@@ -64,6 +64,7 @@
    -l --logfile FILE        read commit message from file
    -d --date DATE           record the specified date as commit date
    -u --user USER           record the specified user as committer
+   -S --subrepos            recurse into subrepositories
    -w --ignore-all-space    ignore white space when comparing lines
    -b --ignore-space-change ignore changes in the amount of white space
    -B --ignore-blank-lines  ignore changes whose lines are all blank
diff --git a/tests/test-subrepo-recursion.t b/tests/test-subrepo-recursion.t
--- a/tests/test-subrepo-recursion.t
+++ b/tests/test-subrepo-recursion.t
@@ -37,6 +37,24 @@
   A foo/y.txt
   A x.txt
 
+Test recursive status via config setting:
+
+  $ hg status --config ui.recursesubrepos=Yes
+  A .hgsub
+  A foo/.hgsub
+  A foo/bar/z.txt
+  A foo/y.txt
+  A x.txt
+
+The command line flag overrides the config setting:
+
+  $ hg status --config ui.recursesubrepos=No --subrepos
+  A .hgsub
+  A foo/.hgsub
+  A foo/bar/z.txt
+  A foo/y.txt
+  A x.txt
+
 Test recursive diff without committing anything:
 
   $ hg diff --nodates -S foo
@@ -58,7 +76,13 @@
 
 Commits:
 
-  $ hg commit -m 0-0-0
+  $ hg commit -m fails --config ui.recursesubrepos=No
+  abort: uncommitted changes in subrepo foo
+  [255]
+
+The --subrepos flag overwrite the config setting:
+
+  $ hg commit -m 0-0-0 --config ui.recursesubrepos=No --subrepos
   committing subrepository foo
   committing subrepository foo/bar
 


More information about the Mercurial-devel mailing list