Rev 3502: Better infrastructure for tracking remote server version in in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Jun 18 04:28:36 BST 2008


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

------------------------------------------------------------
revno: 3502
revision-id:pqm at pqm.ubuntu.com-20080618032827-fq9wj33m0wfpurzv
parent: pqm at pqm.ubuntu.com-20080618021553-nptumo40ezmv5ksr
parent: andrew.bennetts at canonical.com-20080617043218-gm8jc3cdk0lgjcfv
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2008-06-18 04:28:27 +0100
message:
  Better infrastructure for tracking remote server version in
  	SmartClientMedium. (Andrew Bennetts)
modified:
  bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
  bzrlib/smart/client.py         client.py-20061116014825-2k6ada6xgulslami-1
  bzrlib/smart/medium.py         medium.py-20061103051856-rgu2huy59fkz902q-1
  bzrlib/tests/test_remote.py    test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
  bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
  bzrlib/transport/http/_urllib.py _urlgrabber.py-20060113083826-0bbf7d992fbf090c
    ------------------------------------------------------------
    revno: 3453.4.10
    revision-id:andrew.bennetts at canonical.com-20080617043218-gm8jc3cdk0lgjcfv
    parent: andrew.bennetts at canonical.com-20080617042226-8kog0j96nztjgoa4
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: remote-is-at-least
    timestamp: Tue 2008-06-17 14:32:18 +1000
    message:
      Change _is_remote_at_least to _is_remote_before.
    modified:
      bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
      bzrlib/smart/medium.py         medium.py-20061103051856-rgu2huy59fkz902q-1
      bzrlib/tests/test_remote.py    test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
      bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
    ------------------------------------------------------------
    revno: 3453.4.9
    revision-id:andrew.bennetts at canonical.com-20080617042226-8kog0j96nztjgoa4
    parent: andrew.bennetts at canonical.com-20080615234528-4co0hcs5tear0pva
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: remote-is-at-least
    timestamp: Tue 2008-06-17 14:22:26 +1000
    message:
      Rename _remote_is_not to _remember_remote_is_before.
    modified:
      bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
      bzrlib/smart/client.py         client.py-20061116014825-2k6ada6xgulslami-1
      bzrlib/smart/medium.py         medium.py-20061103051856-rgu2huy59fkz902q-1
      bzrlib/tests/test_remote.py    test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
    ------------------------------------------------------------
    revno: 3453.4.8
    revision-id:andrew.bennetts at canonical.com-20080615234528-4co0hcs5tear0pva
    parent: andrew.bennetts at canonical.com-20080611235921-5j77i6gne7sh8x3s
    parent: pqm at pqm.ubuntu.com-20080612170229-8h3mrl35jgqhs0gt
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: remote-is-at-least
    timestamp: Mon 2008-06-16 09:45:28 +1000
    message:
      Merge from bzr.dev.
    modified:
      bzrlib/xml_serializer.py       xml.py-20050309040759-57d51586fdec365d
    ------------------------------------------------------------
    revno: 3453.4.7
    revision-id:andrew.bennetts at canonical.com-20080611235921-5j77i6gne7sh8x3s
    parent: andrew.bennetts at canonical.com-20080610073759-ewmdzkasnyz6gagl
    parent: pqm at pqm.ubuntu.com-20080611120348-tqhq37qvfz624jyb
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: remote-is-at-least
    timestamp: Thu 2008-06-12 09:59:21 +1000
    message:
      Merge from bzr.dev.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/__init__.py             __init__.py-20050309040759-33e65acf91bbcd5d
      bzrlib/diff.py                 diff.py-20050309040759-26944fbbf2ebbf36
      bzrlib/export/tar_exporter.py  tar_exporter.py-20051114235828-1f6349a2f090a5d0
      bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
      bzrlib/smart/protocol.py       protocol.py-20061108035435-ot0lstk2590yqhzr-1
      bzrlib/tests/blackbox/test_export.py test_export.py-20051229024010-e6c26658e460fb1c
      bzrlib/tests/test_diff.py      testdiff.py-20050727164403-d1a3496ebb12e339
      bzrlib/tests/test_osutils.py   test_osutils.py-20051201224856-e48ee24c12182989
      bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
      doc/developers/HACKING.txt     HACKING-20050805200004-2a5dc975d870f78c
      doc/developers/index.txt       index.txt-20070508041241-qznziunkg0nffhiw-1
      doc/developers/releasing.txt   releasing.txt-20080502015919-fnrcav8fwy8ccibu-1
      doc/index.txt                  index.txt-20070813101924-07gd9i9d2jt124bf-1
    ------------------------------------------------------------
    revno: 3453.4.6
    revision-id:andrew.bennetts at canonical.com-20080610073759-ewmdzkasnyz6gagl
    parent: andrew.bennetts at canonical.com-20080605230057-raqbjdzpzvu4emf8
    parent: pqm at pqm.ubuntu.com-20080609211646-amc2rr2zi50omr8m
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: remote-is-at-least
    timestamp: Tue 2008-06-10 17:37:59 +1000
    message:
      Merge from bzr.dev.
    added:
      bzrlib/tests/blackbox/test_alias.py test_alias.py-20080425112253-fbt0yz1c1834jriz-1
      bzrlib/tests/blackbox/test_modified.py test_modified.py-20080424085848-nwqjenan4dq2vq3w-1
      bzrlib/tests/per_repository_reference/ repository_external_-20080220025549-nnm2s80it1lvcwnc-1
      bzrlib/tests/per_repository_reference/__init__.py __init__.py-20080220025549-nnm2s80it1lvcwnc-2
      bzrlib/tests/per_repository_reference/test_add_inventory.py test_add_inventory.p-20080220025549-nnm2s80it1lvcwnc-3
      bzrlib/tests/per_repository_reference/test_add_revision.py test_add_revision.py-20080220034108-ao1u8qgakqbo5a08-1
      bzrlib/tests/per_repository_reference/test_add_signature_text.py test_add_signature_t-20080220041905-1j2g4lyz3c6h34v4-1
      bzrlib/tests/per_repository_reference/test_all_revision_ids.py test_all_revision_id-20080220041905-1j2g4lyz3c6h34v4-2
      bzrlib/tests/per_repository_reference/test_break_lock.py test_break_lock.py-20080220042825-1f48qmpnuqqp5wg2-1
      bzrlib/tests/per_repository_reference/test_check.py test_check.py-20080220044229-sxxe747gzi6q8fyv-1
    renamed:
      doc/en/user-guide/revnos.txt => doc/en/user-guide/zen.txt revnos.txt-20080111231928-pbntxea0ynh9ww1t-1
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/check.py                check.py-20050309040759-f3a679400c06bcc1
      bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
      bzrlib/counted_lock.py         counted_lock.py-20070502135927-7dk86io3ok7ctx6k-1
      bzrlib/dirstate.py             dirstate.py-20060728012006-d6mvoihjb3je9peu-1
      bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
      bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
      bzrlib/merge_directive.py      merge_directive.py-20070228184838-ja62280spt1g7f4x-1
      bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
      bzrlib/tag.py                  tag.py-20070212110532-91cw79inah2cfozx-1
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
      bzrlib/tests/blackbox/__init__.py __init__.py-20051128053524-eba30d8255e08dc3
      bzrlib/tests/blackbox/test_added.py test_added.py-20060119085008-6b8b90369d42a26c
      bzrlib/tests/blackbox/test_non_ascii.py test_non_ascii.py-20060105214030-68010be784a5d854
      bzrlib/tests/blackbox/test_unknowns.py test_unknowns.py-20070905015344-74tg6s1synijo2oe-1
      bzrlib/tests/branch_implementations/test_pull.py test_pull.py-20060410103942-83c35b26657414fc
      bzrlib/tests/http_server.py    httpserver.py-20061012142527-m1yxdj1xazsf8d7s-1
      bzrlib/tests/repository_implementations/__init__.py __init__.py-20060131092037-9564957a7d4a841b
      bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
      bzrlib/tests/test_counted_lock.py test_counted_lock.py-20070502135927-7dk86io3ok7ctx6k-2
      bzrlib/tests/test_diff.py      testdiff.py-20050727164403-d1a3496ebb12e339
      bzrlib/tests/test_dirstate.py  test_dirstate.py-20060728012006-d6mvoihjb3je9peu-2
      bzrlib/tests/test_lockable_files.py test_lockable_files.py-20051225183927-365c7fd99591caf1
      bzrlib/tests/test_merge_directive.py test_merge_directive-20070228184838-ja62280spt1g7f4x-2
      bzrlib/tests/test_msgeditor.py test_msgeditor.py-20051202041359-920315ec6011ee51
      bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
      bzrlib/tests/test_transform.py test_transaction.py-20060105172520-b3ffb3946550e6c4
      bzrlib/tests/test_transport_implementations.py test_transport_implementations.py-20051227111451-f97c5c7d5c49fce7
      bzrlib/tests/test_versionedfile.py test_versionedfile.py-20060222045249-db45c9ed14a1c2e5
      bzrlib/transform.py            transform.py-20060105172343-dd99e54394d91687
      bzrlib/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
      bzrlib/versionedfile.py        versionedfile.py-20060222045106-5039c71ee3b65490
      bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
      contrib/bzr_access             bzr_access-20071210163004-c9lb1renhra2ncg0-1
      doc/en/user-guide/core_concepts.txt core_concepts.txt-20071114035000-q36a9h57ps06uvnl-2
      doc/en/user-guide/index.txt    index.txt-20060622101119-tgwtdci8z769bjb9-2
      doc/en/user-guide/zen.txt      revnos.txt-20080111231928-pbntxea0ynh9ww1t-1
    ------------------------------------------------------------
    revno: 3453.4.5
    revision-id:andrew.bennetts at canonical.com-20080605230057-raqbjdzpzvu4emf8
    parent: andrew.bennetts at canonical.com-20080603224305-qmk0zbwc8kieqlbm
    parent: pqm at pqm.ubuntu.com-20080604222149-sq8txbpiit3ckogx
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: remote-is-at-least
    timestamp: Fri 2008-06-06 09:00:57 +1000
    message:
      Merge from bzr.dev.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/__init__.py             __init__.py-20050309040759-33e65acf91bbcd5d
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/lockdir.py              lockdir.py-20060220222025-98258adf27fbdda3
      bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
      bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
      bzrlib/tests/blackbox/test_uncommit.py test_uncommit.py-20051027212835-84944b63adae51be
      bzrlib/tests/branch_implementations/test_branch.py testbranch.py-20050711070244-121d632bc37d7253
      bzrlib/tests/test_branch.py    test_branch.py-20060116013032-97819aa07b8ab3b5
      bzrlib/tests/test_lockdir.py   test_lockdir.py-20060220222025-33d4221569a3d600
      bzrlib/tests/test_switch.py    test_switch.py-20071116011000-v5lnw7d2wkng9eux-2
      bzrlib/tests/test_transport_implementations.py test_transport_implementations.py-20051227111451-f97c5c7d5c49fce7
      bzrlib/tests/test_workingtree_4.py test_workingtree_4.p-20070223025758-531n3tznl3zacv2o-1
      bzrlib/tests/workingtree_implementations/test_parents.py test_set_parents.py-20060807231740-yicmnlci1mj8smu1-1
      bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
      bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
    ------------------------------------------------------------
    revno: 3453.4.4
    revision-id:andrew.bennetts at canonical.com-20080603224305-qmk0zbwc8kieqlbm
    parent: andrew.bennetts at canonical.com-20080602231754-548g9nunvahbgkv1
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: remote-is-at-least
    timestamp: Wed 2008-06-04 08:43:05 +1000
    message:
      Small optimisation: don't bother trying RPCs from >= 1.6 if the server doesn't support protocol v3.
    modified:
      bzrlib/smart/client.py         client.py-20061116014825-2k6ada6xgulslami-1
      bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
    ------------------------------------------------------------
    revno: 3453.4.3
    revision-id:andrew.bennetts at canonical.com-20080602231754-548g9nunvahbgkv1
    parent: andrew.bennetts at canonical.com-20080529065132-rbfcrtmrbdgmqass
    parent: pqm at pqm.ubuntu.com-20080601233619-di6or8d3o26n917q
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: remote-is-at-least
    timestamp: Tue 2008-06-03 09:17:54 +1000
    message:
      Merge from bzr.dev.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/commands.py             bzr.py-20050309040720-d10f4714595cf8c3
      bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
      bzrlib/graph.py                graph_walker.py-20070525030359-y852guab65d4wtn0-1
      bzrlib/log.py                  log.py-20050505065812-c40ce11702fe5fb1
      bzrlib/merge.py                merge.py-20050513021216-953b65a438527106
      bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
      bzrlib/repofmt/knitrepo.py     knitrepo.py-20070206081537-pyy4a00xdas0j4pf-1
      bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
      bzrlib/revisionspec.py         revisionspec.py-20050907152633-17567659fd5c0ddb
      bzrlib/smart/client.py         client.py-20061116014825-2k6ada6xgulslami-1
      bzrlib/smart/message.py        message.py-20080222013625-ncqmh3nrxjkxab87-1
      bzrlib/symbol_versioning.py    symbol_versioning.py-20060105104851-9ecf8af605d15a80
      bzrlib/tests/branch_implementations/test_update.py test_update.py-20060305010612-e68efbcbb1baa69f
      bzrlib/tests/test_errors.py    test_errors.py-20060210110251-41aba2deddf936a8
      bzrlib/tests/test_graph.py     test_graph_walker.py-20070525030405-enq4r60hhi9xrujc-1
      bzrlib/tests/test_merge.py     testmerge.py-20050905070950-c1b5aa49ff911024
      bzrlib/tests/test_revisionspec.py testrevisionnamespaces.py-20050711050225-8b4af89e6b1efe84
      bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
      bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
      bzrlib/tests/test_symbol_versioning.py test_symbol_versioning.py-20060105104851-51d7722c2018d42b
      bzrlib/uncommit.py             uncommit.py-20050626215513-5ec509fa425b305c
      doc/developers/HACKING.txt     HACKING-20050805200004-2a5dc975d870f78c
      doc/developers/index.txt       index.txt-20070508041241-qznziunkg0nffhiw-1
      doc/developers/releasing.txt   releasing.txt-20080502015919-fnrcav8fwy8ccibu-1
      doc/en/user-guide/branching_a_project.txt branching_a_project.-20071122141511-0knao2lklsdsvb1q-2
      doc/en/user-guide/partner_intro.txt partner_workflow.txt-20071122141511-0knao2lklsdsvb1q-4
      doc/en/user-guide/releasing_a_project.txt releasing_a_project.-20071121073725-0corxykv5irjal00-5
      doc/en/user-guide/svn_plugin.txt svn_plugin.txt-20080509065016-cjc90f46407vi9a0-2
      doc/en/user-guide/undoing_mistakes.txt undoing_mistakes.txt-20071121092300-8fyacngt1w98e5mp-1
    ------------------------------------------------------------
    revno: 3453.4.2
    revision-id:andrew.bennetts at canonical.com-20080529065132-rbfcrtmrbdgmqass
    parent: andrew.bennetts at canonical.com-20080529064343-raflmdzsj7bunjj1
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: remote-is-at-least
    timestamp: Thu 2008-05-29 16:51:32 +1000
    message:
      Remove whitespace nits.
    modified:
      bzrlib/smart/medium.py         medium.py-20061103051856-rgu2huy59fkz902q-1
    ------------------------------------------------------------
    revno: 3453.4.1
    revision-id:andrew.bennetts at canonical.com-20080529064343-raflmdzsj7bunjj1
    parent: pqm at pqm.ubuntu.com-20080527013230-8qjaju10duxpy3e2
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: remote-is-at-least
    timestamp: Thu 2008-05-29 16:43:43 +1000
    message:
      Better infrastructure on SmartClientMedium for tracking the remote version.
    modified:
      bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
      bzrlib/smart/medium.py         medium.py-20061103051856-rgu2huy59fkz902q-1
      bzrlib/tests/test_remote.py    test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
      bzrlib/transport/http/_urllib.py _urlgrabber.py-20060113083826-0bbf7d992fbf090c
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2008-06-07 22:15:25 +0000
+++ b/bzrlib/remote.py	2008-06-17 04:32:18 +0000
@@ -840,7 +840,7 @@
     def _get_parent_map(self, keys):
         """Helper for get_parent_map that performs the RPC."""
         medium = self._client._medium
-        if not medium._remote_is_at_least_1_2:
+        if medium._is_remote_before((1, 2)):
             # We already found out that the server can't understand
             # Repository.get_parent_map requests, so just fetch the whole
             # graph.
@@ -919,7 +919,7 @@
             medium.disconnect()
             # To avoid having to disconnect repeatedly, we keep track of the
             # fact the server doesn't understand remote methods added in 1.2.
-            medium._remote_is_at_least_1_2 = False
+            medium._remember_remote_is_before((1, 2))
             return self.get_revision_graph(None)
         response_tuple, response_handler = response
         if response_tuple[0] not in ['ok']:
@@ -1080,7 +1080,7 @@
 
     def get_data_stream_for_search(self, search):
         medium = self._client._medium
-        if not medium._remote_is_at_least_1_2:
+        if medium._is_remote_before((1, 2)):
             self._ensure_real()
             return self._real_repository.get_data_stream_for_search(search)
         REQUEST_NAME = 'Repository.stream_revisions_chunked'
@@ -1101,7 +1101,7 @@
             medium.disconnect()
             # To avoid having to disconnect repeatedly, we keep track of the
             # fact the server doesn't understand this remote method.
-            medium._remote_is_at_least_1_2 = False
+            medium._remember_remote_is_before((1, 2))
             self._ensure_real()
             return self._real_repository.get_data_stream_for_search(search)
 

=== modified file 'bzrlib/smart/client.py'
--- a/bzrlib/smart/client.py	2008-05-30 04:33:39 +0000
+++ b/bzrlib/smart/client.py	2008-06-17 04:22:26 +0000
@@ -61,6 +61,9 @@
                     response_handler)
         else:
             for protocol_version in [3, 2]:
+                if protocol_version == 2:
+                    # If v3 doesn't work, the remote side is older than 1.6.
+                    self._medium._remember_remote_is_before((1, 6))
                 response_handler = self._send_request(
                     protocol_version, method, args, body=body,
                     readv_body=readv_body)

=== modified file 'bzrlib/smart/medium.py'
--- a/bzrlib/smart/medium.py	2008-05-20 23:30:28 +0000
+++ b/bzrlib/smart/medium.py	2008-06-17 04:32:18 +0000
@@ -440,9 +440,45 @@
         self._protocol_version = None
         self._done_hello = False
         # Be optimistic: we assume the remote end can accept new remote
-        # requests until we get an error saying otherwise.  (1.2 adds some
-        # requests that send bodies, which confuses older servers.)
-        self._remote_is_at_least_1_2 = True
+        # requests until we get an error saying otherwise.
+        # _remote_version_is_before tracks the bzr version the remote side
+        # can be based on what we've seen so far.
+        self._remote_version_is_before = None
+
+    def _is_remote_before(self, version_tuple):
+        """Is it possible the remote side is supports RPCs for a given version?
+
+        Typical use::
+
+            needed_version = (1, 2)
+            if medium._is_remote_before(needed_version):
+                fallback_to_pre_1_2_rpc()
+            else:
+                try:
+                    do_1_2_rpc()
+                except UnknownSmartMethod:
+                    medium._remember_remote_is_before(needed_version)
+                    fallback_to_pre_1_2_rpc()
+
+        :seealso: _remember_remote_is_before
+        """
+        if self._remote_version_is_before is None:
+            # So far, the remote side seems to support everything
+            return False
+        return version_tuple >= self._remote_version_is_before
+
+    def _remember_remote_is_before(self, version_tuple):
+        """Tell this medium that the remote side is older the given version.
+
+        :seealso: _is_remote_before
+        """
+        if (self._remote_version_is_before is not None and
+            version_tuple > self._remote_version_is_before):
+            raise AssertionError, (
+                "_remember_remote_is_before(%r) called, but "
+                "_remember_remote_is_before(%r) was called previously."
+                % (version_tuple, self._remote_version_is_before))
+        self._remote_version_is_before = version_tuple
 
     def protocol_version(self):
         """Find out if 'hello' smart request works."""

=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py	2008-05-22 05:48:22 +0000
+++ b/bzrlib/tests/test_remote.py	2008-06-17 04:32:18 +0000
@@ -187,9 +187,8 @@
 class FakeMedium(medium.SmartClientMedium):
 
     def __init__(self, client_calls, base):
-        self._remote_is_at_least_1_2 = True
+        medium.SmartClientMedium.__init__(self, base)
         self._client_calls = client_calls
-        self.base = base
 
     def disconnect(self):
         self._client_calls.append(('disconnect medium',))
@@ -254,6 +253,34 @@
                 'xyz/', scheme + '//host/path', 'xyz/')
 
 
+class Test_ClientMedium_remote_is_at_least(tests.TestCase):
+    """Tests for the behaviour of client_medium.remote_is_at_least."""
+
+    def test_initially_unlimited(self):
+        """A fresh medium assumes that the remote side supports all
+        versions.
+        """
+        client_medium = medium.SmartClientMedium('dummy base')
+        self.assertFalse(client_medium._is_remote_before((99, 99)))
+    
+    def test__remember_remote_is_before(self):
+        """Calling _remember_remote_is_before ratchets down the known remote
+        version.
+        """
+        client_medium = medium.SmartClientMedium('dummy base')
+        # Mark the remote side as being less than 1.6.  The remote side may
+        # still be 1.5.
+        client_medium._remember_remote_is_before((1, 6))
+        self.assertTrue(client_medium._is_remote_before((1, 6)))
+        self.assertFalse(client_medium._is_remote_before((1, 5)))
+        # Calling _remember_remote_is_before again with a lower value works.
+        client_medium._remember_remote_is_before((1, 5))
+        self.assertTrue(client_medium._is_remote_before((1, 5)))
+        # You cannot call _remember_remote_is_before with a larger value.
+        self.assertRaises(
+            AssertionError, client_medium._remember_remote_is_before, (1, 9))
+
+
 class TestBzrDirOpenBranch(tests.TestCase):
 
     def test_branch_present(self):
@@ -883,7 +910,7 @@
         repo, client = self.setup_fake_client_and_repository(transport_path)
         client.add_unknown_method_response('Repository,get_parent_map')
         client.add_success_response_with_body('', 'ok')
-        self.assertTrue(client._medium._remote_is_at_least_1_2)
+        self.assertFalse(client._medium._is_remote_before((1, 2)))
         rev_id = 'revision-id'
         expected_deprecations = [
             'bzrlib.remote.RemoteRepository.get_revision_graph was deprecated '
@@ -898,7 +925,7 @@
               ('quack/', ''))],
             client._calls)
         # The medium is now marked as being connected to an older server
-        self.assertFalse(client._medium._remote_is_at_least_1_2)
+        self.assertTrue(client._medium._is_remote_before((1, 2)))
 
     def test_get_parent_map_fallback_parentless_node(self):
         """get_parent_map falls back to get_revision_graph on old servers.  The
@@ -915,7 +942,7 @@
         transport_path = 'quack'
         repo, client = self.setup_fake_client_and_repository(transport_path)
         client.add_success_response_with_body(rev_id, 'ok')
-        client._medium._remote_is_at_least_1_2 = False
+        client._medium._remember_remote_is_before((1, 2))
         expected_deprecations = [
             'bzrlib.remote.RemoteRepository.get_revision_graph was deprecated '
             'in version 1.4.']

=== modified file 'bzrlib/tests/test_smart_transport.py'
--- a/bzrlib/tests/test_smart_transport.py	2008-06-02 01:12:17 +0000
+++ b/bzrlib/tests/test_smart_transport.py	2008-06-17 04:32:18 +0000
@@ -2774,7 +2774,7 @@
         self.assertCallDoesNotBreakMedium('method', ('args',), u'body')
 
 
-class MockMedium(object):
+class MockMedium(medium.SmartClientMedium):
     """A mock medium that can be used to test _SmartClient.
     
     It can be given a series of requests to expect (and responses it should
@@ -2791,10 +2791,9 @@
     """
 
     def __init__(self):
-        self.base = 'dummy base'
+        super(MockMedium, self).__init__('dummy base')
         self._mock_request = _MockMediumRequest(self)
         self._expected_events = []
-        self._protocol_version = None
         
     def expect_request(self, request_bytes, response_bytes,
                        allow_partial_read=False):
@@ -2931,6 +2930,9 @@
         # medium, and the smart_client returns the response from the server.
         self.assertEqual(('response value',), result)
         self.assertEqual([], medium._expected_events)
+        # Also, the v3 works then the server should be assumed to support RPCs
+        # introduced in 1.6.
+        self.assertFalse(medium._is_remote_before((1, 6)))
 
     def test_version_two_server(self):
         """If the server only speaks protocol 2, the client will first try
@@ -2969,6 +2971,10 @@
         self.assertEqual(('another response',), result)
         self.assertEqual([], medium._expected_events)
 
+        # Also, because v3 is not supported, the client medium should assume
+        # that RPCs introduced in 1.6 aren't supported either.
+        self.assertTrue(medium._is_remote_before((1, 6)))
+
     def test_unknown_version(self):
         """If the server does not use any known (or at least supported)
         protocol version, a SmartProtocolError is raised.

=== modified file 'bzrlib/transport/http/_urllib.py'
--- a/bzrlib/transport/http/_urllib.py	2008-05-19 10:04:15 +0000
+++ b/bzrlib/transport/http/_urllib.py	2008-05-29 06:43:43 +0000
@@ -48,7 +48,6 @@
             self._opener = _from_transport._opener
         else:
             self._opener = self._opener_class()
-        self._remote_is_at_least_1_2 = True
 
     def _perform(self, request):
         """Send the request to the server and handles common errors.




More information about the bazaar-commits mailing list