[PATCH 2 of 2] subrepo: create subrepos using clone instead of pull

Martin Geisler mg at aragost.com
Fri Mar 25 15:07:55 UTC 2011


# HG changeset patch
# User Martin Geisler <mg at aragost.com>
# Date 1301064435 -3600
# Node ID d786036b749bc58d219b22039559480716bb5071
# Parent  a8019f68e1463d6b1d5406f5f22d17f9aa8c828c
subrepo: create subrepos using clone instead of pull

Subrepositories are currently always created empty and then filled
with data using pull. This is wasteful when you do an initial clone
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 while creating hardlinks when possible.

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -346,8 +346,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)
@@ -450,9 +453,18 @@
                 srcurl = _abssource(self._repo)
                 other = hg.repository(self._repo.ui, srcurl)
 
-            self._repo.ui.status(_('pulling subrepo %s from %s\n')
-                                 % (subrelpath(self), 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):
diff --git a/tests/test-static-http.t b/tests/test-static-http.t
--- a/tests/test-static-http.t
+++ b/tests/test-static-http.t
@@ -118,7 +118,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
diff --git a/tests/test-subrepo-deep-nested-change.t b/tests/test-subrepo-deep-nested-change.t
--- a/tests/test-subrepo-deep-nested-change.t
+++ b/tests/test-subrepo-deep-nested-change.t
@@ -27,12 +27,7 @@
   $ echo "sub1 = ../sub1" > main/.hgsub
   $ hg clone sub1 main/sub1
   updating to branch default
-  pulling subrepo sub2 from $TESTTMP/sub1/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/sub1/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
diff --git a/tests/test-subrepo-recursion.t b/tests/test-subrepo-recursion.t
--- a/tests/test-subrepo-recursion.t
+++ b/tests/test-subrepo-recursion.t
@@ -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
diff --git a/tests/test-subrepo-relative-path.t b/tests/test-subrepo-relative-path.t
--- a/tests/test-subrepo-relative-path.t
+++ b/tests/test-subrepo-relative-path.t
@@ -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
diff --git a/tests/test-subrepo.t b/tests/test-subrepo.t
--- a/tests/test-subrepo.t
+++ b/tests/test-subrepo.t
@@ -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



More information about the Mercurial-devel mailing list