Rev 2214: Merge Repository.sprout refactoring, and make that use Repository.tarball in http://sourcefrog.net/bzr/hpss-faster-copy

Martin Pool mbp at sourcefrog.net
Mon Apr 23 13:06:56 BST 2007


At http://sourcefrog.net/bzr/hpss-faster-copy

------------------------------------------------------------
revno: 2214
revision-id: mbp at sourcefrog.net-20070423120654-7k0q70jyjrvb5g38
parent: mbp at sourcefrog.net-20070423071826-0vcm0vzp4jp3ajax
parent: mbp at sourcefrog.net-20070423095250-xzaleukzs05x9lp0
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: hpss-faster-copy
timestamp: Mon 2007-04-23 22:06:54 +1000
message:
  Merge Repository.sprout refactoring, and make that use Repository.tarball
modified:
  bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
  bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
  bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
  bzrlib/tests/test_remote.py    test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
    ------------------------------------------------------------
    revno: 2018.1.2.1.50.2.80.1.99.1.9.1.21.1.26.2.74.2.2.2.32.1.1.1.27
    merged: mbp at sourcefrog.net-20070423095250-xzaleukzs05x9lp0
    parent: pqm at pqm.ubuntu.com-20070421151139-5wau2ukbpx5z1hv2
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: sprout-cleanup
    timestamp: Mon 2007-04-23 19:52:50 +1000
    message:
      Add new Repository.sprout,
      
      Cleaner in intention and purpose than copy_content_into.  It doesn't copy the
      extra settings of the repository (like working-trees and shared), which is
      normally what you'll want.
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2007-04-23 05:03:44 +0000
+++ b/bzrlib/bzrdir.py	2007-04-23 12:06:54 +0000
@@ -781,11 +781,8 @@
             result.create_repository()
         elif source_repository is not None and result_repo is None:
             # have source, and want to make a new target repo
-            # we don't clone the repo because that preserves attributes
-            # like is_shared(), and we have not yet implemented a 
-            # repository sprout().
-            result_repo = result.create_repository()
-        if result_repo is not None:
+            result_repo = source_repository.sprout(result, revision_id=revision_id)
+        else:
             # fetch needed content into target.
             if source_repository is not None:
                 # would rather do 

=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2007-04-23 07:18:26 +0000
+++ b/bzrlib/remote.py	2007-04-23 12:06:54 +0000
@@ -442,6 +442,12 @@
         else:
             raise errors.SmartServerError(error_code=response)
 
+    def sprout(self, to_bzrdir, revision_id=None):
+        # TODO: Option to control what format is created?
+        to_repo = to_bzrdir.create_repository()
+        self._copy_repository_tarball(to_repo, revision_id)
+        return to_repo
+
     ### These methods are just thin shims to the VFS object for now.
 
     def revision_tree(self, revision_id):
@@ -578,6 +584,11 @@
         return self._real_repository.check(revision_ids)
 
     def copy_content_into(self, destination, revision_id=None):
+        self._ensure_real()
+        return self._real_repository.copy_content_into(
+            destination, revision_id=revision_id)
+
+    def _copy_repository_tarball(self, destination, revision_id=None):
         # get a tarball of the remote repository, and copy from that into the
         # destination
         from bzrlib import osutils

=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2007-04-18 05:38:31 +0000
+++ b/bzrlib/repository.py	2007-04-23 09:52:50 +0000
@@ -395,6 +395,23 @@
 
         :return: The newly created destination repository.
         """
+        # TODO: deprecate after 0.16; cloning this with all its settings is
+        # probably not very useful -- mbp 20070423
+        dest_repo = self._create_sprouting_repo(a_bzrdir, shared=self.is_shared())
+        self.copy_content_into(dest_repo, revision_id)
+        return dest_repo
+
+    @needs_read_lock
+    def sprout(self, to_bzrdir, revision_id=None):
+        """Create a descendent repository for new development.
+
+        Unlike clone, this does not copy the settings of the repository.
+        """
+        dest_repo = self._create_sprouting_repo(to_bzrdir, shared=False)
+        dest_repo.fetch(self, revision_id=revision_id)
+        return dest_repo
+
+    def _create_sprouting_repo(self, a_bzrdir, shared):
         if not isinstance(a_bzrdir._format, self.bzrdir._format.__class__):
             # use target default format.
             dest_repo = a_bzrdir.create_repository()
@@ -402,10 +419,9 @@
             # Most control formats need the repository to be specifically
             # created, but on some old all-in-one formats it's not needed
             try:
-                dest_repo = self._format.initialize(a_bzrdir, shared=self.is_shared())
+                dest_repo = self._format.initialize(a_bzrdir, shared=shared)
             except errors.UninitializableFormat:
                 dest_repo = a_bzrdir.open_repository()
-        self.copy_content_into(dest_repo, revision_id)
         return dest_repo
 
     @needs_read_lock
@@ -772,7 +788,7 @@
         reconciler = RepoReconciler(self, thorough=thorough)
         reconciler.reconcile()
         return reconciler
-    
+
     @needs_read_lock
     def revision_tree(self, revision_id):
         """Return Tree for a revision on this branch.
@@ -1385,6 +1401,9 @@
     @needs_write_lock
     def copy_content(self, revision_id=None):
         """Make a complete copy of the content in self into destination.
+
+        This copies both the repository's revision data, and configuration information
+        such as the make_working_trees setting.
         
         This is a destructive operation! Do not use it on existing 
         repositories.

=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py	2007-04-23 07:18:26 +0000
+++ b/bzrlib/tests/test_remote.py	2007-04-23 12:06:54 +0000
@@ -661,8 +661,8 @@
         self.assertEqual(expected_calls, client._calls)
         self.assertEqual(self.tarball_content, tarball_data)
 
-    def test_copy_content_into_uses_tarball(self):
-        # copy_content_into on a RemoteRepository should try to use the
+    def test_sprout_uses_tarball(self):
+        # RemoteRepository.sprout should try to use the
         # tarball command rather than accessing all the files
         transport_path = 'srcrepo'
         expected_responses = [(('ok',), self.tarball_content),
@@ -676,9 +676,8 @@
         dest_transport.mkdir('destrepo')
         bzrdir_format = bzrdir.format_registry.make_bzrdir('default')
         dest_bzrdir = bzrdir_format.initialize_on_transport(dest_transport)
-        dest_repo = dest_bzrdir.create_repository()
         # try to copy...
-        remote_repo.copy_content_into(dest_repo)
+        remote_repo.sprout(dest_bzrdir)
 
 
 class TestRemoteRepositoryCopyContent(tests.TestCaseWithTransport):




More information about the bazaar-commits mailing list