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

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Sat Sep 29 06:28:45 CDT 2012


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1348917084 -32400
# Node ID 6ed7c5ea60696b1d553fa9ba7117fea74c19613b
# Parent  5c89e7fa5bc20597080494aea43a09903e9e7a6a
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 5c89e7fa5bc2 -r 6ed7c5ea6069 mercurial/subrepo.py
--- a/mercurial/subrepo.py	Thu Sep 20 19:02:47 2012 +0200
+++ b/mercurial/subrepo.py	Sat Sep 29 20:11:24 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 5c89e7fa5bc2 -r 6ed7c5ea6069 tests/test-subrepo.t
--- a/tests/test-subrepo.t	Thu Sep 20 19:02:47 2012 +0200
+++ b/tests/test-subrepo.t	Sat Sep 29 20:11:24 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