[MERGE] Fix MemoryTransport().abspath('/foo')

Andrew Bennetts andrew at canonical.com
Fri Oct 13 06:38:46 BST 2006


MemoryTransport().abspath('/foo') was producing 'memory://foo/', which obviously
isn't right.

The attached bundle fixes this by adjusting Transport._combine_paths.  No other
transports seem to be affected though, so perhaps I've fixed this in the wrong
place?

Anyway, here's the fix I have, it's simple and doesn't break any existing
transport tests (and obviously passes the new ones).  Please review.

-Andrew.

-------------- next part --------------
# Bazaar revision bundle v0.8
#
# message:
#   Fix memory_transport.abspath('/foo')
# committer: Andrew Bennetts <andrew.bennetts at canonical.com>
# date: Fri 2006-10-13 15:29:02.743000031 +1000

=== modified file bzrlib/tests/test_transport.py
--- bzrlib/tests/test_transport.py
+++ bzrlib/tests/test_transport.py
@@ -179,8 +179,9 @@
         self.assertEqual("memory:///", transport.base)
         self.assertEqual("memory:///", transport.abspath('/'))
 
-    def test_relpath(self):
+    def test_abspath_of_relpath_starting_at_root(self):
         transport = MemoryTransport()
+        self.assertEqual("memory:///foo", transport.abspath('/foo'))
 
     def test_append_and_get(self):
         transport = MemoryTransport()

=== modified file bzrlib/tests/test_transport_implementations.py
--- bzrlib/tests/test_transport_implementations.py
+++ bzrlib/tests/test_transport_implementations.py
@@ -1117,6 +1117,9 @@
         # the abspath of "/" and "/foo/.." should result in the same location
         self.assertEqual(transport.abspath("/"), transport.abspath("/foo/.."))
 
+        self.assertEqual(transport.clone("/").abspath('foo'),
+                         transport.abspath("/foo"))
+
     def test_local_abspath(self):
         transport = self.get_transport()
         try:

=== modified file bzrlib/transport/__init__.py
--- bzrlib/transport/__init__.py
+++ bzrlib/transport/__init__.py
@@ -328,6 +328,10 @@
             '/home/sarah/project/foo'
             >>> t._combine_paths('/home/sarah', '../../etc')
             '/etc'
+            >>> t._combine_paths('/home/sarah', '/etc')
+            '/etc'
+            >>> t._combine_paths('/home/sarah', '../../../etc')
+            '/etc'
 
         :param base_path: urlencoded path for the transport root; typically a 
              URL but need not contain scheme/host/etc.
@@ -359,6 +363,8 @@
             elif p != '':
                 base_parts.append(p)
         path = '/'.join(base_parts)
+        if not path.startswith('/'):
+            path = '/' + path
         return path
 
     def relpath(self, abspath):

# revision id: andrew.bennetts at canonical.com-20061013052902-60a2d663ee8d494b
# sha1: 27cf49ac8fd3bdae6498ad46f4541fa1b088f857
# inventory sha1: 5f8460d7c69df50deff81f5dcfaeb758d6be7433
# parent ids:
#   pqm at pqm.ubuntu.com-20061010072307-037a6f63da8a1bdd
# base id: pqm at pqm.ubuntu.com-20061010072307-037a6f63da8a1bdd
# properties:
#   branch-nick: memory transport abspath



More information about the bazaar mailing list