Add support for id maps to the file id generating functions.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 23 Dec 2006 16:58:12 +0000 (17:58 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Sat, 23 Dec 2006 16:58:12 +0000 (17:58 +0100)
__init__.py
fileids.py
repository.py
tests/test_fileids.py
tests/test_repos.py
tests/test_transport.py

index 99b8a514ae148f37373a913c88c282187bca098b..3850b34cc3678758405408ceee62e78b95bf9d31 100644 (file)
@@ -55,6 +55,10 @@ def check_bzrlib_version(desired):
             raise Exception, 'Version mismatch'
 
 check_bzrlib_version(required_bzr_version)
+try:
+    from bzrlib.workingtree import WorkingTreeFormat4
+except ImportError:
+    warning('this version of bzr-svn requires WorkingTreeFormat4 to be available to work properly')
 
 import branch
 import convert
index ba9015c2464594b5504363cc8f53aae47b26e244..741693c3b7df75e89feb783106f52bac77198c6e 100644 (file)
@@ -98,7 +98,8 @@ class FileIdMap(object):
 
         return map
 
-    def apply_changes(self, uuid, revnum, branch, global_changes, map):
+    def apply_changes(self, uuid, revnum, branch, global_changes, map, 
+            renames={}):
         """Change file id map to incorporate specified changes.
 
         :param uuid: UUID of repository changes happen in
@@ -116,7 +117,7 @@ class FileIdMap(object):
 
         revid = generate_svn_revision_id(uuid, revnum, branch)
 
-        return self._apply_changes(map, revid, changes, find_children)
+        return self._apply_changes(map, revid, changes, find_children, renames)
 
     def get_map(self, uuid, revnum, branch, pb=None):
         """Make sure the map is up to date until revnum."""
@@ -178,7 +179,12 @@ class FileIdMap(object):
 
 class SimpleFileIdMap(FileIdMap):
     @staticmethod
-    def _apply_changes(map, revid, changes, find_children=None):
+    def _apply_changes(map, revid, changes, find_children=None, renames={}):
+        def new_file_id(path):
+            mutter('new file id for %r. renames: %r' % (path, renames))
+            if renames.has_key(path):
+                return renames[path]
+            return generate_file_id(revid, path)
         sorted_paths = changes.keys()
         sorted_paths.sort()
         for p in sorted_paths:
@@ -192,7 +198,7 @@ class SimpleFileIdMap(FileIdMap):
                         del map[c]
 
             if data[0] in ('A', 'R'):
-                map[p] = generate_file_id(revid, p), revid
+                map[p] = new_file_id(p), revid
 
                 if not data[1] is None:
                     mutter('%r:%s copied from %r:%s' % (p, revid, data[1], data[2]))
@@ -200,7 +206,7 @@ class SimpleFileIdMap(FileIdMap):
                         warn('incomplete data for %r' % p)
                     else:
                         for c in find_children(data[1], data[2]):
-                            map[c.replace(data[1], p, 1)] = generate_file_id(revid, c), revid
+                            map[c.replace(data[1], p, 1)] = new_file_id(c), revid
 
             elif data[0] == 'M':
                 assert map.has_key(p), "Map has no item %s to modify" % p
index c9a5854ea43149f1d56e74765b03c7414724ecf8..9ea0c13781acacc0f7d033b53abbb108de25bff2 100644 (file)
@@ -259,8 +259,8 @@ class SvnRepository(Repository):
     def get_fileid_map(self, revnum, path, pb=None):
         return self.fileid_map.get_map(self.uuid, revnum, path, pb)
 
-    def transform_fileid_map(self, uuid, revnum, branch, changes, map):
-        return self.fileid_map.apply_changes(uuid, revnum, branch, changes, map)
+    def transform_fileid_map(self, uuid, revnum, branch, changes, map, renames={}):
+        return self.fileid_map.apply_changes(uuid, revnum, branch, changes, map, renames={})
 
     def path_to_file_id(self, revnum, path):
         """Generate a bzr file id from a Subversion file name. 
index f4168ef9bd6d58eb0862f67e7b7c04751f2ef7d5..8a3530423a0bbe055dae8b8cd0a23e3433f740c7 100644 (file)
@@ -148,13 +148,15 @@ class TestComplexFileids(TestCaseWithSubversionRepository):
                 revid)
 
 class TestFileMapping(TestCase):
-    def apply_mappings(self, mappings, find_children=None):
+    def apply_mappings(self, mappings, find_children=None, renames={}):
         map = {"": ("ROOT", "first-revision") }
         revids = mappings.keys()
         revids.sort()
         for r in revids:
+            if not renames.has_key(r):
+                renames[r] = {}
             map = SimpleFileIdMap._apply_changes(map, r, mappings[r], 
-                                                 find_children)
+                                                 find_children, renames=renames[r])
         return map
 
     def test_simple(self):
@@ -190,3 +192,25 @@ class TestFileMapping(TestCase):
                                    "foo/bla": ('M', None, None)}
                 })
         self.assertEqual("svn-v%d:2@uuid-" % MAPPING_VERSION, map["foo"][1])
+
+    def test_usemap(self):
+        map = self.apply_mappings(
+                {("svn-v%d:1@uuid-" % MAPPING_VERSION): {
+                                   "foo": ('A', None, None), 
+                                   "foo/bla": ('A', None, None)},
+                 ("svn-v%d:2@uuid-" % MAPPING_VERSION): {
+                                   "foo/bla": ('M', None, None)}
+                 }, 
+                renames={("svn-v%d:1@uuid-" % MAPPING_VERSION): {"foo": "myid"}})
+        self.assertEqual("myid", map["foo"][0])
+
+    def test_usemap_later(self):
+        map = self.apply_mappings(
+                {("svn-v%d:1@uuid-" % MAPPING_VERSION): {
+                                   "foo": ('A', None, None), 
+                                   "foo/bla": ('A', None, None)},
+                 ("svn-v%d:2@uuid-" % MAPPING_VERSION): {
+                                   "foo/bla": ('M', None, None)}
+                 }, 
+                renames={("svn-v%d:2@uuid-" % MAPPING_VERSION): {"foo": "myid"}})
+        self.assertEqual("svn-v%d:1@uuid--foo" % MAPPING_VERSION, map["foo"][0])
index 7ace2ea995c11f3c62be3fd0e964f4be55d92a51..4fb6713e1463f49cb084a149d19703b097194257 100644 (file)
@@ -14,6 +14,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+from bzrlib.branch import Branch
 from bzrlib.bzrdir import BzrDir
 from bzrlib.errors import NoSuchRevision
 from bzrlib.inventory import Inventory
@@ -89,6 +90,17 @@ class TestSubversionRepositoryWorks(TestCaseWithSubversionRepository):
             repository.revision_parents(
                 "svn-v%d:2@%s-" % (MAPPING_VERSION, repository.uuid)))
 
+    def test_revision_fileidmap(self):
+        repos_url = self.make_client('d', 'dc')
+        self.build_tree({'dc/foo': "data"})
+        self.client_add("dc/foo")
+        self.client_set_prop("dc", "bzr:file-ids", "foo\tsomeid\n")
+        self.client_commit("dc", "My Message")
+        repository = Repository.open("svn+%s" % repos_url)
+        tree = repository.revision_tree(Branch.open(repos_url).last_revision())
+        self.assertEqual("someid", tree.inventory.path2id("foo"))
+        self.assertFalse("svn-v2:1@%s--foo" % repository.uuid in tree.inventory)
+
     def test_revision_ghost_parents(self):
         repos_url = self.make_client('d', 'dc')
         self.build_tree({'dc/foo': "data"})
index 89705386f6fe8988cab7459787131ff5bca3bc70..704ffba597a7d4e563eb6ab03636914d40348978 100644 (file)
@@ -112,7 +112,7 @@ class SvnRaTest(TestCaseWithSubversionRepository):
 
         t = SvnRaTransport(repos_url)
         self.assertEqual("%s/dir" % repos_url, t.clone('dir').base)
-        
+
     def test_get_root(self):
         repos_url = self.make_client('d', 'dc')
         self.build_tree({"dc/dir": None, "dc/bl": "data"})