Rev 4071: Add a BzrDirFormat.network_name. in http://people.ubuntu.com/~robertc/baz2.0/bzrdir.network_name
Robert Collins
robertc at robertcollins.net
Tue Mar 3 01:06:32 GMT 2009
At http://people.ubuntu.com/~robertc/baz2.0/bzrdir.network_name
------------------------------------------------------------
revno: 4071
revision-id: robertc at robertcollins.net-20090303010625-5bjnznbsmxv0bm7j
parent: pqm at pqm.ubuntu.com-20090302155409-89pygn9tisbc0lir
committer: Robert Collins <robertc at robertcollins.net>
branch nick: bzrdir.network_name
timestamp: Tue 2009-03-03 12:06:25 +1100
message:
Add a BzrDirFormat.network_name.
=== modified file 'NEWS'
--- a/NEWS 2009-03-02 15:54:09 +0000
+++ b/NEWS 2009-03-03 01:06:25 +0000
@@ -170,8 +170,9 @@
``resume_write_group`` methods. These are currently only useful
with pack repositories. (Andrew Bennetts, Robert Collins)
- * ``RepositoryFormat`` objects now have a ``network_name`` for passing
- the format across RPC calls. (Robert Collins, Andrew Bennetts)
+ * ``BzrDirFormat``, ``BranchFormat`` and ``RepositoryFormat`` objects
+ now have a ``network_name`` for passing the format across RPC calls.
+ (Robert Collins, Andrew Bennetts)
* ``RepositoryFormat`` objects now all have a new attribute
``_serializer`` used by fetch when reserialising is required.
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2009-03-02 04:45:02 +0000
+++ b/bzrlib/branch.py 2009-03-03 01:06:25 +0000
@@ -1709,7 +1709,7 @@
network_format_registry = registry.FormatRegistry()
"""Registry of formats indexed by their network name.
-The network name for a repository format is an identifier that can be used when
+The network name for a branch format is an identifier that can be used when
referring to formats with smart server operations. See
BranchFormat.network_name() for more detail.
"""
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py 2009-02-26 06:01:51 +0000
+++ b/bzrlib/bzrdir.py 2009-03-03 01:06:25 +0000
@@ -1779,6 +1779,16 @@
"""
return True
+ def network_name(self):
+ """A simple byte string uniquely identifying this format for RPC calls.
+
+ Bzr control formats use thir disk format string to identify the format
+ over the wire. Its possible that other control formats have more
+ complex detection requirements, so we permit them to use any unique and
+ immutable string they desire.
+ """
+ raise NotImplementedError(self.network_name)
+
def same_model(self, target_format):
return (self.repository_format.rich_root_data ==
target_format.rich_root_data)
@@ -1829,6 +1839,8 @@
@classmethod
def register_format(klass, format):
klass._formats[format.get_format_string()] = format
+ # bzr native formats have a network name of their format string.
+ network_format_registry.register(format.get_format_string(), format)
@classmethod
def register_control_format(klass, format):
@@ -1923,6 +1935,9 @@
"""
return False
+ def network_name(self):
+ return self.get_format_string()
+
def _open(self, transport):
"""See BzrDirFormat._open."""
return BzrDir4(transport, self)
@@ -1981,6 +1996,9 @@
result._init_workingtree()
return result
+ def network_name(self):
+ return self.get_format_string()
+
def _open(self, transport):
"""See BzrDirFormat._open."""
return BzrDir5(transport, self)
@@ -2038,6 +2056,9 @@
result._init_workingtree()
return result
+ def network_name(self):
+ return self.get_format_string()
+
def _open(self, transport):
"""See BzrDirFormat._open."""
return BzrDir6(transport, self)
@@ -2125,6 +2146,9 @@
"""See BzrDirFormat.get_format_description()."""
return "Meta directory format 1"
+ def network_name(self):
+ return self.get_format_string()
+
def _open(self, transport):
"""See BzrDirFormat._open."""
return BzrDirMeta1(transport, self)
@@ -2174,6 +2198,15 @@
__set_workingtree_format)
+network_format_registry = registry.FormatRegistry()
+"""Registry of formats indexed by their network name.
+
+The network name for a BzrDirFormat is an identifier that can be used when
+referring to formats with smart server operations. See
+BzrDirFormat.network_name() for more detail.
+"""
+
+
# Register bzr control format
BzrDirFormat.register_control_format(BzrDirFormat)
@@ -2706,12 +2739,22 @@
class RemoteBzrDirFormat(BzrDirMetaFormat1):
"""Format representing bzrdirs accessed via a smart server"""
+ def __init__(self):
+ BzrDirMetaFormat1.__init__(self)
+ self._network_name = None
+
def get_format_description(self):
return 'bzr remote bzrdir'
def get_format_string(self):
raise NotImplementedError(self.get_format_string)
+ def network_name(self):
+ if self._network_name:
+ return self._network_name
+ else:
+ raise AssertionError("No network name set.")
+
@classmethod
def probe_transport(klass, transport):
"""Return a RemoteBzrDirFormat object if it looks possible."""
@@ -2830,7 +2873,7 @@
"""Register a metadir subformat.
These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
- by the Repository format.
+ by the Repository/Branch/WorkingTreeformats.
:param repository_format: The fully-qualified repository format class
name as a string.
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py 2009-03-02 07:13:41 +0000
+++ b/bzrlib/remote.py 2009-03-03 01:06:25 +0000
@@ -112,6 +112,7 @@
raise errors.UnexpectedSmartServerResponse(response)
if response == ('no',):
raise errors.NotBranchError(path=transport.base)
+ self._ensure_real()
def _ensure_real(self):
"""Ensure that there is a _real_bzrdir set.
@@ -121,6 +122,8 @@
if not self._real_bzrdir:
self._real_bzrdir = BzrDir.open_from_transport(
self.root_transport, _server_formats=False)
+ self._format._network_name = \
+ self._real_bzrdir._format.network_name()
def _translate_error(self, err, **context):
_translate_error(err, bzrdir=self, **context)
=== modified file 'bzrlib/tests/bzrdir_implementations/test_bzrdir.py'
--- a/bzrlib/tests/bzrdir_implementations/test_bzrdir.py 2009-03-02 03:38:07 +0000
+++ b/bzrlib/tests/bzrdir_implementations/test_bzrdir.py 2009-03-03 01:06:25 +0000
@@ -1165,6 +1165,26 @@
opened_dir._format)
self.failUnless(isinstance(opened_dir, bzrdir.BzrDir))
+ def test_format_network_name(self):
+ # All control formats must have a network name.
+ dir = self.make_bzrdir('.')
+ format = dir._format
+ network_name = format.network_name()
+ self.assertIsInstance(network_name, str)
+ # We want to test that the network_name matches the actual format on
+ # disk. For local control dirsthat means that using network_name as a
+ # key in the registry gives back the same format. For remote obects
+ # we check that the network_name of the RemoteBzrDirFormat we have
+ # locally matches the actual format present on disk.
+ if isinstance(format, bzrdir.RemoteBzrDirFormat):
+ dir._ensure_real()
+ real_dir = dir._real_bzrdir
+ self.assertEqual(real_dir._format.network_name(), network_name)
+ else:
+ registry = bzrdir.network_format_registry
+ looked_up_format = registry.get(network_name)
+ self.assertEqual(format.__class__, looked_up_format.__class__)
+
def test_open_not_bzrdir(self):
# test the formats specific behaviour for no-content or similar dirs.
self.assertRaises(NotBranchError,
More information about the bazaar-commits
mailing list