Use locking and write groups properly, fixes compatibility with packs.
authorJelmer Vernooij <jelmer@samba.org>
Tue, 23 Oct 2007 12:31:34 +0000 (14:31 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Tue, 23 Oct 2007 12:31:34 +0000 (14:31 +0200)
FAQ
NEWS
commit.py
fetch.py
tests/test_branch.py
tests/test_fetch.py
tests/test_push.py
tests/test_upgrade.py

diff --git a/FAQ b/FAQ
index bd2dabdd18128ad6466654776a4107bcfc6c76a1..72571296f61d993497823c3cb0769b229eda8628 100644 (file)
--- a/FAQ
+++ b/FAQ
@@ -40,6 +40,12 @@ upgrade the repository, run:
 
   $ bzr upgrade --dirstate-with-subtree
 
+or, if you would like to try the experimental packs format:
+
+::
+
+ $ bzr upgrade --experimental-subtree 
+
 ===========================================================================
 Pushing a branch that didn't exist in Subversion yet with `bzr push` fails.
 ===========================================================================
diff --git a/NEWS b/NEWS
index 4a8702c91a580301c26d8acdbe8aa4ea17c8823f..dd3b8ec2e29e12ff2d0474e8e039a5c46f043b38 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,8 @@ bzr-svn 0.4.4 UNRELEASED
 
    * Fix compatibility with 0.92.
 
+   * Fix compatibility with packs.
+
    * Handle long file names with unicode characters correctly on 
      python2.4 (#129334)
 
index 1243d5ce1c125d94c2d34771b318d5d089928c1a..47565df572a31d3119b2ee03319a61c234de59fa 100644 (file)
--- a/commit.py
+++ b/commit.py
@@ -659,16 +659,20 @@ def push(target, source, revision_id, validate=False):
     else:
         base_revid = rev.parent_ids[0]
 
-    old_tree = source.repository.revision_tree(revision_id)
-    base_tree = source.repository.revision_tree(base_revid)
-
-    builder = SvnCommitBuilder(target.repository, target, rev.parent_ids,
-                               target.get_config(), rev.timestamp,
-                               rev.timezone, rev.committer, rev.properties, 
-                               revision_id, base_tree.inventory)
-                         
-    builder.new_inventory = source.repository.get_inventory(revision_id)
-    replay_delta(builder, base_tree, old_tree)
+    source.lock_read()
+    try:
+        old_tree = source.repository.revision_tree(revision_id)
+        base_tree = source.repository.revision_tree(base_revid)
+
+        builder = SvnCommitBuilder(target.repository, target, rev.parent_ids,
+                                   target.get_config(), rev.timestamp,
+                                   rev.timezone, rev.committer, rev.properties, 
+                                   revision_id, base_tree.inventory)
+                             
+        builder.new_inventory = source.repository.get_inventory(revision_id)
+        replay_delta(builder, base_tree, old_tree)
+    finally:
+        source.unlock()
     try:
         builder.commit(rev.message)
     except SubversionException, (_, num):
index a7b5ff821c550130a6e70d55d45adf26e8410e75..bcde7d245b8d6ead5d19083a60ffb03300293c97 100644 (file)
--- a/fetch.py
+++ b/fetch.py
@@ -73,6 +73,7 @@ class RevisionBuildEditor(svn.delta.Editor):
         self._svn_revprops = svn_revprops
         self._premature_deletes = set()
         self.pool = Pool()
+        self.target.start_write_group()
 
     def _get_revision(self, revid):
         """Creates the revision object.
@@ -338,7 +339,6 @@ class RevisionBuildEditor(svn.delta.Editor):
         rev.inventory_sha1 = osutils.sha_string(
             bzrlib.xml5.serializer_v5.write_inventory_to_string(
                 self.inventory))
-        self.target.start_write_group()
         try:
             self.target.add_revision(self.revid, rev, self.inventory)
             self.target.commit_write_group()
index 777c3806b7b3f5f36eaac0c9293483731fb150bd..564354e64ca41cadc8f6f3f8f77d5fc1706d06de 100644 (file)
@@ -488,6 +488,7 @@ foohosts""")
         newbranch = newdir.open_branch()
 
         uuid = "6f95bc5c-e18d-4021-aca8-49ed51dbcb75"
+        newbranch.lock_read()
         tree = newbranch.repository.revision_tree(
                 generate_svn_revision_id(uuid, 7, "branches/foobranch", 
                 "trunk0"))
@@ -499,6 +500,7 @@ foohosts""")
             generate_svn_revision_id(uuid, 6, "branches/foobranch", "trunk0"),
             generate_svn_revision_id(uuid, 7, "branches/foobranch", "trunk0")],
                           weave.versions())
+        newbranch.unlock()
  
 
     def test_fetch_odd(self):
@@ -538,16 +540,17 @@ foohosts""")
         uuid = olddir.find_repository().uuid
         tree = newbranch.repository.revision_tree(
              generate_svn_revision_id(uuid, 6, "branches/foobranch", "trunk0"))
-
+        transaction = newbranch.repository.get_transaction()
+        newbranch.repository.lock_read()
         weave = newbranch.repository.weave_store.get_weave(
-                tree.inventory.path2id("hosts"), 
-                newbranch.repository.get_transaction())
-        self.assertEqual([
+                tree.inventory.path2id("hosts"), transaction)
+        self.assertEqual(set([
             generate_svn_revision_id(uuid, 1, "trunk", "trunk0"),
             generate_svn_revision_id(uuid, 2, "trunk", "trunk0"),
             generate_svn_revision_id(uuid, 3, "trunk", "trunk0"),
-            generate_svn_revision_id(uuid, 6, "branches/foobranch", "trunk0")],
-                          weave.versions())
+            generate_svn_revision_id(uuid, 6, "branches/foobranch", "trunk0")]),
+                          set(weave.versions()))
+        newbranch.repository.unlock()
 
     def test_check(self):
         self.make_client('d', 'dc')
index c8d4daad9c5072794014ffbcaacee3a4cd97ba11..dd7d4c473b6802b5aba05072922b3bc5bc34ee83 100644 (file)
@@ -173,11 +173,15 @@ class TestFetchWorks(TestCaseWithSubversionRepository):
             oldrepos.generate_revision_id(1, "", "none")))
         self.assertTrue(newrepos.has_revision(
             oldrepos.generate_revision_id(2, "", "none")))
-        tree = newrepos.revision_tree(
-                oldrepos.generate_revision_id(2, "", "none"))
-        self.assertTrue(tree.has_filename("foo/bla"))
-        self.assertTrue(tree.has_filename("foo"))
-        self.assertEqual("data", tree.get_file_by_path("foo/bla").read())
+        newrepos.lock_read()
+        try:
+            tree = newrepos.revision_tree(
+                    oldrepos.generate_revision_id(2, "", "none"))
+            self.assertTrue(tree.has_filename("foo/bla"))
+            self.assertTrue(tree.has_filename("foo"))
+            self.assertEqual("data", tree.get_file_by_path("foo/bla").read())
+        finally:
+            newrepos.unlock()
 
     def test_fetch_replace(self):
         repos_url = self.make_client('d', 'dc')
index 1666d1b0b8e147d284f01227730192f93742418e..01704373aec0a03f1da7e923fcbbfe43c0b1bea4 100644 (file)
@@ -344,13 +344,17 @@ class PushNewBranchTests(TestCaseWithSubversionRepository):
         repos = Repository.open(repos_url)
         wt.branch.repository.fetch(repos)
         other_rev = repos.generate_revision_id(3, "", "none")
-        merge = Merger.from_revision_ids(DummyProgress(), wt, other=other_rev)
-        merge.merge_type = Merge3Merger
-        merge.do_merge()
-        self.assertEquals(base_revid, merge.base_rev_id)
-        merge.set_pending()
-        self.assertEquals([wt.last_revision(), other_rev], wt.get_parent_ids())
-        wt.commit("merge", rev_id="mymerge")
+        wt.lock_write()
+        try:
+            merge = Merger.from_revision_ids(DummyProgress(), wt, other=other_rev)
+            merge.merge_type = Merge3Merger
+            merge.do_merge()
+            self.assertEquals(base_revid, merge.base_rev_id)
+            merge.set_pending()
+            self.assertEquals([wt.last_revision(), other_rev], wt.get_parent_ids())
+            wt.commit("merge", rev_id="mymerge")
+        finally:
+            wt.unlock()
         self.assertTrue(os.path.exists("bzrco/baz.txt"))
         raise KnownFailure("can't work for repository root")
         wt.branch.push(Branch.open(repos_url))
@@ -383,13 +387,17 @@ class PushNewBranchTests(TestCaseWithSubversionRepository):
         repos = Repository.open(repos_url)
         wt.branch.repository.fetch(repos)
         other_rev = repos.generate_revision_id(3, "trunk", "trunk0")
-        merge = Merger.from_revision_ids(DummyProgress(), wt, other=other_rev)
-        merge.merge_type = Merge3Merger
-        merge.do_merge()
-        self.assertEquals(base_revid, merge.base_rev_id)
-        merge.set_pending()
-        self.assertEquals([wt.last_revision(), other_rev], wt.get_parent_ids())
-        wt.commit("merge", rev_id="mymerge")
+        wt.lock_write()
+        try:
+            merge = Merger.from_revision_ids(DummyProgress(), wt, other=other_rev)
+            merge.merge_type = Merge3Merger
+            merge.do_merge()
+            self.assertEquals(base_revid, merge.base_rev_id)
+            merge.set_pending()
+            self.assertEquals([wt.last_revision(), other_rev], wt.get_parent_ids())
+            wt.commit("merge", rev_id="mymerge")
+        finally:
+            wt.unlock()
         self.assertTrue(os.path.exists("bzrco/baz.txt"))
         wt.branch.push(Branch.open(repos_url+"/trunk"))
 
index 98f79d5537d6d8cc67b34bf680c0488a0972d03d..a6b6cc93319913b7a22dd4e5d82a015b00464811 100644 (file)
@@ -129,8 +129,8 @@ class UpgradeTests(TestCaseWithSubversionRepository):
 
         self.assertTrue(newrepos.has_revision(oldrepos.generate_revision_id(1, "", "none")))
         self.assertTrue(newrepos.has_revision("customrev-svn%d-upgrade" % MAPPING_VERSION))
-        self.assertTrue([oldrepos.generate_revision_id(1, "", "none")],
-                        newrepos.revision_parents("customrev-svn%d-upgrade" % MAPPING_VERSION))
+        self.assertTrue((oldrepos.generate_revision_id(1, "", "none"),),
+                        tuple(newrepos.revision_parents("customrev-svn%d-upgrade" % MAPPING_VERSION)))
 
     @skip_no_rebase
     def test_single_keep_parent_fileid(self):
@@ -185,16 +185,22 @@ class UpgradeTests(TestCaseWithSubversionRepository):
 
         tree = newrepos.revision_tree("svn-v1:1@%s-" % oldrepos.uuid)
 
+        newrepos.lock_write()
+        newrepos.start_write_group()
+
         vf = newrepos.weave_store.get_weave_or_empty(tree.inventory.path2id("a"), newrepos.get_transaction())
         vf.clone_text("customrev-svn%d-upgrade" % MAPPING_VERSION,
                 "svn-v1:1@%s-" % oldrepos.uuid, ["svn-v1:1@%s-" % oldrepos.uuid])
 
+        newrepos.commit_write_group()
+        newrepos.unlock()
+
         upgrade_repository(newrepos, oldrepos, allow_changes=True)
 
         self.assertTrue(newrepos.has_revision(oldrepos.generate_revision_id(1, "", "none")))
         self.assertTrue(newrepos.has_revision("customrev-svn%d-upgrade" % MAPPING_VERSION))
-        self.assertTrue([oldrepos.generate_revision_id(1, "", "none")],
-                        newrepos.revision_parents("customrev-svn%d-upgrade" % MAPPING_VERSION))
+        self.assertTrue((oldrepos.generate_revision_id(1, "", "none"),),
+                        tuple(newrepos.revision_parents("customrev-svn%d-upgrade" % MAPPING_VERSION)))
 
     @skip_no_rebase
     def test_more_custom(self):
@@ -226,10 +232,10 @@ class UpgradeTests(TestCaseWithSubversionRepository):
         self.assertTrue(newrepos.has_revision(oldrepos.generate_revision_id(1, "", "none")))
         self.assertTrue(newrepos.has_revision("customrev-svn%d-upgrade" % MAPPING_VERSION))
         self.assertTrue(newrepos.has_revision("anotherrev-svn%d-upgrade" % MAPPING_VERSION))
-        self.assertTrue([oldrepos.generate_revision_id(1, "", "none")],
-                        newrepos.revision_parents("customrev-svn%d-upgrade" % MAPPING_VERSION))
-        self.assertTrue(["customrev-svn%d-upgrade" % MAPPING_VERSION],
-                        newrepos.revision_parents("anotherrev-svn%d-upgrade" % MAPPING_VERSION))
+        self.assertTrue((oldrepos.generate_revision_id(1, "", "none"),),
+                        tuple(newrepos.revision_parents("customrev-svn%d-upgrade" % MAPPING_VERSION)))
+        self.assertTrue(("customrev-svn%d-upgrade" % MAPPING_VERSION,),
+                        tuple(newrepos.revision_parents("anotherrev-svn%d-upgrade" % MAPPING_VERSION)))
 
     @skip_no_rebase
     def test_more_custom_branch(self):