changeset 10666:4c50a90b90fc stable

subrepo: keep ui and hgrc in sync when creating new repo
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Fri, 12 Mar 2010 01:23:35 +0100
parents 664bb0ce95ed
children b7e528212828
files mercurial/subrepo.py
diffstat 1 files changed, 17 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/subrepo.py	Fri Mar 12 01:23:35 2010 +0100
+++ b/mercurial/subrepo.py	Fri Mar 12 01:23:35 2010 +0100
@@ -177,24 +177,32 @@
         self._state = state
         r = ctx._repo
         root = r.wjoin(path)
-        if os.path.exists(os.path.join(root, '.hg')):
-            self._repo = hg.repository(r.ui, root)
-        else:
+        create = False
+        if not os.path.exists(os.path.join(root, '.hg')):
+            create = True
             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' % os.path.join(
-                _abssource(ctx._repo), path))
-            f.close()
+        self._repo = hg.repository(r.ui, root, create=create)
         self._repo._subparent = r
         self._repo._subsource = state[0]
 
+        if create:
+            fp = self._repo.opener("hgrc", "w", text=True)
+            fp.write('[paths]\n')
+
+            def addpathconfig(key, value):
+                fp.write('%s = %s\n' % (key, value))
+                self._repo.ui.setconfig('paths', key, value)
+
+            defpath = os.path.join(_abssource(ctx._repo), path)
+            addpathconfig('default', defpath)
+            fp.close()
+
     def dirty(self):
         r = self._state[1]
         if r == '':
             return True
         w = self._repo[None]
-        if w.p1() != self._repo[r]: # version checked out changed
+        if w.p1() != self._repo[r]: # version checked out change
             return True
         return w.dirty() # working directory changed