[PATCH 1 of 4 V3] subrepo: isolate configuration between each repositories in subrepo tree

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Wed Oct 17 19:07:35 CDT 2012


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1350478821 -32400
# Node ID 2b0610ddab5949cc1213e291dac0500d8cb13d6a
# Parent  9837cafc25b10c51659b65b5971622eab0bc9197
subrepo: isolate configuration between each repositories in subrepo tree

Before this patch, repository local configurations are not isolated
between repositories in subrepo tree, because "localrepository"
objects for each subrepositories are created with "ui" instance of the
parent of each ones.

So, local configuration of the parent or higher repositories are
visible also in children or lower ones.

This patch uses "baseui" instead of "ui" to create repository object:
the former contains only global configuration.

This patch also copies 'ui.commitsubrepos' configuration to commit
recursively in subrepo tree, because it may be set in not
"repo.baseui" but "repo.ui".

diff -r 9837cafc25b1 -r 2b0610ddab59 mercurial/subrepo.py
--- a/mercurial/subrepo.py	Sat Oct 13 15:10:39 2012 -0500
+++ b/mercurial/subrepo.py	Wed Oct 17 22:00:21 2012 +0900
@@ -395,7 +395,11 @@
         if not os.path.exists(os.path.join(root, '.hg')):
             create = True
             util.makedirs(root)
-        self._repo = hg.repository(r.ui, root, create=create)
+        self._repo = hg.repository(r.baseui, root, create=create)
+        for s, k in [('ui', 'commitsubrepos')]:
+            v = r.ui.config(s, k)
+            if v:
+                self._repo.ui.setconfig(s, k, v)
         self._initrepo(r, state[0], create)
 
     def _initrepo(self, parentrepo, source, create):
diff -r 9837cafc25b1 -r 2b0610ddab59 tests/test-subrepo.t
--- a/tests/test-subrepo.t	Sat Oct 13 15:10:39 2012 -0500
+++ b/tests/test-subrepo.t	Wed Oct 17 22:00:21 2012 +0900
@@ -1021,3 +1021,62 @@
   ? s/f19
   $ rm s/f19
   $ cd ..
+
+Test the isolation of the repository local configuration between each
+repositories in subrepo tree:
+
+  $ mkdir use-baseui
+  $ cd use-baseui
+
+  $ hg init parent
+  $ hg init parent/sub1
+  $ echo 1 > parent/sub1/1
+  $ hg -R parent/sub1 commit -Am '#0 at parent/sub1'
+  adding 1
+  $ hg init parent/sub2
+  $ hg init parent/sub2/sub21
+  $ echo 21 > parent/sub2/sub21/21
+  $ hg -R parent/sub2/sub21 commit -Am '#0 at parent/sub2/sub21'
+  adding 21
+  $ cat > parent/sub2/.hgsub <<EOF
+  > sub21 = sub21
+  > EOF
+  $ hg -R parent/sub2 commit -Am '#0 at parent/sub2'
+  adding .hgsub
+  $ hg init parent/sub3
+  $ echo 3 > parent/sub3/3
+  $ hg -R parent/sub3 commit -Am '#0 at parent/sub3'
+  adding 3
+  $ cat > parent/.hgsub <<EOF
+  > sub1 = sub1
+  > sub2 = sub2
+  > sub3 = sub3
+  > EOF
+  $ hg -R parent commit -Am '#0 at parent'
+  adding .hgsub
+
+  $ cat > $TESTTMP/use-baseui/showvalue.py <<EOF
+  > def reposetup(ui, repo):
+  >     ui.write('%s: showvalue.value=%s\n' %
+  >              (repo.root, ui.config('showvalue', 'value')))
+  > EOF
+  $ cat > parent/.hg/hgrc <<EOF
+  > [showvalue]
+  > value = parent
+  > EOF
+  $ cat > parent/sub2/.hg/hgrc <<EOF
+  > [showvalue]
+  > value = sub2
+  > EOF
+  $ cat >> $HGRCPATH <<EOF
+  > [extensions]
+  > extensions.showvalue=$TESTTMP/use-baseui/showvalue.py
+  > EOF
+  $ hg -R parent status -S
+  $TESTTMP/use-baseui/parent: showvalue.value=parent
+  $TESTTMP/use-baseui/parent/sub1: showvalue.value=None
+  $TESTTMP/use-baseui/parent/sub2: showvalue.value=sub2
+  $TESTTMP/use-baseui/parent/sub2/sub21: showvalue.value=None
+  $TESTTMP/use-baseui/parent/sub3: showvalue.value=None
+
+  $ cd ..


More information about the Mercurial-devel mailing list