Rev 3824: Allow the source branch to pass itself into BzrDir.sprout. in http://bzr.arbash-meinel.com/branches/bzr/1.10-dev/branch_startup

John Arbash Meinel john at arbash-meinel.com
Fri Nov 7 23:17:23 GMT 2008


At http://bzr.arbash-meinel.com/branches/bzr/1.10-dev/branch_startup

------------------------------------------------------------
revno: 3824
revision-id: john at arbash-meinel.com-20081107231705-rwiztjhnf1wjtdzx
parent: pqm at pqm.ubuntu.com-20081104203753-tr3wp885v5p7ccpc
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: branch_startup
timestamp: Fri 2008-11-07 17:17:05 -0600
message:
  Allow the source branch to pass itself into BzrDir.sprout.
  
  This allows us to avoid opening the source branch 2 times, which also causes
  problems with the lifetime of repository and branch locks during the sprout.
-------------- next part --------------
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2008-11-03 21:52:46 +0000
+++ b/bzrlib/builtins.py	2008-11-07 23:17:05 +0000
@@ -977,7 +977,8 @@
                                             possible_transports=[to_transport],
                                             accelerator_tree=accelerator_tree,
                                             hardlink=hardlink, stacked=stacked,
-                                            force_new_repo=standalone)
+                                            force_new_repo=standalone,
+                                            source_branch=br_from)
                 branch = dir.open_branch()
             except errors.NoSuchRevision:
                 to_transport.delete_tree('.')

=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2008-10-28 22:19:31 +0000
+++ b/bzrlib/bzrdir.py	2008-11-07 23:17:05 +0000
@@ -1061,7 +1061,8 @@
 
     def sprout(self, url, revision_id=None, force_new_repo=False,
                recurse='down', possible_transports=None,
-               accelerator_tree=None, hardlink=False, stacked=False):
+               accelerator_tree=None, hardlink=False, stacked=False,
+               source_branch=None):
         """Create a copy of this bzrdir prepared for use as a new line of
         development.
 
@@ -1088,22 +1089,25 @@
         cloning_format = self.cloning_metadir(stacked)
         # Create/update the result branch
         result = cloning_format.initialize_on_transport(target_transport)
-        try:
-            source_branch = self.open_branch()
-            source_repository = source_branch.repository
+        # if a stacked branch wasn't requested, we don't create one
+        # even if the origin was stacked
+        stacked_branch_url = None
+        if source_branch is not None:
             if stacked:
                 stacked_branch_url = self.root_transport.base
-            else:
-                # if a stacked branch wasn't requested, we don't create one
-                # even if the origin was stacked
-                stacked_branch_url = None
-        except errors.NotBranchError:
-            source_branch = None
+            source_repository = source_branch.repository
+        else:
             try:
-                source_repository = self.open_repository()
-            except errors.NoRepositoryPresent:
-                source_repository = None
-            stacked_branch_url = None
+                source_branch = self.open_branch()
+                source_repository = source_branch.repository
+                if stacked:
+                    stacked_branch_url = self.root_transport.base
+            except errors.NotBranchError:
+                source_branch = None
+                try:
+                    source_repository = self.open_repository()
+                except errors.NoRepositoryPresent:
+                    source_repository = None
         repository_policy = result.determine_repository_policy(
             force_new_repo, stacked_branch_url, require_stacking=stacked)
         result_repo = repository_policy.acquire_repository()



More information about the bazaar-commits mailing list