Work around a strange bug in the subversion code that will report an
authorJelmer Vernooij <jelmer@samba.org>
Tue, 26 Dec 2006 02:35:40 +0000 (03:35 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Tue, 26 Dec 2006 02:35:40 +0000 (03:35 +0100)
add without a delete when an is being replaced and has the same filename and
origin.

__init__.py
convert.py
fetch.py
fileids.py
tests/test_repos.py

index 7eff13d9ea95f069f41da2b12b4cebc13e33316b..9d34156fbfd717c8f90586441abf145ff0d847f7 100644 (file)
@@ -123,7 +123,7 @@ class cmd_svn_import(Command):
     def run(self, url, output_dir, trees=False, shared=False, scheme="trunk"):
         from convert import convert_repository
 
-        convert_repository(url, output_dir, scheme_, shared, trees)
+        convert_repository(url, output_dir, scheme, shared, trees)
 
 
 register_command(cmd_svn_import)
index 0f3222eb832a736daa4d13e9defcdede380525b1..54e1f50c49d2d8895a77d170d4a1adbabf10a4cc 100644 (file)
@@ -62,19 +62,19 @@ def convert_repository(url, output_dir, scheme, create_shared_repo=True, working
             
         url = tmp_repos
 
-    if create_shared_repo:
-        try:
-            target_repos = Repository.open(output_dir)
-            assert target_repos.is_shared()
-        except NotBranchError:
-            if scheme.is_branch(""):
-                BzrDir.create_branch_and_repo(output_dir)
-            else:
-                BzrDir.create_repository(output_dir, shared=True)
-            target_repos = Repository.open(output_dir)
-        target_repos.set_make_working_trees(working_trees)
-
     try:
+        if create_shared_repo:
+            try:
+                target_repos = Repository.open(output_dir)
+                assert target_repos.is_shared()
+            except NotBranchError:
+                if scheme.is_branch(""):
+                    BzrDir.create_branch_and_repo(output_dir)
+                else:
+                    BzrDir.create_repository(output_dir, shared=True)
+                target_repos = Repository.open(output_dir)
+            target_repos.set_make_working_trees(working_trees)
+
         source_repos = SvnRepository.open(url)
 
         source_repos.set_branching_scheme(scheme)
index e2ea6bc833d5833334efc70214eb8b24b1df521e..64752b0dd89afb6d8149d1943a0ec7cef092c0de 100644 (file)
--- a/fetch.py
+++ b/fetch.py
@@ -117,6 +117,12 @@ class RevisionBuildEditor(svn.delta.Editor):
                 ie.revision = revision_id
                 return file_id
 
+            # there is a strange bug in the subversion editor that causes 
+            # it to not report deletes for files that are 
+            # being replaced (R) by an older copy of themselves
+            if copyfrom_path == path and base_file_id in self.inventory:
+                del self.inventory[base_file_id]
+
         self.dir_baserev[file_id] = []
         ie = self.inventory.add_path(path, 'directory', file_id)
         ie.revision = revision_id
index ec022892054694ba04acf9bce793f3ca9e56ff4e..d99cc6c2aa5437d4990a1d7c337b04e7af702483 100644 (file)
@@ -177,9 +177,6 @@ class SimpleFileIdMap(FileIdMap):
         for p in sorted_paths:
             data = changes[p]
 
-            # FIXME: If this was actually a replace from the same path earlier, 
-            # change data[0] to 'M'
-            
             if data[0] in ('D', 'R'):
                 assert map.has_key(p), "No map entry %s to delete/replace" % p
                 del map[p]
@@ -191,15 +188,13 @@ class SimpleFileIdMap(FileIdMap):
             if data[0] in ('A', 'R'):
                 map[p] = generate_file_id(revid, p), revid
 
-                if not data[1] is None:
+                if data[1] is not None:
                     mutter('%r:%s copied from %r:%s' % (p, revid, data[1], data[2]))
-                    if find_children is None:
-                        warn('incomplete data for %r' % p)
-                    else:
-                        for c in find_children(data[1], data[2]):
-                            path = c.replace(data[1], p, 1)
-                            map[path] = generate_file_id(revid, c), revid
-                            mutter('added mapping %r -> %r' % (path, map[path]))
+                    assert find_children is not None, 'incomplete data for %r' % p
+                    for c in find_children(data[1], data[2]):
+                        path = c.replace(data[1], p, 1)
+                        map[path] = generate_file_id(revid, c), revid
+                        mutter('added mapping %r -> %r' % (path, map[path]))
 
             elif data[0] == 'M':
                 if p == "":
index 67290069b240affb745baf139040d649b77fac72..4bb6b366945a61ea6cae52191d47ccfb47b1f9a9 100644 (file)
@@ -553,7 +553,7 @@ Node-copyfrom-path: bla
                 "svn-v%d:1@%s-" % (MAPPING_VERSION, oldrepos.uuid))
         inv2 = newrepos.get_inventory(
                 "svn-v%d:3@%s-" % (MAPPING_VERSION, oldrepos.uuid))
-        self.assertNotEqual(inv1.path2id("bla"), inv2.path2id("bla"))
+        self.assertEqual(inv1.path2id("bla"), inv2.path2id("bla"))
 
     def test_fetch_replace_backup(self):
         filename = os.path.join(self.test_dir, "dumpfile")
@@ -732,7 +732,7 @@ Node-copyfrom-path: bla
                 "svn-v%d:1@%s-" % (MAPPING_VERSION, oldrepos.uuid))
         inv2 = newrepos.get_inventory(
                 "svn-v%d:3@%s-" % (MAPPING_VERSION, oldrepos.uuid))
-        self.assertNotEqual(inv1.path2id("bla"), inv2.path2id("bla"))
+        self.assertEqual(inv1.path2id("bla"), inv2.path2id("bla"))
 
     def test_fetch_replace_unrelated(self):
         filename = os.path.join(self.test_dir, "dumpfile")
@@ -874,6 +874,168 @@ Node-copyfrom-path: x
                 "svn-v%d:4@%s-" % (MAPPING_VERSION, oldrepos.uuid))
         self.assertNotEqual(inv1.path2id("x"), inv2.path2id("x"))
 
+    def test_fetch_replace_related(self):
+        filename = os.path.join(self.test_dir, "dumpfile")
+        open(filename, 'w').write("""SVN-fs-dump-format-version: 2
+
+UUID: 606c7b1f-987c-4826-b37d-eb456ceb87e1
+
+Revision-number: 0
+Prop-content-length: 56
+Content-length: 56
+
+K 8
+svn:date
+V 27
+2006-12-26T00:04:55.850520Z
+PROPS-END
+
+Revision-number: 1
+Prop-content-length: 103
+Content-length: 103
+
+K 7
+svn:log
+V 3
+add
+K 10
+svn:author
+V 6
+jelmer
+K 8
+svn:date
+V 27
+2006-12-26T00:05:15.504335Z
+PROPS-END
+
+Node-path: x
+Node-kind: dir
+Node-action: add
+Prop-content-length: 10
+Content-length: 10
+
+PROPS-END
+
+
+Revision-number: 2
+Prop-content-length: 102
+Content-length: 102
+
+K 7
+svn:log
+V 2
+rm
+K 10
+svn:author
+V 6
+jelmer
+K 8
+svn:date
+V 27
+2006-12-26T00:05:30.775369Z
+PROPS-END
+
+Node-path: x
+Node-action: delete
+
+
+Revision-number: 3
+Prop-content-length: 105
+Content-length: 105
+
+K 7
+svn:log
+V 5
+readd
+K 10
+svn:author
+V 6
+jelmer
+K 8
+svn:date
+V 27
+2006-12-26T00:05:43.584249Z
+PROPS-END
+
+Node-path: y
+Node-kind: dir
+Node-action: add
+Node-copyfrom-rev: 1
+Node-copyfrom-path: x
+Prop-content-length: 10
+Content-length: 10
+
+PROPS-END
+
+
+Revision-number: 4
+Prop-content-length: 108
+Content-length: 108
+
+K 7
+svn:log
+V 8
+Replace
+
+K 10
+svn:author
+V 6
+jelmer
+K 8
+svn:date
+V 27
+2006-12-25T04:30:06.383777Z
+PROPS-END
+
+Node-path: y
+Node-action: delete
+
+
+Revision-number: 5
+Prop-content-length: 108
+Content-length: 108
+
+K 7
+svn:log
+V 8
+Replace
+
+K 10
+svn:author
+V 6
+jelmer
+K 8
+svn:date
+V 27
+2006-12-25T04:30:06.383777Z
+PROPS-END
+
+
+Node-path: y
+Node-kind: dir
+Node-action: add
+Node-copyfrom-rev: 1
+Node-copyfrom-path: x
+
+
+""")
+        os.mkdir("old")
+
+        load_dumpfile("dumpfile", "old")
+        oldrepos = Repository.open("old")
+        dir = BzrDir.create("f")
+        newrepos = dir.create_repository()
+        oldrepos.copy_content_into(newrepos)
+        self.assertTrue(newrepos.has_revision(
+            "svn-v%d:1@%s-" % (MAPPING_VERSION, oldrepos.uuid)))
+        self.assertTrue(newrepos.has_revision(
+            "svn-v%d:5@%s-" % (MAPPING_VERSION, oldrepos.uuid)))
+        inv1 = newrepos.get_inventory(
+                "svn-v%d:1@%s-" % (MAPPING_VERSION, oldrepos.uuid))
+        inv2 = newrepos.get_inventory(
+                "svn-v%d:5@%s-" % (MAPPING_VERSION, oldrepos.uuid))
+        self.assertNotEqual(inv1.path2id("y"), inv2.path2id("y"))
+
     # FIXME
     def notest_fetch_all(self):
         repos_url = self.make_client('d', 'dc')