Rev 2819: [MERGE][0.91][Bug 133965] PathNotChild, port mismatch with "bzr info" for bzr:// smartserver in http://sourcefrog.net/bzr/0.91-integration

Martin Pool mbp at sourcefrog.net
Wed Sep 26 01:50:07 BST 2007


At http://sourcefrog.net/bzr/0.91-integration

------------------------------------------------------------
revno: 2819
revision-id: mbp at sourcefrog.net-20070926005005-xbsj9nwk6b3jgw48
parent: pqm at pqm.ubuntu.com-20070918030602-nib3bzyt7cyymg8w
parent: andrew.bennetts at canonical.com-20070912021105-0n78a0y6qe37efwy
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: 0.91-integration
timestamp: Wed 2007-09-26 10:50:05 +1000
message:
  [MERGE][0.91][Bug 133965] PathNotChild, port mismatch with "bzr info" for bzr:// smartserver
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/tests/test_transport.py testtransport.py-20050718175618-e5cdb99f4555ddce
  bzrlib/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
  bzrlib/transport/remote.py     ssh.py-20060608202016-c25gvf1ob7ypbus6-1
    ------------------------------------------------------------
    revno: 2811.1.5
    revision-id: andrew.bennetts at canonical.com-20070912021105-0n78a0y6qe37efwy
    parent: andrew.bennetts at canonical.com-20070912020523-nb33chg5t3fjefxq
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: port-mismatch-bug-133965
    timestamp: Wed 2007-09-12 12:11:05 +1000
    message:
      Tidy up unwanted change to NEWS.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 2811.1.4
    revision-id: andrew.bennetts at canonical.com-20070912020523-nb33chg5t3fjefxq
    parent: andrew.bennetts at canonical.com-20070912020400-c2wtzni2upwf8bb9
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: port-mismatch-bug-133965
    timestamp: Wed 2007-09-12 12:05:23 +1000
    message:
      Set default_port for all registered protocols (if appropriate).
    modified:
      bzrlib/tests/test_transport.py testtransport.py-20050718175618-e5cdb99f4555ddce
      bzrlib/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
    ------------------------------------------------------------
    revno: 2811.1.3
    revision-id: andrew.bennetts at canonical.com-20070912020400-c2wtzni2upwf8bb9
    parent: andrew.bennetts at canonical.com-20070911034640-do3wxbvugv32fliv
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: port-mismatch-bug-133965
    timestamp: Wed 2007-09-12 12:04:00 +1000
    message:
      Move new NEWS entry to more appropriate location
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 2811.1.2
    revision-id: andrew.bennetts at canonical.com-20070911034640-do3wxbvugv32fliv
    parent: andrew.bennetts at canonical.com-20070911022326-9ywi7t9nuga6ou3p
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: port-mismatch-bug-133965
    timestamp: Tue 2007-09-11 13:46:40 +1000
    message:
      Use the 'info' part of the transport_list_registry to track default ports rather than a separate dict.
    modified:
      bzrlib/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
    ------------------------------------------------------------
    revno: 2811.1.1
    revision-id: andrew.bennetts at canonical.com-20070911022326-9ywi7t9nuga6ou3p
    parent: pqm at pqm.ubuntu.com-20070911010353-6lu7ek40rbjhj86o
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: port-mismatch-bug-133965
    timestamp: Tue 2007-09-11 12:23:26 +1000
    message:
      Cherrypick fix proposed for 0.90.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/tests/test_transport.py testtransport.py-20050718175618-e5cdb99f4555ddce
      bzrlib/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
      bzrlib/transport/remote.py     ssh.py-20060608202016-c25gvf1ob7ypbus6-1
=== modified file 'NEWS'
--- a/NEWS	2007-09-18 02:17:58 +0000
+++ b/NEWS	2007-09-26 00:50:05 +0000
@@ -155,9 +155,14 @@
    * Overwrite conflicting tags by ``push`` and ``pull`` if the
      ``--overwrite`` option is specified.  (Lukáš Lalinský, #93947)
 
-    * In checkouts, tags are copied into the master branch when created,
-      changed or deleted, and are copied into the checkout when it is 
-      updated.  (Martin Pool, #93856, #93860)
+   * In checkouts, tags are copied into the master branch when created,
+     changed or deleted, and are copied into the checkout when it is 
+     updated.  (Martin Pool, #93856, #93860)
+
+   * Fix ''bzr info bzr://host/'' and other operations on ''bzr://' URLs with
+     an implicit port.  We were incorrectly raising PathNotChild due to
+     inconsistent treatment of the ''_port'' attribute on the Transport object.
+     (Andrew Bennetts, #133965)
 
   IMPROVEMENTS:
 

=== modified file 'bzrlib/tests/test_transport.py'
--- a/bzrlib/tests/test_transport.py	2007-08-19 20:38:10 +0000
+++ b/bzrlib/tests/test_transport.py	2007-09-12 02:05:23 +0000
@@ -54,6 +54,10 @@
 from bzrlib.transport.memory import MemoryTransport
 from bzrlib.transport.local import (LocalTransport,
                                     EmulatedWin32LocalTransport)
+from bzrlib.transport.remote import (
+    BZR_DEFAULT_PORT,
+    RemoteTCPTransport
+    )
 
 
 # TODO: Should possibly split transport-specific tests into their own files.
@@ -617,7 +621,7 @@
     def test_parse_url(self):
         t = ConnectedTransport('sftp://simple.example.com/home/source')
         self.assertEquals(t._host, 'simple.example.com')
-        self.assertEquals(t._port, None)
+        self.assertEquals(t._port, 22)
         self.assertEquals(t._path, '/home/source/')
         self.failUnless(t._user is None)
         self.failUnless(t._password is None)
@@ -712,6 +716,50 @@
         self.assertIsNot(t1, t2)
 
 
+class TestRemoteTCPTransport(TestCase):
+    """Tests for bzr:// transport (RemoteTCPTransport)."""
+
+    def test_relpath_with_implicit_port(self):
+        """Connected transports with the same URL are the same, even if the
+        port is implicit.
+
+        So t.relpath(url) should always be '' if t.base is the same as url, or
+        if the only difference is that one explicitly specifies the default
+        port and the other doesn't specify a port.
+        """
+        t_implicit_port = RemoteTCPTransport('bzr://host.com/')
+        self.assertEquals('', t_implicit_port.relpath('bzr://host.com/'))
+        self.assertEquals('', t_implicit_port.relpath('bzr://host.com:4155/'))
+        t_explicit_port = RemoteTCPTransport('bzr://host.com:4155/')
+        self.assertEquals('', t_explicit_port.relpath('bzr://host.com/'))
+        self.assertEquals('', t_explicit_port.relpath('bzr://host.com:4155/'))
+
+    def test_construct_uses_default_port(self):
+        """If no port is specified, then RemoteTCPTransport uses
+        BZR_DEFAULT_PORT.
+        """
+        t = get_transport('bzr://host.com/')
+        self.assertEquals(BZR_DEFAULT_PORT, t._port)
+
+    def test_url_omits_default_port(self):
+        """If a RemoteTCPTransport uses the default port, then its base URL
+        will omit the port.
+
+        This is like how ":80" is omitted from "http://example.com/".
+        """
+        t = get_transport('bzr://host.com:4155/')
+        self.assertEquals('bzr://host.com/', t.base)
+
+    def test_url_includes_non_default_port(self):
+        """Non-default ports are included in the transport's URL.
+
+        Contrast this to `test_url_omits_default_port`.
+        """
+        t = get_transport('bzr://host.com:666/')
+        self.assertEquals('bzr://host.com:666/', t.base)
+
+
+
 def get_test_permutations():
     """Return transport permutations to be used in testing.
 

=== modified file 'bzrlib/transport/__init__.py'
--- a/bzrlib/transport/__init__.py	2007-09-10 09:27:54 +0000
+++ b/bzrlib/transport/__init__.py	2007-09-12 02:05:23 +0000
@@ -128,19 +128,26 @@
         self.get(key).insert(0, 
                 registry._LazyObjectGetter(module_name, member_name))
 
-    def register_transport(self, key, help=None, info=None):
-        self.register(key, [], help, info)
+    def register_transport(self, key, help=None, default_port=None):
+        self.register(key, [], help, default_port)
 
     def set_default_transport(self, key=None):
         """Return either 'key' or the default key if key is None"""
         self._default_key = key
 
+    def get_default_port(self, scheme):
+        """Return the registered default port for this protocol scheme."""
+        try:
+            return self.get_info(scheme + '://')
+        except LookupError:
+            return None
+
 
 transport_list_registry = TransportListRegistry( )
 
 
-def register_transport_proto(prefix, help=None, info=None):
-    transport_list_registry.register_transport(prefix, help, info)
+def register_transport_proto(prefix, help=None, info=None, default_port=None):
+    transport_list_registry.register_transport(prefix, help, default_port)
 
 
 def register_lazy_transport(prefix, module, classname):
@@ -1255,6 +1262,10 @@
         host = urllib.unquote(host)
         path = urllib.unquote(path)
 
+        if port is None:
+            # The port isn't explicitly specified, so return the default (if
+            # there is one).
+            port = transport_list_registry.get_default_port(scheme)
         return (scheme, user, password, host, port, path)
 
     @staticmethod
@@ -1285,7 +1296,10 @@
             # have one so that it doesn't get accidentally
             # exposed.
             netloc = '%s@%s' % (urllib.quote(user), netloc)
-        if port is not None:
+        if (port is not None and 
+            port != transport_list_registry.get_default_port(scheme)):
+            # Include the port in the netloc (unless it's the same as the
+            # default, in which case we omit it as it is redundant).
             netloc = '%s:%d' % (netloc, port)
         path = urllib.quote(path)
         return urlparse.urlunparse((scheme, netloc, path, None, None, None))
@@ -1625,34 +1639,37 @@
 transport_list_registry.set_default_transport("file://")
 
 register_transport_proto('sftp://',
-            help="Access using SFTP (most SSH servers provide SFTP).")
+            help="Access using SFTP (most SSH servers provide SFTP).",
+            default_port=22)
 register_lazy_transport('sftp://', 'bzrlib.transport.sftp', 'SFTPTransport')
 # Decorated http transport
 register_transport_proto('http+urllib://',
 #                help="Read-only access of branches exported on the web."
-            )
+            default_port=80)
 register_lazy_transport('http+urllib://', 'bzrlib.transport.http._urllib',
                         'HttpTransport_urllib')
 register_transport_proto('https+urllib://',
 #                help="Read-only access of branches exported on the web using SSL."
-            )
+            default_port=443)
 register_lazy_transport('https+urllib://', 'bzrlib.transport.http._urllib',
                         'HttpTransport_urllib')
 register_transport_proto('http+pycurl://',
 #                help="Read-only access of branches exported on the web."
-            )
+            default_port=80)
 register_lazy_transport('http+pycurl://', 'bzrlib.transport.http._pycurl',
                         'PyCurlTransport')
 register_transport_proto('https+pycurl://',
 #                help="Read-only access of branches exported on the web using SSL."
-            )
+            default_port=443)
 register_lazy_transport('https+pycurl://', 'bzrlib.transport.http._pycurl',
                         'PyCurlTransport')
 # Default http transports (last declared wins (if it can be imported))
 register_transport_proto('http://',
-            help="Read-only access of branches exported on the web.")
+            help="Read-only access of branches exported on the web.",
+            default_port=80)
 register_transport_proto('https://',
-            help="Read-only access of branches exported on the web using SSL.")
+            help="Read-only access of branches exported on the web using SSL.",
+            default_port=443)
 register_lazy_transport('http://', 'bzrlib.transport.http._urllib',
                         'HttpTransport_urllib')
 register_lazy_transport('https://', 'bzrlib.transport.http._urllib',
@@ -1661,10 +1678,12 @@
 register_lazy_transport('https://', 'bzrlib.transport.http._pycurl', 'PyCurlTransport')
 
 register_transport_proto('ftp://',
-            help="Access using passive FTP.")
+            help="Access using passive FTP.",
+            default_port=21)
 register_lazy_transport('ftp://', 'bzrlib.transport.ftp', 'FtpTransport')
 register_transport_proto('aftp://',
-            help="Access using active FTP.")
+            help="Access using active FTP.",
+            default_port=21)
 register_lazy_transport('aftp://', 'bzrlib.transport.ftp', 'FtpTransport')
 
 register_transport_proto('memory://')
@@ -1691,19 +1710,21 @@
                         'bzrlib.transport.fakevfat',
                         'FakeVFATTransportDecorator')
 register_transport_proto('bzr://',
-            help="Fast access using the Bazaar smart server.")
+            help="Fast access using the Bazaar smart server.",
+            default_port=4155)
 
 register_lazy_transport('bzr://',
                         'bzrlib.transport.remote',
                         'RemoteTCPTransport')
 register_transport_proto('bzr+http://',
 #                help="Fast access using the Bazaar smart server over HTTP."
-             )
+            default_port=80)
 register_lazy_transport('bzr+http://',
                         'bzrlib.transport.remote',
                         'RemoteHTTPTransport')
 register_transport_proto('bzr+ssh://',
-            help="Fast access using the Bazaar smart server over SSH.")
+            help="Fast access using the Bazaar smart server over SSH.",
+            default_port=22)
 register_lazy_transport('bzr+ssh://',
                         'bzrlib.transport.remote',
                         'RemoteSSHTransport')

=== modified file 'bzrlib/transport/remote.py'
--- a/bzrlib/transport/remote.py	2007-08-15 06:53:07 +0000
+++ b/bzrlib/transport/remote.py	2007-09-11 02:23:26 +0000
@@ -450,8 +450,6 @@
 
     def _build_medium(self):
         assert self.base.startswith('bzr://')
-        if self._port is None:
-            self._port = BZR_DEFAULT_PORT
         return medium.SmartTCPClientMedium(self._host, self._port), None
 
 




More information about the bazaar-commits mailing list