changeset 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 98e4d3914c2e
children 10286a04fbd9
files mercurial/subrepo.py tests/test-static-http.t tests/test-subrepo-deep-nested-change.t tests/test-subrepo-recursion.t tests/test-subrepo-relative-path.t tests/test-subrepo.t
diffstat 6 files changed, 30 insertions(+), 68 deletions(-) [+]
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):
--- a/tests/test-static-http.t	Mon May 09 16:41:45 2011 +0200
+++ b/tests/test-static-http.t	Mon May 09 17:15:44 2011 +0200
@@ -117,7 +117,7 @@
   adding file changes
   added 1 changesets with 3 changes to 3 files
   updating to branch default
-  pulling subrepo sub from static-http://localhost:$HGPORT/sub
+  cloning subrepo sub from static-http://localhost:$HGPORT/sub
   requesting all changes
   adding changesets
   adding manifests
--- a/tests/test-subrepo-deep-nested-change.t	Mon May 09 16:41:45 2011 +0200
+++ b/tests/test-subrepo-deep-nested-change.t	Mon May 09 17:15:44 2011 +0200
@@ -27,12 +27,7 @@
   $ echo "sub1 = ../sub1" > main/.hgsub
   $ hg clone sub1 main/sub1
   updating to branch default
-  pulling subrepo sub2 from $TESTTMP/sub2
-  requesting all changes
-  adding changesets
-  adding manifests
-  adding file changes
-  added 1 changesets with 1 changes to 1 files
+  cloning subrepo sub2 from $TESTTMP/sub2
   3 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg add -R main
   adding main/.hgsub
@@ -55,18 +50,8 @@
 
   $ hg clone main cloned
   updating to branch default
-  pulling subrepo sub1 from $TESTTMP/sub1
-  requesting all changes
-  adding changesets
-  adding manifests
-  adding file changes
-  added 1 changesets with 3 changes to 3 files
-  pulling subrepo sub1/sub2 from $TESTTMP/sub2
-  requesting all changes
-  adding changesets
-  adding manifests
-  adding file changes
-  added 1 changesets with 1 changes to 1 files
+  cloning subrepo sub1 from $TESTTMP/sub1
+  cloning subrepo sub1/sub2 from $TESTTMP/sub2
   3 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
 Checking cloned repo ids
--- a/tests/test-subrepo-recursion.t	Mon May 09 16:41:45 2011 +0200
+++ b/tests/test-subrepo-recursion.t	Mon May 09 17:15:44 2011 +0200
@@ -313,18 +313,8 @@
   $ cd ..
   $ hg clone repo repo2
   updating to branch default
-  pulling subrepo foo from $TESTTMP/repo/foo
-  requesting all changes
-  adding changesets
-  adding manifests
-  adding file changes
-  added 4 changesets with 7 changes to 3 files
-  pulling subrepo foo/bar from $TESTTMP/repo/foo/bar
-  requesting all changes
-  adding changesets
-  adding manifests
-  adding file changes
-  added 3 changesets with 3 changes to 1 files
+  cloning subrepo foo from $TESTTMP/repo/foo
+  cloning subrepo foo/bar from $TESTTMP/repo/foo/bar
   3 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ cd repo2
   $ hg outgoing -S
--- a/tests/test-subrepo-relative-path.t	Mon May 09 16:41:45 2011 +0200
+++ b/tests/test-subrepo-relative-path.t	Mon May 09 17:15:44 2011 +0200
@@ -44,7 +44,7 @@
   adding file changes
   added 1 changesets with 3 changes to 3 files
   updating to branch default
-  pulling subrepo sub from http://localhost:$HGPORT/sub
+  cloning subrepo sub from http://localhost:$HGPORT/sub
   requesting all changes
   adding changesets
   adding manifests
@@ -79,7 +79,7 @@
   adding file changes
   added 1 changesets with 3 changes to 3 files
   updating to branch default
-  pulling subrepo sub from ssh://user@dummy/sub
+  cloning subrepo sub from ssh://user@dummy/sub
   requesting all changes
   adding changesets
   adding manifests
--- a/tests/test-subrepo.t	Mon May 09 16:41:45 2011 +0200
+++ b/tests/test-subrepo.t	Mon May 09 17:15:44 2011 +0200
@@ -239,24 +239,9 @@
   $ cd ..
   $ hg clone t tc
   updating to branch default
-  pulling subrepo s from $TESTTMP/sub/t/s
-  requesting all changes
-  adding changesets
-  adding manifests
-  adding file changes
-  added 4 changesets with 5 changes to 3 files
-  pulling subrepo s/ss from $TESTTMP/sub/t/s/ss
-  requesting all changes
-  adding changesets
-  adding manifests
-  adding file changes
-  added 1 changesets with 1 changes to 1 files
-  pulling subrepo t from $TESTTMP/sub/t/t
-  requesting all changes
-  adding changesets
-  adding manifests
-  adding file changes
-  added 4 changesets with 4 changes to 1 files (+1 heads)
+  cloning subrepo s from $TESTTMP/sub/t/s
+  cloning subrepo s/ss from $TESTTMP/sub/t/s/ss
+  cloning subrepo t from $TESTTMP/sub/t/t
   3 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ cd tc
   $ hg debugsub
@@ -563,12 +548,7 @@
   committing subrepository s
   $ hg clone repo repo2
   updating to branch default
-  pulling subrepo s from $TESTTMP/sub/repo/s
-  requesting all changes
-  adding changesets
-  adding manifests
-  adding file changes
-  added 1 changesets with 1 changes to 1 files
+  cloning subrepo s from $TESTTMP/sub/repo/s
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg -q -R repo2 pull -u
   $ echo 1 > repo2/s/a
@@ -639,12 +619,7 @@
   adding manifests
   adding file changes
   added 1 changesets with 2 changes to 2 files
-  pulling subrepo sub/repo from issue1852a/sub/repo
-  requesting all changes
-  adding changesets
-  adding manifests
-  adding file changes
-  added 2 changesets with 2 changes to 1 files
+  cloning subrepo sub/repo from issue1852a/sub/repo
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
 Try to push from the other side