Rev 4296: Move use_existing and create_prefix all the way down to clone_on_transport, reducing duplicate work. in http://people.ubuntu.com/~robertc/baz2.0/pending/push.roundtrips
Robert Collins
robertc at robertcollins.net
Wed Apr 22 03:36:42 BST 2009
At http://people.ubuntu.com/~robertc/baz2.0/pending/push.roundtrips
------------------------------------------------------------
revno: 4296
revision-id: robertc at robertcollins.net-20090422023623-7juu383fqtbu3yzv
parent: robertc at robertcollins.net-20090420041945-qvim67wg99c3euki
committer: Robert Collins <robertc at robertcollins.net>
branch nick: push.roundtrips
timestamp: Wed 2009-04-22 12:36:23 +1000
message:
Move use_existing and create_prefix all the way down to clone_on_transport, reducing duplicate work.
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2009-04-20 04:19:45 +0000
+++ b/bzrlib/branch.py 2009-04-22 02:36:23 +0000
@@ -1145,48 +1145,13 @@
to_transport.
:param use_existing_dir: Use an existing directory if one exists.
"""
- # The destination doesn't exist; create it.
- # XXX: Refactor the create_prefix/no_create_prefix code into a
- # common helper function
-
- def make_directory(transport):
- transport.mkdir('.')
- return transport
-
- def redirected(transport, e, redirection_notice):
- note(redirection_notice)
- return transport._redirected_to(e.source, e.target)
-
- try:
- to_transport = transport.do_catching_redirections(
- make_directory, to_transport, redirected)
- except errors.FileExists:
- if not use_existing_dir:
- raise errors.BzrCommandError("Target directory %s"
- " already exists, but does not have a valid .bzr"
- " directory. Supply --use-existing-dir to push"
- " there anyway." % to_transport.base)
- except errors.NoSuchFile:
- if not create_prefix:
- raise errors.BzrCommandError("Parent directory of %s"
- " does not exist."
- "\nYou may supply --create-prefix to create all"
- " leading parent directories."
- % to_transport.base)
- to_transport.create_prefix()
- except errors.TooManyRedirections:
- raise errors.BzrCommandError("Too many redirections trying "
- "to make %s." % to_transport.base)
-
- # Now the target directory exists, but doesn't have a .bzr
- # directory. So we need to create it, along with any work to create
- # all of the dependent branches, etc.
# XXX: Fix the bzrdir API to allow getting the branch back from the
# clone call. Or something. 20090224 RBC/spiv.
if revision_id is None:
revision_id = self.last_revision()
dir_to = self.bzrdir.clone_on_transport(to_transport,
- revision_id=revision_id, stacked_on=stacked_on)
+ revision_id=revision_id, stacked_on=stacked_on,
+ create_prefix=create_prefix, use_existing_dir=use_existing_dir)
return dir_to.open_branch()
def create_checkout(self, to_location, revision_id=None,
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py 2009-04-14 02:35:07 +0000
+++ b/bzrlib/bzrdir.py 2009-04-22 02:36:23 +0000
@@ -178,8 +178,8 @@
preserve_stacking=preserve_stacking)
def clone_on_transport(self, transport, revision_id=None,
- force_new_repo=False, preserve_stacking=False,
- stacked_on=None):
+ force_new_repo=False, preserve_stacking=False, stacked_on=None,
+ create_prefix=False, use_existing_dir=False):
"""Clone this bzrdir and its contents to transport verbatim.
:param transport: The transport for the location to produce the clone
@@ -191,8 +191,46 @@
even if one is available.
:param preserve_stacking: When cloning a stacked branch, stack the
new branch on top of the other branch's stacked-on branch.
+ :param create_prefix: Create any missing directories leading up to
+ to_transport.
+ :param use_existing_dir: Use an existing directory if one exists.
"""
- transport.ensure_base()
+ # The destination doesn't exist; create it.
+ # XXX: Refactor the create_prefix/no_create_prefix code into a
+ # common helper function
+
+ def make_directory(transport):
+ transport.mkdir('.')
+ return transport
+
+ def redirected(transport, e, redirection_notice):
+ note(redirection_notice)
+ return transport._redirected_to(e.source, e.target)
+
+ try:
+ transport = do_catching_redirections(make_directory, transport,
+ redirected)
+ except errors.FileExists:
+ if not use_existing_dir:
+ raise errors.BzrCommandError("Target directory %s"
+ " already exists, but does not have a valid .bzr"
+ " directory. Supply --use-existing-dir to push"
+ " there anyway." % transport.base)
+ except errors.NoSuchFile:
+ if not create_prefix:
+ raise errors.BzrCommandError("Parent directory of %s"
+ " does not exist."
+ "\nYou may supply --create-prefix to create all"
+ " leading parent directories."
+ % transport.base)
+ transport.create_prefix()
+ except errors.TooManyRedirections:
+ raise errors.BzrCommandError("Too many redirections trying "
+ "to make %s." % transport.base)
+
+ # Now the target directory exists, but doesn't have a .bzr
+ # directory. So we need to create it, along with any work to create
+ # all of the dependent branches, etc.
require_stacking = (stacked_on is not None)
format = self.cloning_metadir(require_stacking)
# Bug: We create a metadir without knowing if it can support stacking,
=== modified file 'bzrlib/tests/blackbox/test_push.py'
--- a/bzrlib/tests/blackbox/test_push.py 2009-04-15 03:20:48 +0000
+++ b/bzrlib/tests/blackbox/test_push.py 2009-04-22 02:36:23 +0000
@@ -201,7 +201,7 @@
# being too low. If rpc_count increases, more network roundtrips have
# become necessary for this use case. Please do not adjust this number
# upwards without agreement from bzr's network support maintainers.
- self.assertLength(19, self.hpss_calls)
+ self.assertLength(18, self.hpss_calls)
def test_push_smart_stacked_streaming_acceptance(self):
self.setup_smart_server_with_call_log()
@@ -217,7 +217,7 @@
# being too low. If rpc_count increases, more network roundtrips have
# become necessary for this use case. Please do not adjust this number
# upwards without agreement from bzr's network support maintainers.
- self.assertLength(23, self.hpss_calls)
+ self.assertLength(22, self.hpss_calls)
remote = Branch.open('public')
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
More information about the bazaar-commits
mailing list