Rev 2881: merge 0.91 back to trunk in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Oct 4 00:24:53 BST 2007


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 2881
revision-id: pqm at pqm.ubuntu.com-20071003232450-c831pepea3skddct
parent: pqm at pqm.ubuntu.com-20071003070115-95pox4ok1e47a7v0
parent: mbp at sourcefrog.net-20071003052550-lqew94cmeb1oqfpp
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2007-10-04 00:24:50 +0100
message:
  merge 0.91 back to trunk
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
  bzrlib/tests/test_remote.py    test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
  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: 2878.1.1
    merged: mbp at sourcefrog.net-20071003052550-lqew94cmeb1oqfpp
    parent: pqm at pqm.ubuntu.com-20071003042319-er7zwdzllxy1ywg7
    parent: pqm at pqm.ubuntu.com-20070926015803-j3skrr9dfjf44k1s
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: integration
    timestamp: Wed 2007-10-03 15:25:50 +1000
    message:
      Preparing to merge 0.91 back into trunk
    ------------------------------------------------------------
    revno: 2814.5.5
    merged: pqm at pqm.ubuntu.com-20070926015803-j3skrr9dfjf44k1s
    parent: pqm at pqm.ubuntu.com-20070918030602-nib3bzyt7cyymg8w
    parent: mbp at sourcefrog.net-20070926010457-c2jpnnig4uqb7k69
    committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
    branch nick: 0.91
    timestamp: Wed 2007-09-26 02:58:03 +0100
    message:
      Preparing 0.91 final
        ------------------------------------------------------------
        revno: 2814.5.4.1.5
        merged: mbp at sourcefrog.net-20070926010457-c2jpnnig4uqb7k69
        parent: mbp at sourcefrog.net-20070926010416-urocvnuycqfdwnf4
        parent: bialix at ukr.net-20070913093037-n8bp84n8kcifkvqu
        committer: Martin Pool <mbp at sourcefrog.net>
        branch nick: 0.91-integration
        timestamp: Wed 2007-09-26 11:04:57 +1000
        message:
          separate word (dev/candidate) in version info with dots
        ------------------------------------------------------------
        revno: 2814.5.4.1.4
        merged: mbp at sourcefrog.net-20070926010416-urocvnuycqfdwnf4
        parent: mbp at sourcefrog.net-20070926005413-akcavowkb7k4yi1s
        committer: Martin Pool <mbp at sourcefrog.net>
        branch nick: 0.91-integration
        timestamp: Wed 2007-09-26 11:04:16 +1000
        message:
          Preparing 0.91 final
        ------------------------------------------------------------
        revno: 2814.5.4.1.3
        merged: mbp at sourcefrog.net-20070926005413-akcavowkb7k4yi1s
        parent: mbp at sourcefrog.net-20070926005308-30n4v1t2lejhkjap
        committer: Martin Pool <mbp at sourcefrog.net>
        branch nick: 0.91-integration
        timestamp: Wed 2007-09-26 10:54:13 +1000
        message:
          Update news for recent merges
        ------------------------------------------------------------
        revno: 2814.5.4.1.2
        merged: mbp at sourcefrog.net-20070926005308-30n4v1t2lejhkjap
        parent: mbp at sourcefrog.net-20070926005005-xbsj9nwk6b3jgw48
        parent: andrew.bennetts at canonical.com-20070914025541-xymskacw08apuoq5
        committer: Martin Pool <mbp at sourcefrog.net>
        branch nick: 0.91-integration
        timestamp: Wed 2007-09-26 10:53:08 +1000
        message:
          [MERGE][0.91] Make RemoteRepository.sprout cope gracefully with servers that don't support the 'Repository.tarball' request.
            ------------------------------------------------------------
            revno: 2814.5.2.2.3
            merged: andrew.bennetts at canonical.com-20070914025541-xymskacw08apuoq5
            parent: andrew.bennetts at canonical.com-20070914024300-om8lbs7nag4n44u4
            committer: Andrew Bennetts <andrew.bennetts at canonical.com>
            branch nick: tarball-back-compat-for-0.91
            timestamp: Fri 2007-09-14 12:55:41 +1000
            message:
              Improve the test.
            ------------------------------------------------------------
            revno: 2814.5.2.2.2
            merged: andrew.bennetts at canonical.com-20070914024300-om8lbs7nag4n44u4
            parent: andrew.bennetts at canonical.com-20070914013818-yvv1e53dsc6gagss
            committer: Andrew Bennetts <andrew.bennetts at canonical.com>
            branch nick: tarball-back-compat-for-0.91
            timestamp: Fri 2007-09-14 12:43:00 +1000
            message:
              Make the fallback a little tidier.
            ------------------------------------------------------------
            revno: 2814.5.2.2.1
            merged: andrew.bennetts at canonical.com-20070914013818-yvv1e53dsc6gagss
            parent: pqm at pqm.ubuntu.com-20070912051907-80aaitfew8esgq23
            committer: Andrew Bennetts <andrew.bennetts at canonical.com>
            branch nick: tarball-back-compat-for-0.91
            timestamp: Fri 2007-09-14 11:38:18 +1000
            message:
              Cope gracefully if the server doesn't support the Repository.tarball smart request.
        ------------------------------------------------------------
        revno: 2814.5.4.1.1
        merged: 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
        ------------------------------------------------------------
        revno: 2811.1.5
        merged: 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.
        ------------------------------------------------------------
        revno: 2811.1.4
        merged: 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).
        ------------------------------------------------------------
        revno: 2811.1.3
        merged: 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
        ------------------------------------------------------------
        revno: 2811.1.2
        merged: 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.
        ------------------------------------------------------------
        revno: 2811.1.1
        merged: 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.
    ------------------------------------------------------------
    revno: 2814.5.4
    merged: pqm at pqm.ubuntu.com-20070918030602-nib3bzyt7cyymg8w
    parent: pqm at pqm.ubuntu.com-20070917023258-jf395vu1uxf5tij3
    parent: ian.clatworthy at internode.on.net-20070918021758-wwzbjkj68ycxdbd2
    committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
    branch nick: 0.91
    timestamp: Tue 2007-09-18 04:06:02 +0100
    message:
      Re-apply Aaron's fix for #94975 (Ian Clatworthy)
        ------------------------------------------------------------
        revno: 2814.5.3.1.1
        merged: ian.clatworthy at internode.on.net-20070918021758-wwzbjkj68ycxdbd2
        parent: pqm at pqm.ubuntu.com-20070917023258-jf395vu1uxf5tij3
        committer: Ian Clatworthy <ian.clatworthy at internode.on.net>
        branch nick: integ.0.91
        timestamp: Tue 2007-09-18 12:17:58 +1000
        message:
          Re-apply Aaron's fix for #94975 (Ian Clatworthy)
    ------------------------------------------------------------
    revno: 2814.5.3
    merged: pqm at pqm.ubuntu.com-20070917023258-jf395vu1uxf5tij3
    parent: pqm at pqm.ubuntu.com-20070912051907-80aaitfew8esgq23
    parent: mbp at sourcefrog.net-20070917013450-gcweeqfh3xo1kc5b
    committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
    branch nick: 0.91
    timestamp: Mon 2007-09-17 03:32:58 +0100
    message:
      Merge install-without-compiler fix for 0.91
        ------------------------------------------------------------
        revno: 2814.5.2.1.1
        merged: mbp at sourcefrog.net-20070917013450-gcweeqfh3xo1kc5b
        parent: pqm at pqm.ubuntu.com-20070912051907-80aaitfew8esgq23
        parent: bialix at ukr.net-20070915051300-fyhdnjmmv97uec4u
        committer: Martin Pool <mbp at sourcefrog.net>
        branch nick: 0.91-integration
        timestamp: Mon 2007-09-17 11:34:50 +1000
        message:
          Merge install-without-compiler fix for 0.91
    ------------------------------------------------------------
    revno: 2814.5.2
    merged: pqm at pqm.ubuntu.com-20070912051907-80aaitfew8esgq23
    parent: pqm at pqm.ubuntu.com-20070911091512-e0003oibunapfebj
    parent: robertc at robertcollins.net-20070912031604-lzy05h9u6dyfrfgb
    committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
    branch nick: 0.91
    timestamp: Wed 2007-09-12 06:19:07 +0100
    message:
      (robertc) Fix fetching of revisions referring to nested trees. (Robert Collins)
    ------------------------------------------------------------
    revno: 2814.5.1
    merged: pqm at pqm.ubuntu.com-20070911091512-e0003oibunapfebj
    parent: pqm at pqm.ubuntu.com-20070911055622-a3060rj7l0iy38l2
    parent: mbp at sourcefrog.net-20070911080513-wyvsvi910c2bnht5
    committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
    branch nick: 0.91
    timestamp: Tue 2007-09-11 10:15:12 +0100
    message:
      (mbp) corrected 0.91rc2
    ------------------------------------------------------------
    revno: 2814.6.3
    merged: mbp at sourcefrog.net-20070911080513-wyvsvi910c2bnht5
    parent: mbp at sourcefrog.net-20070911080310-fijxcn71as7upuk7
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: 0.91-integration
    timestamp: Tue 2007-09-11 18:05:13 +1000
    message:
      Update for 0.91rc2
    ------------------------------------------------------------
    revno: 2814.6.2
    merged: mbp at sourcefrog.net-20070911080310-fijxcn71as7upuk7
    parent: mbp at sourcefrog.net-20070911071231-7xqkkj2dumnc1zmi
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: 0.91-integration
    timestamp: Tue 2007-09-11 18:03:10 +1000
    message:
      Revert accidentally-committed pdb insertion in remote.py
    ------------------------------------------------------------
    revno: 2814.6.1
    merged: mbp at sourcefrog.net-20070911071231-7xqkkj2dumnc1zmi
    parent: pqm at pqm.ubuntu.com-20070911055622-a3060rj7l0iy38l2
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: 0.91-release
    timestamp: Tue 2007-09-11 17:12:31 +1000
    message:
      (mbp) release 0.91rc1
=== modified file 'NEWS'
--- a/NEWS	2007-10-03 06:15:06 +0000
+++ b/NEWS	2007-10-03 23:24:50 +0000
@@ -202,12 +202,34 @@
      (Martin Pool)
 
 
+bzr 0.91 2007-09-26
+===================
+
+  BUG FIXES:
+
+   * Print a warning instead of aborting the ``python setup.py install``
+     process if building of a C extension is not possible.
+     (Lukáš Lalinský, Alexander Belchenko)
+
+   * Fix commit ordering in corner case (Aaron Bentley, #94975)
+
+   * 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)
+
+   * Make RemoteRepository.sprout cope gracefully with servers that don't
+     support the ``Repository.tarball`` request.
+     (Andrew Bennetts)
+
+
 bzr 0.91rc2 2007-09-11
 ======================
 
    * Replaced incorrect tarball for previous release; a debug statement was left 
      in bzrlib/remote.py.
 
+
 bzr 0.91rc1 2007-09-11
 ======================
 
@@ -342,9 +364,9 @@
    * 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)
 
    * Print a warning instead of aborting the ``python setup.py install``
      process if building of a C extension is not possible.

=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2007-10-03 03:33:39 +0000
+++ b/bzrlib/remote.py	2007-10-03 05:25:50 +0000
@@ -511,13 +511,14 @@
         return self._real_repository.break_lock()
 
     def _get_tarball(self, compression):
-        """Return a TemporaryFile containing a repository tarball"""
+        """Return a TemporaryFile containing a repository tarball.
+        
+        Returns None if the server does not support sending tarballs.
+        """
         import tempfile
         path = self.bzrdir._path_for_remote_call(self._client)
         response, protocol = self._client.call_expecting_body(
             'Repository.tarball', path, compression)
-        assert response[0] in ('ok', 'failure'), \
-            'unexpected response code %s' % (response,)
         if response[0] == 'ok':
             # Extract the tarball and return it
             t = tempfile.NamedTemporaryFile()
@@ -525,14 +526,23 @@
             t.write(protocol.read_body_bytes())
             t.seek(0)
             return t
-        else:
-            raise errors.SmartServerError(error_code=response)
+        if (response == ('error', "Generic bzr smart protocol error: "
+                "bad request 'Repository.tarball'") or
+              response == ('error', "Generic bzr smart protocol error: "
+                "bad request u'Repository.tarball'")):
+            protocol.cancel_read_body()
+            return None
+        raise errors.UnexpectedSmartServerResponse(response)
 
     def sprout(self, to_bzrdir, revision_id=None):
         # TODO: Option to control what format is created?
-        to_repo = to_bzrdir.create_repository()
-        self._copy_repository_tarball(to_repo, revision_id)
-        return to_repo
+        to_repo = self._copy_repository_tarball(to_bzrdir, revision_id)
+        if to_repo is None:
+            self._ensure_real()
+            return self._real_repository.sprout(
+                to_bzrdir, revision_id=revision_id)
+        else:
+            return to_repo
 
     ### These methods are just thin shims to the VFS object for now.
 
@@ -688,7 +698,7 @@
         return self._real_repository.copy_content_into(
             destination, revision_id=revision_id)
 
-    def _copy_repository_tarball(self, destination, revision_id=None):
+    def _copy_repository_tarball(self, to_bzrdir, revision_id=None):
         # get a tarball of the remote repository, and copy from that into the
         # destination
         from bzrlib import osutils
@@ -698,6 +708,9 @@
         # TODO: Maybe a progress bar while streaming the tarball?
         note("Copying repository content as tarball...")
         tar_file = self._get_tarball('bz2')
+        if tar_file is None:
+            return None
+        destination = to_bzrdir.create_repository()
         try:
             tar = tarfile.open('repository', fileobj=tar_file,
                 mode='r|bz2')
@@ -711,9 +724,7 @@
                 osutils.rmtree(tmpdir)
         finally:
             tar_file.close()
-        # TODO: if the server doesn't support this operation, maybe do it the
-        # slow way using the _real_repository?
-        #
+        return destination
         # TODO: Suggestion from john: using external tar is much faster than
         # python's tarfile library, but it may not work on windows.
 

=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py	2007-07-19 06:34:09 +0000
+++ b/bzrlib/tests/test_remote.py	2007-09-14 02:55:41 +0000
@@ -106,11 +106,18 @@
 class FakeProtocol(object):
     """Lookalike SmartClientRequestProtocolOne allowing body reading tests."""
 
-    def __init__(self, body):
+    def __init__(self, body, fake_client):
         self._body_buffer = StringIO(body)
+        self._fake_client = fake_client
 
     def read_body_bytes(self, count=-1):
-        return self._body_buffer.read(count)
+        bytes = self._body_buffer.read(count)
+        if self._body_buffer.tell() == len(self._body_buffer.getvalue()):
+            self._fake_client.expecting_body = False
+        return bytes
+
+    def cancel_read_body(self):
+        self._fake_client.expecting_body = False
 
 
 class FakeClient(_SmartClient):
@@ -118,13 +125,14 @@
     
     def __init__(self, responses):
         # We don't call the super init because there is no medium.
-        """create a FakeClient.
+        """Create a FakeClient.
 
         :param respones: A list of response-tuple, body-data pairs to be sent
             back to callers.
         """
         self.responses = responses
         self._calls = []
+        self.expecting_body = False
 
     def call(self, method, *args):
         self._calls.append(('call', method, args))
@@ -133,7 +141,8 @@
     def call_expecting_body(self, method, *args):
         self._calls.append(('call_expecting_body', method, args))
         result = self.responses.pop(0)
-        return result[0], FakeProtocol(result[1])
+        self.expecting_body = True
+        return result[0], FakeProtocol(result[1], self)
 
 
 class TestBzrDirOpenBranch(tests.TestCase):
@@ -751,6 +760,49 @@
         # try to copy...
         remote_repo.sprout(dest_bzrdir)
 
+    def test_backwards_compatibility(self):
+        """If the server doesn't recognise this request, fallback to VFS.
+        
+        This happens when a current client talks to an older server that
+        doesn't implement 'Repository.tarball'.
+        """
+        # Make a regular local repository to receive the results
+        dest_transport = MemoryTransport()
+        dest_transport.mkdir('destrepo')
+        bzrdir_format = bzrdir.format_registry.make_bzrdir('default')
+        dest_bzrdir = bzrdir_format.initialize_on_transport(dest_transport)
+
+        error_msg = (
+            "Generic bzr smart protocol error: "
+            "bad request 'Repository.tarball'")
+        responses = [(('error', error_msg), '')]
+        remote_repo, client = self.setup_fake_client_and_repository(
+            responses, 'path')
+        mock_real_repo = MockRealRepository()
+        remote_repo._real_repository = mock_real_repo
+
+        # try to copy...
+        remote_repo.sprout(dest_bzrdir)
+
+        self.assertEqual([('sprout', dest_bzrdir, None)], mock_real_repo.calls,
+            "RemoteRepository didn't fallback to the real repository correctly")
+        self.failIf(client.expecting_body,
+            "The protocol has been left in an unclean state that will cause "
+            "TooManyConcurrentRequests errors.")
+
+
+class MockRealRepository(object):
+    """Mock of a RemoteRepository's '_real_repository' attribute.
+    
+    Used by TestRepositoryTarball.test_backwards_compatibility.
+    """
+
+    def __init__(self):
+        self.calls = []
+
+    def sprout(self, to_bzrdir, revision_id=None):
+        self.calls.append(('sprout', to_bzrdir, revision_id))
+
 
 class TestRemoteRepositoryCopyContent(tests.TestCaseWithTransport):
     """RemoteRepository.copy_content_into optimizations"""

=== modified file 'bzrlib/tests/test_transport.py'
--- a/bzrlib/tests/test_transport.py	2007-09-21 12:30:48 +0000
+++ b/bzrlib/tests/test_transport.py	2007-10-03 05:25:50 +0000
@@ -55,6 +55,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.
@@ -618,7 +622,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)
@@ -713,6 +717,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-10-03 03:14:53 +0000
+++ b/bzrlib/transport/__init__.py	2007-10-03 05:25:50 +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):
@@ -1256,6 +1263,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
@@ -1286,7 +1297,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))
@@ -1626,34 +1640,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',
@@ -1662,10 +1679,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://')
@@ -1692,14 +1711,15 @@
                         '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')
@@ -1710,7 +1730,8 @@
                         '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-10-03 03:14:53 +0000
+++ b/bzrlib/transport/remote.py	2007-10-03 05:25:50 +0000
@@ -451,8 +451,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