[MERGE] Add Branch.get_reference and BzrDir.get_branch_reference, plus other miscellany
Andrew Bennetts
andrew at canonical.com
Fri Apr 13 08:22:58 BST 2007
Sorry for the slightly unfocused bundle, but it's fairly short.
This is yet more stuff from the hpss branch.
-Andrew.
-------------- next part --------------
# Bazaar revision bundle v0.9
#
# message:
# Some miscellaneous new APIs, tests and other changes from the hpss branch.
# committer: Andrew Bennetts <andrew.bennetts at canonical.com>
# date: Fri 2007-04-13 17:18:57.884000063 +1000
=== modified file NEWS
--- NEWS
+++ NEWS
@@ -42,9 +42,12 @@
to be in bzrlib/transport/smart.py. (Andrew Bennetts)
* The ``lock_write`` method of ``LockableFiles``, ``Repository`` and
- ``Branch`` now accept a ``token`` keyword argument, so that separate
- instances of those objects can share a lock if it has the right token.
- (Andrew Bennetts, Robert Collins)
+ ``Branch`` now accept a ``token`` keyword argument, so that separate
+ instances of those objects can share a lock if it has the right token.
+ (Andrew Bennetts, Robert Collins)
+
+ * New method 'get_branch_reference' on 'BzrDir' allows the detection of
+ branch references - which the smart server component needs.
BUGFIXES:
=== modified file bzrlib/branch.py
--- bzrlib/branch.py
+++ bzrlib/branch.py
@@ -813,6 +813,18 @@
"""Return the current default format."""
return klass._default_format
+ def get_reference(self, a_bzrdir):
+ """Get the target reference of the branch in a_bzrdir.
+
+ format probing must have been completed before calling
+ this method - it is assumed that the format of the branch
+ in a_bzrdir is correct.
+
+ :param a_bzrdir: The bzrdir to get the branch data from.
+ :return: None if the branch is not a reference branch.
+ """
+ return None
+
def get_format_string(self):
"""Return the ASCII format string that identifies this format."""
raise NotImplementedError(self.get_format_string)
@@ -1125,6 +1137,11 @@
"""See BranchFormat.get_format_description()."""
return "Checkout reference format 1"
+ def get_reference(self, a_bzrdir):
+ """See BranchFormat.get_reference()."""
+ transport = a_bzrdir.get_branch_transport(None)
+ return transport.get('location').read()
+
def initialize(self, a_bzrdir, target_branch=None):
"""Create a branch of this format in a_bzrdir."""
if target_branch is None:
@@ -1745,6 +1762,19 @@
return "Experimental branch format"
@classmethod
+ def get_reference(cls, a_bzrdir):
+ """Get the target reference of the branch in a_bzrdir.
+
+ format probing must have been completed before calling
+ this method - it is assumed that the format of the branch
+ in a_bzrdir is correct.
+
+ :param a_bzrdir: The bzrdir to get the branch data from.
+ :return: None if the branch is not a reference branch.
+ """
+ return None
+
+ @classmethod
def _initialize_control_files(cls, a_bzrdir, utf8_files, lock_filename,
lock_class):
branch_transport = a_bzrdir.get_branch_transport(cls)
=== modified file bzrlib/bzrdir.py
--- bzrlib/bzrdir.py
+++ bzrlib/bzrdir.py
@@ -420,6 +420,15 @@
raise errors.NoRepositoryPresent(self)
raise errors.NoRepositoryPresent(self)
+ def get_branch_reference(self):
+ """Return the referenced URL for the branch in this bzrdir.
+
+ :raises NotBranchError: If there is no Branch.
+ :return: The URL the branch in this bzrdir references if it is a
+ reference branch, or None for regular branches.
+ """
+ return None
+
def get_branch_transport(self, branch_format):
"""Get the transport for use by branch format in this BzrDir.
@@ -1044,12 +1053,26 @@
def destroy_workingtree_metadata(self):
self.transport.delete_tree('checkout')
+ def find_branch_format(self):
+ """Find the branch 'format' for this bzrdir.
+
+ This might be a synthetic object for e.g. RemoteBranch and SVN.
+ """
+ from bzrlib.branch import BranchFormat
+ return BranchFormat.find_format(self)
+
def _get_mkdir_mode(self):
"""Figure out the mode to use when creating a bzrdir subdir."""
temp_control = lockable_files.LockableFiles(self.transport, '',
lockable_files.TransportLock)
return temp_control._dir_mode
+ def get_branch_reference(self):
+ """See BzrDir.get_branch_reference()."""
+ from bzrlib.branch import BranchFormat
+ format = BranchFormat.find_format(self)
+ return format.get_reference(self)
+
def get_branch_transport(self, branch_format):
"""See BzrDir.get_branch_transport()."""
if branch_format is None:
@@ -1126,8 +1149,7 @@
def open_branch(self, unsupported=False):
"""See BzrDir.open_branch."""
- from bzrlib.branch import BranchFormat
- format = BranchFormat.find_format(self)
+ format = self.find_branch_format()
self._check_supported(format, unsupported)
return format.open(self, _found=True)
@@ -1196,7 +1218,7 @@
@classmethod
def probe_transport(klass, transport):
- """Return the .bzrdir style transport present at URL."""
+ """Return the .bzrdir style format present in a directory."""
try:
format_string = transport.get(".bzr/branch-format").read()
except errors.NoSuchFile:
=== modified file bzrlib/tests/HTTPTestUtil.py
--- bzrlib/tests/HTTPTestUtil.py
+++ bzrlib/tests/HTTPTestUtil.py
@@ -21,6 +21,7 @@
import socket
import urlparse
+from bzrlib.smart import protocol
from bzrlib.tests import TestCaseWithTransport
from bzrlib.tests.HttpServer import (
HttpServer,
@@ -29,7 +30,6 @@
from bzrlib.transport import (
get_transport,
)
-from bzrlib.smart import protocol
class WallRequestHandler(TestingHTTPRequestHandler):
=== modified file bzrlib/tests/branch_implementations/test_bound_sftp.py
--- bzrlib/tests/branch_implementations/test_bound_sftp.py
+++ bzrlib/tests/branch_implementations/test_bound_sftp.py
@@ -31,10 +31,18 @@
)
import bzrlib.errors as errors
from bzrlib.tests import TestSkipped
-from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer, paramiko_loaded
-
-
-class BoundSFTPBranch(TestCaseWithSFTPServer):
+from bzrlib.tests import TestCaseWithTransport
+from bzrlib.transport.local import LocalURLServer
+from bzrlib.transport.memory import MemoryServer
+
+
+class BoundSFTPBranch(TestCaseWithTransport):
+
+ def setUp(self):
+ TestCaseWithTransport.setUp(self)
+ self.vfs_transport_factory = MemoryServer
+ if self.transport_server is LocalURLServer:
+ self.transport_server = None
def create_branches(self):
self.build_tree(['base/', 'base/a', 'base/b'])
@@ -59,11 +67,6 @@
self.assertEqual(['r at b-1'], wt_child.branch.revision_history())
return b_base, wt_child
- def tearDown(self):
- self.sftp_base = None
- bzrlib.transport.sftp.clear_connection_cache()
- super(BoundSFTPBranch, self).tearDown()
-
def test_simple_binding(self):
self.build_tree(['base/', 'base/a', 'base/b', 'child/'])
try:
@@ -332,6 +335,3 @@
# performance even when something fails.
-if not paramiko_loaded:
- del BoundSFTPBranch
-
=== modified file bzrlib/tests/branch_implementations/test_branch.py
--- bzrlib/tests/branch_implementations/test_branch.py
+++ bzrlib/tests/branch_implementations/test_branch.py
@@ -598,6 +598,17 @@
class TestFormat(TestCaseWithBranch):
"""Tests for the format itself."""
+ def test_get_reference(self):
+ """get_reference on all regular branches should return None."""
+ if not self.branch_format.is_supported():
+ # unsupported formats are not loopback testable
+ # because the default open will not open them and
+ # they may not be initializable.
+ return
+ made_branch = self.make_branch('.')
+ self.assertEqual(None,
+ made_branch._format.get_reference(made_branch.bzrdir))
+
def test_format_initialize_find_open(self):
# loopback test to check the current format initializes to itself.
if not self.branch_format.is_supported():
@@ -630,7 +641,7 @@
except NotImplementedError:
return
self.assertEqual(self.branch_format,
- branch.BranchFormat.find_format(opened_control))
+ opened_control.find_branch_format())
class TestBound(TestCaseWithBranch):
=== modified file bzrlib/tests/branch_implementations/test_parent.py
--- bzrlib/tests/branch_implementations/test_parent.py
+++ bzrlib/tests/branch_implementations/test_parent.py
@@ -22,8 +22,8 @@
from bzrlib.branch import Branch
import bzrlib.errors
from bzrlib.osutils import abspath, realpath, getcwd
-from bzrlib.urlutils import local_path_from_url, local_path_to_url, escape
from bzrlib.tests import TestCaseWithTransport
+from bzrlib import urlutils
"""Tests for Branch parent URL"""
@@ -38,7 +38,7 @@
def test_set_get_parent(self):
"""Set, re-get and reset the parent"""
- b = self.make_branch('.')
+ b = self.make_branch('subdir')
url = 'http://bazaar-vcs.org/bzr/bzr.dev'
b.set_parent(url)
self.assertEqual(url, b.get_parent())
@@ -49,15 +49,17 @@
b.set_parent('../other_branch')
- self.assertEqual(local_path_to_url('../other_branch'), b.get_parent())
- path = local_path_to_url('../yanb')
+ expected_parent = urlutils.join(self.get_url('subdir'),
+ '../other_branch')
+ self.assertEqual(expected_parent, b.get_parent())
+ path = urlutils.join(self.get_url('subdir'), '../yanb')
b.set_parent(path)
self.assertEqual('../yanb', b._get_parent_location())
self.assertEqual(path, b.get_parent())
self.assertRaises(bzrlib.errors.InvalidURL, b.set_parent, u'\xb5')
- b.set_parent(escape(u'\xb5'))
+ b.set_parent(urlutils.escape(u'\xb5'))
self.assertEqual('%C2%B5', b._get_parent_location())
self.assertEqual(b.base + '%C2%B5', b.get_parent())
=== modified file bzrlib/tests/bzrdir_implementations/test_bzrdir.py
--- bzrlib/tests/bzrdir_implementations/test_bzrdir.py
+++ bzrlib/tests/bzrdir_implementations/test_bzrdir.py
@@ -493,6 +493,32 @@
self.skipIfNoWorkingTree(target)
self.assertEqual(['1'], target.open_workingtree().get_parent_ids())
+ def test_get_branch_reference_on_reference(self):
+ """get_branch_reference should return the right url."""
+ referenced_branch = self.make_branch('referenced')
+ dir = self.make_bzrdir('source')
+ try:
+ reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
+ referenced_branch)
+ except errors.IncompatibleFormat:
+ # this is ok too, not all formats have to support references.
+ return
+ self.assertEqual(referenced_branch.bzrdir.root_transport.abspath('') + '/',
+ dir.get_branch_reference())
+
+ def test_get_branch_reference_on_non_reference(self):
+ """get_branch_reference should return None for non-reference branches."""
+ branch = self.make_branch('referenced')
+ self.assertEqual(None, branch.bzrdir.get_branch_reference())
+
+ def test_get_branch_reference_no_branch(self):
+ """get_branch_reference should not mask NotBranchErrors."""
+ dir = self.make_bzrdir('source')
+ if dir.has_branch():
+ # this format does not support branchless bzrdirs.
+ return
+ self.assertRaises(errors.NotBranchError, dir.get_branch_reference)
+
def test_sprout_bzrdir_empty(self):
dir = self.make_bzrdir('source')
target = self.sproutOrSkip(dir, self.get_url('target'))
=== modified directory // last-changed:andrew.bennetts at canonical.com-200704130
... 71857-s1rpgdaqrrlvcdsw
# revision id: andrew.bennetts at canonical.com-20070413071857-s1rpgdaqrrlvcdsw
# sha1: f38e5b969875128b6b9a98a268fea48ba55762a8
# inventory sha1: f724054a714c4d418165fc7eb5d3ad9716bcddeb
# parent ids:
# pqm at pqm.ubuntu.com-20070413050623-10v4wozs1tu04kcu
# base id: pqm at pqm.ubuntu.com-20070413050623-10v4wozs1tu04kcu
# properties:
# branch-nick: hpss-miscellany
More information about the bazaar
mailing list