Rev 2441: Add new Repository.sprout, in http://sourcefrog.net/bzr/sprout-cleanup

Martin Pool mbp at sourcefrog.net
Mon Apr 23 10:53:18 BST 2007


At http://sourcefrog.net/bzr/sprout-cleanup

------------------------------------------------------------
revno: 2441
revision-id: 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:
  bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
  bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
  bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2007-04-20 08:33:47 +0000
+++ b/bzrlib/bzrdir.py	2007-04-23 09:52:50 +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:
                 result_repo.fetch(source_repository, revision_id=revision_id)

=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2007-04-20 05:11:46 +0000
+++ b/bzrlib/remote.py	2007-04-23 09:52:50 +0000
@@ -427,6 +427,12 @@
         self._ensure_real()
         return self._real_repository.break_lock()
 
+    def sprout(self, to_bzrdir, revision_id=None):
+        # TODO: Option to control what format is created?
+        to_repo = to_bzrdir.create_repository()
+        to_repo.fetch(self, revision_id=revision_id)
+        return to_repo
+
     ### These methods are just thin shims to the VFS object for now.
 
     def revision_tree(self, revision_id):

=== 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.




More information about the bazaar-commits mailing list