Rev 4292: Remove the explicit set_parent method on RemoteBranch in favour of inheriting from Branch. in http://people.ubuntu.com/~robertc/baz2.0/pending/push.roundtrips

Robert Collins robertc at robertcollins.net
Tue Apr 14 08:11:11 BST 2009


At http://people.ubuntu.com/~robertc/baz2.0/pending/push.roundtrips

------------------------------------------------------------
revno: 4292
revision-id: robertc at robertcollins.net-20090414071101-kmlsxria9ok4ldx5
parent: robertc at robertcollins.net-20090414065058-ca0aptbxp6zzkzat
committer: Robert Collins <robertc at robertcollins.net>
branch nick: push.roundtrips
timestamp: Tue 2009-04-14 17:11:01 +1000
message:
  Remove the explicit set_parent method on RemoteBranch in favour of inheriting from Branch.
=== modified file 'NEWS'
--- a/NEWS	2009-04-14 04:33:41 +0000
+++ b/NEWS	2009-04-14 07:11:01 +0000
@@ -50,6 +50,10 @@
 Internals
 *********
 
+* ``bzrlib.branch.Branch.set_parent`` is now present on the base branch
+  class and will call ``_set_parent_location`` after doing unicode 
+  encoding. (Robert Collins)
+
 * ``bzrlib.bzrdir.BzrDir._get_config`` now returns a ``TransportConfig``
   or similar when the dir supports configuration settings. The base class
   defaults to None. There is a matching new server verb

=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2009-04-04 02:50:01 +0000
+++ b/bzrlib/branch.py	2009-04-14 07:11:01 +0000
@@ -590,6 +590,24 @@
     def set_revision_history(self, rev_history):
         raise NotImplementedError(self.set_revision_history)
 
+    @needs_write_lock
+    def set_parent(self, url):
+        """See Branch.set_parent."""
+        # TODO: Maybe delete old location files?
+        # URLs should never be unicode, even on the local fs,
+        # FIXUP this and get_parent in a future branch format bump:
+        # read and rewrite the file. RBC 20060125
+        if url is not None:
+            if isinstance(url, unicode):
+                try:
+                    url = url.encode('ascii')
+                except UnicodeEncodeError:
+                    raise errors.InvalidURL(url,
+                        "Urls must be 7-bit ascii, "
+                        "use bzrlib.urlutils.escape")
+            url = urlutils.relative_url(self.base, url)
+        self._set_parent_location(url)
+
     def set_stacked_on_url(self, url):
         """Set the URL this branch is stacked against.
 
@@ -944,9 +962,6 @@
                 raise errors.HookFailed(
                     'pre_change_branch_tip', hook_name, exc_info)
 
-    def set_parent(self, url):
-        raise NotImplementedError(self.set_parent)
-
     @needs_write_lock
     def update(self):
         """Synchronise this branch with the master branch if any.
@@ -2194,24 +2209,6 @@
             'push_location', location,
             store=_mod_config.STORE_LOCATION_NORECURSE)
 
-    @needs_write_lock
-    def set_parent(self, url):
-        """See Branch.set_parent."""
-        # TODO: Maybe delete old location files?
-        # URLs should never be unicode, even on the local fs,
-        # FIXUP this and get_parent in a future branch format bump:
-        # read and rewrite the file. RBC 20060125
-        if url is not None:
-            if isinstance(url, unicode):
-                try:
-                    url = url.encode('ascii')
-                except UnicodeEncodeError:
-                    raise errors.InvalidURL(url,
-                        "Urls must be 7-bit ascii, "
-                        "use bzrlib.urlutils.escape")
-            url = urlutils.relative_url(self.base, url)
-        self._set_parent_location(url)
-
     def _set_parent_location(self, url):
         if url is None:
             self._transport.delete('parent')

=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2009-04-14 04:33:41 +0000
+++ b/bzrlib/remote.py	2009-04-14 07:11:01 +0000
@@ -2300,17 +2300,9 @@
         self._ensure_real()
         return self._real_branch._get_parent_location()
 
-    def set_parent(self, url):
-        self._ensure_real()
-        return self._real_branch.set_parent(url)
-
     def _set_parent_location(self, url):
-        # Used by tests, to poke bad urls into branch configurations
-        if url is None:
-            self.set_parent(url)
-        else:
-            self._ensure_real()
-            return self._real_branch._set_parent_location(url)
+        self._ensure_real()
+        return self._real_branch._set_parent_location(url)
 
     @needs_write_lock
     def pull(self, source, overwrite=False, stop_revision=None,
@@ -2415,7 +2407,7 @@
 
     def _response_to_configobj(self, response):
         if len(response[0]) and response[0][0] != 'ok':
-            raise UnexpectedSmartServerResponse(response)
+            raise errors.UnexpectedSmartServerResponse(response)
         lines = response[1].read_body_bytes().splitlines()
         return config.ConfigObj(lines, encoding='utf-8')
 
@@ -2469,9 +2461,13 @@
         self._bzrdir = bzrdir
 
     def _get_configobj(self):
+        medium = self._bzrdir._client._medium
+        verb = 'BzrDir.get_config_file'
+        if medium._is_remote_before((1, 15)):
+            raise errors.UnknownSmartMethod(verb)
         path = self._bzrdir._path_for_remote_call(self._bzrdir._client)
         response = self._bzrdir._call_expecting_body(
-            'BzrDir.get_config_file', path)
+            verb, path)
         return self._response_to_configobj(response)
 
     def _vfs_get_option(self, name, section, default):

=== modified file 'bzrlib/tests/blackbox/test_branch.py'
--- a/bzrlib/tests/blackbox/test_branch.py	2009-04-14 04:33:41 +0000
+++ b/bzrlib/tests/blackbox/test_branch.py	2009-04-14 07:11:01 +0000
@@ -272,7 +272,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(53, self.hpss_calls)
+        self.assertLength(47, self.hpss_calls)
 
     def test_branch_from_trivial_branch_streaming_acceptance(self):
         self.setup_smart_server_with_call_log()

=== modified file 'bzrlib/tests/blackbox/test_push.py'
--- a/bzrlib/tests/blackbox/test_push.py	2009-04-14 04:33:41 +0000
+++ b/bzrlib/tests/blackbox/test_push.py	2009-04-14 07:11:01 +0000
@@ -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(42, self.hpss_calls)
+        self.assertLength(36, self.hpss_calls)
         remote = Branch.open('public')
         self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
 




More information about the bazaar-commits mailing list