diff mercurial/subrepo.py @ 14281:ccb7240acf32

subrepo: create subrepos using clone instead of pull Subrepositories used to be created empty and then filled with data using pull. This is wasteful when you do a clone from a local source since it means that no hardlinks are created for the subrepos. This patch make the hgsubrepo._get method check for an empty subrepo and in that case do a clone instead of a pull. This brings in the same data as before, but creates hardlinks when possible.
author Martin Geisler <mg@aragost.com>
date Mon, 09 May 2011 17:15:44 +0200
parents 680c3c6fcb48
children ba883fa211f3
line wrap: on
line diff
--- a/mercurial/subrepo.py	Mon May 09 16:41:45 2011 +0200
+++ b/mercurial/subrepo.py	Mon May 09 17:15:44 2011 +0200
@@ -342,8 +342,11 @@
             create = True
             util.makedirs(root)
         self._repo = hg.repository(r.ui, root, create=create)
-        self._repo._subparent = r
-        self._repo._subsource = state[0]
+        self._initrepo(r, state[0], create)
+
+    def _initrepo(self, parentrepo, source, create):
+        self._repo._subparent = parentrepo
+        self._repo._subsource = source
 
         if create:
             fp = self._repo.opener("hgrc", "w", text=True)
@@ -431,10 +434,19 @@
         if revision not in self._repo:
             self._repo._subsource = source
             srcurl = _abssource(self._repo)
-            self._repo.ui.status(_('pulling subrepo %s from %s\n')
-                                 % (subrelpath(self), srcurl))
             other = hg.repository(self._repo.ui, srcurl)
-            self._repo.pull(other)
+            if len(self._repo) == 0:
+                self._repo.ui.status(_('cloning subrepo %s from %s\n')
+                                     % (subrelpath(self), srcurl))
+                parentrepo = self._repo._subparent
+                shutil.rmtree(self._repo.root)
+                other, self._repo = hg.clone(self._repo._subparent.ui, other,
+                                             self._repo.root, update=False)
+                self._initrepo(parentrepo, source, create=True)
+            else:
+                self._repo.ui.status(_('pulling subrepo %s from %s\n')
+                                     % (subrelpath(self), srcurl))
+                self._repo.pull(other)
             bookmarks.updatefromremote(self._repo.ui, self._repo, other)
 
     def get(self, state, overwrite=False):