Rev 2520: (Ian Clatworthy, r=john) 'branch lp:projname' now creates ./projname as expected in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Jun 8 14:43:46 BST 2007


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

------------------------------------------------------------
revno: 2520
revision-id: pqm at pqm.ubuntu.com-20070608134340-flu6dlpzyo7izrrs
parent: pqm at pqm.ubuntu.com-20070608032544-x774g5cn0yh8a42p
parent: ian.clatworthy at internode.on.net-20070606140614-yp66v5i1gm5kruqp
committer: Canonical.com Patch Queue Manager<pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2007-06-08 14:43:40 +0100
message:
  (Ian Clatworthy, r=john) 'branch lp:projname' now creates ./projname as expected
modified:
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/tests/test_urlutils.py  test_urlutils.py-20060502192900-46b1f9579987cf9c
  bzrlib/urlutils.py             urlutils.py-20060502195429-e8a161ecf8fac004
    ------------------------------------------------------------
    revno: 2512.4.1
    merged: ian.clatworthy at internode.on.net-20070606140614-yp66v5i1gm5kruqp
    parent: pqm at pqm.ubuntu.com-20070606083714-rt2za45t9gt5nqqh
    committer: Ian Clatworthy <ian.clatworthy at internode.on.net>
    branch nick: bzr.branch-lp-ui
    timestamp: Thu 2007-06-07 00:06:14 +1000
    message:
      Fixes #115491 - 'branch lp:projname' now creates ./projname as exected
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2007-06-06 10:54:10 +0000
+++ b/bzrlib/builtins.py	2007-06-08 13:43:40 +0000
@@ -852,6 +852,10 @@
 
     If the TO_LOCATION is omitted, the last component of the FROM_LOCATION will
     be used.  In other words, "branch ../foo/bar" will attempt to create ./bar.
+    If the FROM_LOCATION has no / or path separator embedded, the TO_LOCATION
+    is derived from the FROM_LOCATION by stripping a leading scheme or drive
+    identifier, if any. For example, "branch lp:foo-bar" will attempt to
+    create ./foo-bar.
 
     To retrieve the branch as of a particular revision, supply the --revision
     parameter, as in "branch foo/bar -r 5".
@@ -881,7 +885,7 @@
                 # RBC 20060209
                 revision_id = br_from.last_revision()
             if to_location is None:
-                to_location = os.path.basename(from_location.rstrip("/\\"))
+                to_location = urlutils.derive_to_location(from_location)
                 name = None
             else:
                 name = os.path.basename(to_location) + '\n'
@@ -921,6 +925,10 @@
     
     If the TO_LOCATION is omitted, the last component of the BRANCH_LOCATION will
     be used.  In other words, "checkout ../foo/bar" will attempt to create ./bar.
+    If the BRANCH_LOCATION has no / or path separator embedded, the TO_LOCATION
+    is derived from the BRANCH_LOCATION by stripping a leading scheme or drive
+    identifier, if any. For example, "checkout lp:foo-bar" will attempt to
+    create ./foo-bar.
 
     To retrieve the branch as of a particular revision, supply the --revision
     parameter, as in "checkout foo/bar -r 5". Note that this will be immediately
@@ -957,7 +965,7 @@
         else:
             revision_id = None
         if to_location is None:
-            to_location = os.path.basename(branch_location.rstrip("/\\"))
+            to_location = urlutils.derive_to_location(branch_location)
         # if the source and to_location are the same, 
         # and there is no working tree,
         # then reconstitute a branch

=== modified file 'bzrlib/tests/test_urlutils.py'
--- a/bzrlib/tests/test_urlutils.py	2007-04-26 06:19:07 +0000
+++ b/bzrlib/tests/test_urlutils.py	2007-06-06 14:06:14 +0000
@@ -570,3 +570,21 @@
         #   u'/dod\xe9' => '/dod\xc3\xa9'
         url = urlutils.local_path_to_url('.')
         self.assertEndsWith(url, '/dod%C3%A9')
+
+
+class TestDeriveToLocation(TestCase):
+    """Test that the mapping of FROM_LOCATION to TO_LOCATION works."""
+
+    def test_to_locations_derived_from_paths(self):
+        derive = urlutils.derive_to_location
+        self.assertEqual("bar", derive("bar"))
+        self.assertEqual("bar", derive("../bar"))
+        self.assertEqual("bar", derive("/foo/bar"))
+        self.assertEqual("bar", derive("c:/foo/bar"))
+        self.assertEqual("bar", derive("c:bar"))
+
+    def test_to_locations_derived_from_urls(self):
+        derive = urlutils.derive_to_location
+        self.assertEqual("bar", derive("http://foo/bar"))
+        self.assertEqual("bar", derive("bzr+ssh://foo/bar"))
+        self.assertEqual("foo-bar", derive("lp:foo-bar"))

=== modified file 'bzrlib/urlutils.py'
--- a/bzrlib/urlutils.py	2007-04-26 06:19:07 +0000
+++ b/bzrlib/urlutils.py	2007-06-06 14:06:14 +0000
@@ -608,3 +608,24 @@
                 # Otherwise take the url decoded one
                 res[i] = decoded
     return u'/'.join(res)
+
+
+def derive_to_location(from_location):
+    """Derive a TO_LOCATION given a FROM_LOCATION.
+
+    The normal case is a FROM_LOCATION of http://foo/bar => bar.
+    The Right Thing for some logical destinations may differ though
+    because no / may be present at all. In that case, the result is
+    the full name without the scheme indicator, e.g. lp:foo-bar => foo-bar.
+    This latter case also applies when a Windows drive
+    is used without a path, e.g. c:foo-bar => foo-bar.
+    If no /, path separator or : is found, the from_location is returned.
+    """
+    if from_location.find("/") >= 0 or from_location.find(os.sep) >= 0:
+        return os.path.basename(from_location.rstrip("/\\"))
+    else:
+        sep = from_location.find(":")
+        if sep > 0:
+            return from_location[sep+1:]
+        else:
+            return from_location




More information about the bazaar-commits mailing list