Rev 2477: merge jam's fix for bug 75721 in file:///v/home/vila/src/bugs/111702/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed May 2 15:42:26 BST 2007
At file:///v/home/vila/src/bugs/111702/
------------------------------------------------------------
revno: 2477
revision-id: v.ladeuil+lp at free.fr-20070502144224-xgusmp6ra32m055m
parent: pqm at pqm.ubuntu.com-20070502125159-zpnij2o99tlddedp
parent: john at arbash-meinel.com-20070502143655-id25373m3lgue8ke
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 111702
timestamp: Wed 2007-05-02 16:42:24 +0200
message:
merge jam's fix for bug 75721
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/bzrdir.py bzrdir.py-20060131065624-156dfea39c4387cb
bzrlib/tests/bzrdir_implementations/__init__.py __init__.py-20060131065642-34c39b54f42dd048
bzrlib/tests/bzrdir_implementations/test_bzrdir.py test_bzrdir.py-20060131065642-0ebeca5e30e30866
bzrlib/tests/test_transport_implementations.py test_transport_implementations.py-20051227111451-f97c5c7d5c49fce7
bzrlib/transport/__init__.py transport.py-20050711165921-4978aa7ce1285ad5
------------------------------------------------------------
revno: 2475.2.2
merged: john at arbash-meinel.com-20070502143655-id25373m3lgue8ke
parent: john at arbash-meinel.com-20070501224141-23intuz4dabm0j73
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: single_connect_for_push_75721
timestamp: Wed 2007-05-02 09:36:55 -0500
message:
Add Transport.ensure_base()
------------------------------------------------------------
revno: 2475.2.1
merged: john at arbash-meinel.com-20070501224141-23intuz4dabm0j73
parent: pqm at pqm.ubuntu.com-20070501182714-71xp33bziogu3qu0
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: single_connect_for_push_75721
timestamp: Tue 2007-05-01 17:41:41 -0500
message:
Fix bug #75721. Update the BzrDir api to add clone_on_transport()
This allows us to pass around a Transport which we already have open
rather calling get_transport(url).
This is mostly noticeable in 'bzr push' which was connecting 3-4 times.
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS 2007-04-30 17:45:10 +0000
+++ b/NEWS 2007-05-01 22:41:41 +0000
@@ -12,6 +12,12 @@
Previously we would report the first file as missing, but not show
the new unknown file. (John Arbash Meinel, #111288)
+ * ``bzr push`` should only connect to the remote location one time.
+ We have been connecting 3 times because we forget to pass around
+ the Transport object. This adds ``BzrDir.clone_on_transport()``, so
+ that we can pass in the Transport that we already have.
+ (John Arbash Meinel, #75721)
+
bzr 0.16rc2 2007-04-30
BUGFIXES:
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2007-04-26 05:06:29 +0000
+++ b/bzrlib/builtins.py 2007-05-01 22:41:41 +0000
@@ -709,7 +709,6 @@
location = stored_loc
to_transport = transport.get_transport(location)
- location_url = to_transport.base
br_to = repository_to = dir_to = None
try:
@@ -777,7 +776,7 @@
# 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.
- dir_to = br_from.bzrdir.clone(location_url,
+ dir_to = br_from.bzrdir.clone_on_transport(to_transport,
revision_id=br_from.last_revision())
br_to = dir_to.open_branch()
# TODO: Some more useful message about what was copied
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py 2007-04-26 08:15:40 +0000
+++ b/bzrlib/bzrdir.py 2007-05-01 22:41:41 +0000
@@ -155,8 +155,23 @@
:param force_new_repo: Do not use a shared repository for the target
even if one is available.
"""
- self._make_tail(url)
- result = self._format.initialize(url)
+ return self.clone_on_transport(get_transport(url),
+ revision_id=revision_id,
+ force_new_repo=force_new_repo)
+
+ def clone_on_transport(self, transport, revision_id=None,
+ force_new_repo=False):
+ """Clone this bzrdir and its contents to transport verbatim.
+
+ If the target directory does not exist, it will be created.
+
+ if revision_id is not None, then the clone operation may tune
+ itself to download less data.
+ :param force_new_repo: Do not use a shared repository for the target
+ even if one is available.
+ """
+ self._make_tail_on_transport(transport)
+ result = self._format.initialize_on_transport(transport)
try:
local_repo = self.find_repository()
except errors.NoRepositoryPresent:
@@ -203,6 +218,17 @@
except errors.FileExists:
pass
+ def _make_tail_on_transport(self, transport):
+ """Create the final directory in transport if it doesn't exist.
+
+ We use "Easier to ask for Permission". And just create it, and ignore
+ if the directory already exists.
+ """
+ try:
+ transport.mkdir('.')
+ except errors.FileExists:
+ pass
+
# TODO: Should take a Transport
@classmethod
def create(cls, base, format=None):
@@ -756,9 +782,10 @@
if revision_id is not None, then the clone operation may tune
itself to download less data.
"""
- self._make_tail(url)
+ target_transport = get_transport(url)
+ self._make_tail_on_transport(target_transport)
cloning_format = self.cloning_metadir()
- result = cloning_format.initialize(url)
+ result = cloning_format.initialize_on_transport(target_transport)
try:
source_branch = self.open_branch()
source_repository = source_branch.repository
=== modified file 'bzrlib/tests/bzrdir_implementations/__init__.py'
--- a/bzrlib/tests/bzrdir_implementations/__init__.py 2007-04-17 09:16:29 +0000
+++ b/bzrlib/tests/bzrdir_implementations/__init__.py 2007-05-01 22:41:41 +0000
@@ -28,12 +28,29 @@
from bzrlib.tests import (
adapt_modules,
default_transport,
+ TestCaseWithTransport,
TestLoader,
TestSuite,
)
from bzrlib.transport.memory import MemoryServer
+class TestCaseWithBzrDir(TestCaseWithTransport):
+
+ def setUp(self):
+ super(TestCaseWithBzrDir, self).setUp()
+ self.bzrdir = None
+
+ def get_bzrdir(self):
+ if self.bzrdir is None:
+ self.bzrdir = self.make_bzrdir(None)
+ return self.bzrdir
+
+ def make_bzrdir(self, relpath, format=None):
+ return super(TestCaseWithBzrDir, self).make_bzrdir(
+ relpath, format=self.bzrdir_format)
+
+
def test_suite():
result = TestSuite()
test_bzrdir_implementations = [
=== modified file 'bzrlib/tests/bzrdir_implementations/test_bzrdir.py'
--- a/bzrlib/tests/bzrdir_implementations/test_bzrdir.py 2007-04-23 08:30:30 +0000
+++ b/bzrlib/tests/bzrdir_implementations/test_bzrdir.py 2007-05-01 22:41:41 +0000
@@ -48,6 +48,7 @@
TestCaseWithTransport,
TestSkipped,
)
+from bzrlib.tests.bzrdir_implementations import TestCaseWithBzrDir
from bzrlib.trace import mutter
from bzrlib.transport import get_transport
from bzrlib.upgrade import upgrade
@@ -55,23 +56,6 @@
from bzrlib.repofmt import weaverepo
-class TestCaseWithBzrDir(TestCaseWithTransport):
-
- def setUp(self):
- super(TestCaseWithBzrDir, self).setUp()
- self.bzrdir = None
-
- def get_bzrdir(self):
- if self.bzrdir is None:
- self.bzrdir = self.make_bzrdir(None)
- return self.bzrdir
-
- def make_bzrdir(self, relpath, format=None):
- return super(TestCaseWithBzrDir, self).make_bzrdir(
- relpath, format=self.bzrdir_format)
-
-
-
class TestBzrDir(TestCaseWithBzrDir):
# Many of these tests test for disk equality rather than checking
# for semantic equivalence. This works well for some tests but
@@ -191,7 +175,15 @@
# so this test is irrelevant.
return
self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
-
+
+ def test_clone_on_transport(self):
+ a_dir = self.make_bzrdir('source')
+ target_transport = a_dir.root_transport.clone('..').clone('target')
+ target = a_dir.clone_on_transport(target_transport)
+ self.assertNotEqual(a_dir.transport.base, target.transport.base)
+ self.assertDirectoriesEqual(a_dir.root_transport, target.root_transport,
+ ['./.bzr/merge-hashes'])
+
def test_clone_bzrdir_empty(self):
dir = self.make_bzrdir('source')
target = dir.clone(self.get_url('target'))
=== modified file 'bzrlib/tests/test_transport_implementations.py'
--- a/bzrlib/tests/test_transport_implementations.py 2007-04-23 05:03:44 +0000
+++ b/bzrlib/tests/test_transport_implementations.py 2007-05-02 14:36:55 +0000
@@ -61,6 +61,38 @@
"""Check that transport.get(relpath).read() == content."""
self.assertEqualDiff(content, transport.get(relpath).read())
+ def test_ensure_base_missing(self):
+ """.ensure_base() should create the directory if it doesn't exist"""
+ t = self.get_transport()
+ t_a = t.clone('a')
+ if t_a.is_readonly():
+ self.assertRaises(TransportNotPossible,
+ t_a.ensure_base)
+ return
+ self.assertTrue(t_a.ensure_base())
+ self.assertTrue(t.has('a'))
+
+ def test_ensure_base_exists(self):
+ """.ensure_base() should just be happy if it already exists"""
+ t = self.get_transport()
+ if t.is_readonly():
+ return
+
+ t.mkdir('a')
+ t_a = t.clone('a')
+ # ensure_base returns False if it didn't create the base
+ self.assertFalse(t_a.ensure_base())
+
+ def test_ensure_base_missing_parent(self):
+ """.ensure_base() will fail if the parent dir doesn't exist"""
+ t = self.get_transport()
+ if t.is_readonly():
+ return
+
+ t_a = t.clone('a')
+ t_b = t_a.clone('b')
+ self.assertRaises(NoSuchFile, t_b.ensure_base)
+
def test_has(self):
t = self.get_transport()
=== modified file 'bzrlib/transport/__init__.py'
--- a/bzrlib/transport/__init__.py 2007-04-26 09:07:38 +0000
+++ b/bzrlib/transport/__init__.py 2007-05-02 14:36:55 +0000
@@ -276,6 +276,22 @@
"""
raise NotImplementedError(self.clone)
+ def ensure_base(self):
+ """Ensure that the directory this transport references exists.
+
+ This will create a directory if it doesn't exist.
+ :return: True if the directory was created, False otherwise.
+ """
+ # The default implementation just uses "Easier to ask for forgiveness
+ # than permission". We attempt to create the directory, and just
+ # suppress a FileExists exception.
+ try:
+ self.mkdir('.')
+ except errors.FileExists:
+ return False
+ else:
+ return True
+
def should_cache(self):
"""Return True if the data pulled across should be cached locally.
"""
More information about the bazaar-commits
mailing list