Rev 5741: Integrate into bzr-2.4. in http://bazaar.launchpad.net/~jameinel/bzr/integration

John Arbash Meinel john at arbash-meinel.com
Thu Mar 24 11:42:01 UTC 2011


At http://bazaar.launchpad.net/~jameinel/bzr/integration

------------------------------------------------------------
revno: 5741 [merge]
revision-id: john at arbash-meinel.com-20110324114142-4tjsf4q4plpt52kr
parent: pqm at pqm.ubuntu.com-20110324034612-q4c2bs7buypnjvn1
parent: john at arbash-meinel.com-20110324113825-7dmqkgjqqt62n4a8
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: integration
timestamp: Thu 2011-03-24 12:41:42 +0100
message:
  Integrate into bzr-2.4.
  Only include the release-notes in 2.4, because we haven't officially
  decided to backport it to 2.3 yet.
  Remove the duplicated 'qastaging' entries.
modified:
  bzrlib/plugins/launchpad/lp_directory.py lp_indirect.py-20070126012204-de5rugwlt22c7u7e-1
  bzrlib/plugins/launchpad/lp_registration.py lp_registration.py-20060315190948-daa617eafe3a8d48
  bzrlib/plugins/launchpad/test_lp_directory.py test_lp_indirect.py-20070126002743-oyle362tzv9cd8mi-1
  doc/en/release-notes/bzr-2.3.txt NEWS-20050323055033-4e00b5db738777ff
  doc/en/release-notes/bzr-2.4.txt bzr2.4.txt-20110114053217-k7ym9jfz243fddjm-1
-------------- next part --------------
=== modified file 'bzrlib/plugins/launchpad/lp_directory.py'
--- a/bzrlib/plugins/launchpad/lp_directory.py	2011-03-23 13:36:31 +0000
+++ b/bzrlib/plugins/launchpad/lp_directory.py	2011-03-24 11:38:25 +0000
@@ -65,11 +65,31 @@
         """See DirectoryService.look_up"""
         return self._resolve(url)
 
-    def _resolve_locally(self, path):
-        # Launchpad is now capable of doing the short-name to long name
-        # resolution inside the bzr+ssh server. We aren't yet able to do so for
-        # HTTP urls. - jam 20110323
-        return {'urls': ['bzr+ssh://bazaar.launchpad.net/+branch/' + path]}
+    def _resolve_locally(self, path, url, _request_factory):
+        # This is the best I could work out about XMLRPC. If an lp: url
+        # includes ~user, then it is specially validated. Otherwise, it is just
+        # sent to +branch/$path.
+        _, netloc, _, _, _ = urlsplit(url)
+        if netloc == '':
+            netloc = LaunchpadService.DEFAULT_INSTANCE
+        base_url = LaunchpadService.LAUNCHPAD_DOMAINS[netloc]
+        base = 'bzr+ssh://bazaar.%s/' % (base_url,)
+        maybe_invalid = False
+        if path.startswith('~'):
+            # A ~user style path, validate it a bit.
+            # If a path looks fishy, fall back to asking XMLRPC to
+            # resolve it for us. That way we still get their nicer error
+            # messages.
+            parts = path.split('/')
+            if (len(parts) < 3
+                or (parts[1] in ('ubuntu', 'debian') and len(parts) < 5)):
+                # This special case requires 5-parts to be valid.
+                maybe_invalid = True
+        else:
+            base += '+branch/'
+        if maybe_invalid:
+            return self._resolve_via_xmlrpc(path, url, _request_factory)
+        return {'urls': [base + path]}
 
     def _resolve_via_xmlrpc(self, path, url, _request_factory):
         service = LaunchpadService.for_url(url)
@@ -140,7 +160,12 @@
         path = path.strip('/')
         path = self._expand_user(path, url, _lp_login)
         if _lp_login is not None:
-            result = self._resolve_locally(path)
+            result = self._resolve_locally(path, url, _request_factory)
+            if 'launchpad' in debug.debug_flags:
+                local_res = result
+                result = self._resolve_via_xmlrpc(path, url, _request_factory)
+                trace.note('resolution for %s\n  local: %s\n remote: %s'
+                           % (url, local_res['urls'], result['urls']))
         else:
             result = self._resolve_via_xmlrpc(path, url, _request_factory)
 

=== modified file 'bzrlib/plugins/launchpad/lp_registration.py'
--- a/bzrlib/plugins/launchpad/lp_registration.py	2011-01-17 06:26:35 +0000
+++ b/bzrlib/plugins/launchpad/lp_registration.py	2011-03-24 11:41:42 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2006-2010 Canonical Ltd
+# Copyright (C) 2006-2011 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -86,8 +86,8 @@
 
     LAUNCHPAD_DOMAINS = {
         'production': 'launchpad.net',
+        'staging': 'staging.launchpad.net',
         'qastaging': 'qastaging.launchpad.net',
-        'staging': 'staging.launchpad.net',
         'demo': 'demo.launchpad.net',
         'dev': 'launchpad.dev',
         }

=== modified file 'bzrlib/plugins/launchpad/test_lp_directory.py'
--- a/bzrlib/plugins/launchpad/test_lp_directory.py	2011-03-23 15:03:13 +0000
+++ b/bzrlib/plugins/launchpad/test_lp_directory.py	2011-03-24 11:41:42 +0000
@@ -20,6 +20,7 @@
 import xmlrpclib
 
 from bzrlib import (
+    debug,
     errors,
     tests,
     transport,
@@ -62,10 +63,12 @@
 
 
 class FakeResolveFactory(object):
+
     def __init__(self, test, expected_path, result):
         self._test = test
         self._expected_path = expected_path
         self._result = result
+        self._submitted = False
 
     def __call__(self, path):
         self._test.assertEqual(self._expected_path, path)
@@ -73,9 +76,136 @@
 
     def submit(self, service):
         self._service_url = service.service_url
+        self._submitted = True
         return self._result
 
 
+class LocalDirectoryURLTests(TestCaseInTempDir):
+    """Tests for branch urls that we try to pass through local resolution."""
+
+    def assertResolve(self, expected, url, submitted=False):
+        path = url[url.index(':')+1:].lstrip('/')
+        factory = FakeResolveFactory(self, path,
+                    dict(urls=['bzr+ssh://fake-resolved']))
+        directory = LaunchpadDirectory()
+        self.assertEqual(expected,
+            directory._resolve(url, factory, _lp_login='user'))
+        # We are testing local resolution, and the fallback when necessary.
+        self.assertEqual(submitted, factory._submitted)
+
+    def test_short_form(self):
+        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/apt',
+                           'lp:apt')
+
+    def test_two_part_form(self):
+        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/apt/2.2',
+                           'lp:apt/2.2')
+
+    def test_two_part_plus_subdir(self):
+        # We allow you to pass more than just what resolves. That way you can
+        # do things like "bzr log lp:apt/2.2/BUGS"
+        # Though the virtual FS implementation currently aborts when given a
+        # URL like this, rather than letting you recurse upwards to find the
+        # real branch at lp:apt/2.2
+        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/apt/2.2/BUGS',
+                           'lp:apt/2.2/BUGS')
+
+    def test_user_expansion(self):
+        self.assertResolve('bzr+ssh://bazaar.launchpad.net/~user/apt/foo',
+                           'lp:~/apt/foo')
+
+    def test_ubuntu(self):
+        # Confirmed against xmlrpc. If you don't have a ~user, xmlrpc doesn't
+        # care that you are asking for 'ubuntu'
+        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/ubuntu',
+                           'lp:ubuntu')
+
+    def test_ubuntu_apt(self):
+        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/ubuntu/apt',
+                           'lp:ubuntu/apt')
+
+    def test_ubuntu_natty_apt(self):
+        self.assertResolve(
+            'bzr+ssh://bazaar.launchpad.net/+branch/ubuntu/natty/apt',
+            'lp:ubuntu/natty/apt')
+
+    def test_ubuntu_natty_apt_filename(self):
+        self.assertResolve(
+            'bzr+ssh://bazaar.launchpad.net/+branch/ubuntu/natty/apt/filename',
+            'lp:ubuntu/natty/apt/filename')
+
+    def test_user_two_part(self):
+        # We fall back to the ResolveFactory. The real Launchpad one will raise
+        # InvalidURL for this case.
+        self.assertResolve('bzr+ssh://fake-resolved', 'lp:~jameinel/apt',
+                           submitted=True)
+
+    def test_user_three_part(self):
+        self.assertResolve('bzr+ssh://bazaar.launchpad.net/~jameinel/apt/foo',
+                           'lp:~jameinel/apt/foo')
+
+    def test_user_three_part_plus_filename(self):
+        self.assertResolve(
+            'bzr+ssh://bazaar.launchpad.net/~jameinel/apt/foo/fname',
+            'lp:~jameinel/apt/foo/fname')
+
+    def test_user_ubuntu_two_part(self):
+        self.assertResolve('bzr+ssh://fake-resolved', 'lp:~jameinel/ubuntu',
+                           submitted=True)
+        self.assertResolve('bzr+ssh://fake-resolved', 'lp:~jameinel/debian',
+                           submitted=True)
+
+    def test_user_ubuntu_three_part(self):
+        self.assertResolve('bzr+ssh://fake-resolved',
+                           'lp:~jameinel/ubuntu/natty', submitted=True)
+        self.assertResolve('bzr+ssh://fake-resolved',
+                           'lp:~jameinel/debian/sid', submitted=True)
+
+    def test_user_ubuntu_four_part(self):
+        self.assertResolve('bzr+ssh://fake-resolved',
+                           'lp:~jameinel/ubuntu/natty/project', submitted=True)
+        self.assertResolve('bzr+ssh://fake-resolved',
+                           'lp:~jameinel/debian/sid/project', submitted=True)
+
+    def test_user_ubuntu_five_part(self):
+        self.assertResolve(
+            'bzr+ssh://bazaar.launchpad.net/~jameinel/ubuntu/natty/apt/branch',
+            'lp:~jameinel/ubuntu/natty/apt/branch')
+        self.assertResolve(
+            'bzr+ssh://bazaar.launchpad.net/~jameinel/debian/sid/apt/branch',
+            'lp:~jameinel/debian/sid/apt/branch')
+
+    def test_user_ubuntu_five_part_plus_subdir(self):
+        self.assertResolve(
+            'bzr+ssh://bazaar.launchpad.net/~jameinel/ubuntu/natty/apt/branch/f',
+            'lp:~jameinel/ubuntu/natty/apt/branch/f')
+        self.assertResolve(
+            'bzr+ssh://bazaar.launchpad.net/~jameinel/debian/sid/apt/branch/f',
+            'lp:~jameinel/debian/sid/apt/branch/f')
+
+    def test_handles_special_lp(self):
+        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/apt', 'lp:apt')
+        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/apt',
+                           'lp:///apt')
+        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/apt',
+                           'lp://production/apt')
+        self.assertResolve('bzr+ssh://bazaar.launchpad.dev/+branch/apt',
+                           'lp://dev/apt')
+        self.assertResolve('bzr+ssh://bazaar.staging.launchpad.net/+branch/apt',
+                           'lp://staging/apt')
+        self.assertResolve('bzr+ssh://bazaar.qastaging.launchpad.net/+branch/apt',
+                           'lp://qastaging/apt')
+        self.assertResolve('bzr+ssh://bazaar.demo.launchpad.net/+branch/apt',
+                           'lp://demo/apt')
+
+    def test_debug_launchpad_uses_resolver(self):
+        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/bzr',
+                           'lp:bzr', submitted=False)
+        debug.debug_flags.add('launchpad')
+        self.addCleanup(debug.debug_flags.discard, 'launchpad')
+        self.assertResolve('bzr+ssh://fake-resolved', 'lp:bzr', submitted=True)
+
+
 class DirectoryUrlTests(TestCaseInTempDir):
     """Tests for branch urls through Launchpad.net directory"""
 
@@ -212,15 +342,15 @@
     def test_resolve_tilde_to_user(self):
         factory = FakeResolveFactory(
             self, '~username/apt/test', dict(urls=[
-                'bzr+ssh://bazaar.launchpad.net/+branch/~username/apt/test']))
+                'bzr+ssh://bazaar.launchpad.net/~username/apt/test']))
         directory = LaunchpadDirectory()
         self.assertEquals(
-            'bzr+ssh://bazaar.launchpad.net/+branch/~username/apt/test',
+            'bzr+ssh://bazaar.launchpad.net/~username/apt/test',
             directory._resolve('lp:~/apt/test', factory, _lp_login='username'))
         # Should also happen when the login is just set by config
         set_lp_login('username')
         self.assertEquals(
-            'bzr+ssh://bazaar.launchpad.net/+branch/~username/apt/test',
+            'bzr+ssh://bazaar.launchpad.net/~username/apt/test',
             directory._resolve('lp:~/apt/test', factory))
 
     def test_tilde_fails_no_login(self):

=== modified file 'doc/en/release-notes/bzr-2.3.txt'
--- a/doc/en/release-notes/bzr-2.3.txt	2011-03-23 15:03:13 +0000
+++ b/doc/en/release-notes/bzr-2.3.txt	2011-03-24 11:41:42 +0000
@@ -33,15 +33,6 @@
   of CHK data, down to just 150MB.) This has noticeable affects for things
   like building checkouts, etc.  (John Arbash Meinel, #737234)
 
-* Resolve ``lp:FOO`` urls locally rather than doing an XMLRPC request if
-  the user has done ``bzr launchpad-login``. The bzr+ssh URLs were already
-  being handed off to the remote server anyway (xmlrpc has been mapping
-  ``lp:bzr`` to ``bzr+ssh://bazaar.launchpad.net/+branch/bzr``, rather
-  than ``bzr+ssh://bazaar.launchpad.net/~bzr-pqm/bzr/bzr.dev`` for a few
-  months now.) By doing it ourselves, we can cut out substantial startup
-  time. From Netherlands to London it was taking 368ms to do the XMLRPC
-  call as much as 2s from Sydney. (John Arbash Meinel, #397739)
-
 Bug Fixes
 *********
 

=== modified file 'doc/en/release-notes/bzr-2.4.txt'
--- a/doc/en/release-notes/bzr-2.4.txt	2011-03-24 03:04:03 +0000
+++ b/doc/en/release-notes/bzr-2.4.txt	2011-03-24 11:41:42 +0000
@@ -26,6 +26,16 @@
 .. Improvements to existing commands, especially improved performance 
    or memory usage, or better results.
 
+* Resolve ``lp:FOO`` urls locally rather than doing an XMLRPC request if
+  the user has done ``bzr launchpad-login``. The bzr+ssh URLs were already
+  being handed off to the remote server anyway (xmlrpc has been mapping
+  ``lp:bzr`` to ``bzr+ssh://bazaar.launchpad.net/+branch/bzr``, rather
+  than ``bzr+ssh://bazaar.launchpad.net/~bzr-pqm/bzr/bzr.dev`` for a few
+  months now.) By doing it ourselves, we can cut out substantial startup
+  time. From Netherlands to London it was taking 368ms to do the XMLRPC
+  call as much as 2s from Sydney. You can test the local logic by using
+  ``-Dlaunchpad``.  (John Arbash Meinel, #397739)
+
 Bug Fixes
 *********
 



More information about the bazaar-commits mailing list