[PATCH] sburepo: change default path in hgrc of subrepo after cloning

Saint Germain saintger at gmail.com
Mon Feb 8 18:03:46 CST 2010


# HG changeset patch
# User Saint Germain <saintger at gmail.com>
# Date 1265673777 -3600
# Node ID c896016c1a4f6bd6fd9b30b6549a3aeeb0759671
# Parent  b9e44cc97355ff27e05f6cd384061fc12731cec0
sburepo: change default path in hgrc of subrepo after cloning

Previous behavior was to put in the cloned subrepos the path found in the original main repo.
However it isn't valid for relative path and it seems more logical to reference instead the subrepos
working copy path of the original main repo.

We have to be careful however to keep the previous behavior in case of committing a new subrepo.
In that case, the correct default path is the value referenced in the .hgsub file appended to the
main repository path (to have the correct relative path).

diff -r b9e44cc97355 -r c896016c1a4f mercurial/subrepo.py
--- a/mercurial/subrepo.py	Wed Feb 03 16:09:19 2010 +0000
+++ b/mercurial/subrepo.py	Tue Feb 09 01:02:57 2010 +0100
@@ -183,7 +183,16 @@
             util.makedirs(root)
             self._repo = hg.repository(r.ui, root, create=True)
             f = file(os.path.join(root, '.hg', 'hgrc'), 'w')
-            f.write('[paths]\ndefault = %s\n' % state[0])
+            # If newly commited, a subrepo default path is set to .hgsub value
+            if state[1] == '':
+                f.write('[paths]\ndefault = %s\n' % os.path.join(
+                    _abssource(ctx._repo), state[0]))
+            # Otherwise (cloning case) it is set to the cloning source path
+            # However this introduce a discrepancy between the subrepo default
+            # path and its .hgsub value (still set to the pre-cloning value)
+            else:
+                f.write('[paths]\ndefault = %s\n' % os.path.join(
+                    _abssource(ctx._repo), path))
             f.close()
         self._repo._subparent = r
         self._repo._subsource = state[0]
diff -r b9e44cc97355 -r c896016c1a4f tests/test-subrepo
--- a/tests/test-subrepo	Wed Feb 03 16:09:19 2010 +0000
+++ b/tests/test-subrepo	Tue Feb 09 01:02:57 2010 +0100
@@ -160,5 +160,28 @@
 
 hg up 5
 hg merge 4    # try to merge default into br again
+cd ..
+
+echo % test repository cloning
+mkdir mercurial mercurial2
+cd mercurial
+hg init $PWD/nested_absolute # Using $PWD instead of /tmp
+echo test > $PWD/nested_absolute/foo
+hg -R $PWD/nested_absolute add
+hg -R $PWD/nested_absolute ci -mtest
+hg init nested_relative
+echo test2 > nested_relative/foo2
+hg -R nested_relative add
+hg -R nested_relative ci -mtest2
+hg init main
+echo nested_relative = ../nested_relative > main/.hgsub
+echo nested_absolute = $PWD/nested_absolute >> main/.hgsub
+hg -R main add
+hg -R main ci -m "add subrepos"
+cd ..
+hg clone mercurial/main mercurial2/main
+cat mercurial/main/nested_absolute/.hg/hgrc mercurial/main/nested_relative/.hg/hgrc | sed "s:${PWD}:/tmp:"
+cat mercurial2/main/nested_absolute/.hg/hgrc mercurial2/main/nested_relative/.hg/hgrc | sed "s:${PWD}:/tmp:"
+rm -rf mercurial mercurial2
 
 exit 0
diff -r b9e44cc97355 -r c896016c1a4f tests/test-subrepo.out
--- a/tests/test-subrepo.out	Wed Feb 03 16:09:19 2010 +0000
+++ b/tests/test-subrepo.out	Tue Feb 09 01:02:57 2010 +0100
@@ -243,3 +243,19 @@
 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 (branch merge, don't forget to commit)
+% test repository cloning
+adding nested_absolute/foo
+adding nested_relative/foo2
+adding main/.hgsub
+committing subrepository nested_relative
+committing subrepository nested_absolute
+updating to branch default
+2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+[paths]
+default = /tmp/mercurial/nested_absolute
+[paths]
+default = /tmp/mercurial/main/../nested_relative
+[paths]
+default = /tmp/mercurial/main/nested_absolute
+[paths]
+default = /tmp/mercurial/main/nested_relative


More information about the Mercurial-devel mailing list