Rev 4469: Both StreamSink and InterDifferingSerialiser now pack after fetching when it is beneficial in http://people.ubuntu.com/~robertc/baz2.0/pending/autopack-cross-format-fetch

Robert Collins robertc at robertcollins.net
Mon Jun 22 07:15:05 BST 2009


At http://people.ubuntu.com/~robertc/baz2.0/pending/autopack-cross-format-fetch

------------------------------------------------------------
revno: 4469
revision-id: robertc at robertcollins.net-20090622061438-3v9hl1pe2ph72ik4
parent: robertc at robertcollins.net-20090622052704-32rm1mbm9mgfk1v3
committer: Robert Collins <robertc at robertcollins.net>
branch nick: autopack-cross-format-fetch
timestamp: Mon 2009-06-22 16:14:38 +1000
message:
  Both StreamSink and InterDifferingSerialiser now pack after fetching when it is beneficial
=== modified file 'NEWS'
--- a/NEWS	2009-06-22 05:27:04 +0000
+++ b/NEWS	2009-06-22 06:14:38 +0000
@@ -83,10 +83,11 @@
   when doing a pack operation changes the compression of content in the
   repository. (Robert Collins)
 
-* ``StreamSink`` will call ``Repository.pack`` with the hint returned
-  by ``Repository.commit_write_group`` if the formats were different and
-  the repository can increase compression by doing a pack operation.
-  (Robert Collins, partial fix for #376748)
+* ``StreamSink`` and ``InterDifferingSerialiser`` will call
+  ``Repository.pack`` with the hint returned by
+  ``Repository.commit_write_group`` if the formats were different and the
+  repository can increase compression by doing a pack operation.
+  (Robert Collins, #376748)
 
 Improvements
 ************

=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2009-06-22 05:27:04 +0000
+++ b/bzrlib/repository.py	2009-06-22 06:14:38 +0000
@@ -3688,6 +3688,7 @@
         cache = lru_cache.LRUCache(100)
         cache[basis_id] = basis_tree
         del basis_tree # We don't want to hang on to it here
+        hints = []
         for offset in range(0, len(revision_ids), batch_size):
             self.target.start_write_group()
             try:
@@ -3699,7 +3700,11 @@
                 self.target.abort_write_group()
                 raise
             else:
-                self.target.commit_write_group()
+                hint = self.target.commit_write_group()
+                if hint:
+                    hints.extend(hint)
+        if hints and self.target._format.pack_compresses:
+            self.target.pack(hint=hints)
         pb.update('Transferring revisions', len(revision_ids),
                   len(revision_ids))
 

=== modified file 'bzrlib/tests/test_repository.py'
--- a/bzrlib/tests/test_repository.py	2009-06-22 05:27:04 +0000
+++ b/bzrlib/tests/test_repository.py	2009-06-22 06:14:38 +0000
@@ -1379,7 +1379,7 @@
         self.assertTrue(new_pack.signature_index._optimize_for_size)
 
 
-class TestSinkPacks(TestCaseWithTransport):
+class TestCrossFormatPacks(TestCaseWithTransport):
 
     def log_pack(self, hint=None):
         self.calls.append(('pack', hint))
@@ -1411,16 +1411,49 @@
         else:
             self.assertLength(0, self.calls)
 
-    def test_format_hint_no(self):
+    def run_fetch(self, src_fmt, target_fmt, expect_pack_called):
+        self.expect_hint = expect_pack_called
+        self.calls = []
+        source_tree = self.make_branch_and_tree('src', format=src_fmt)
+        source_tree.lock_write()
+        self.addCleanup(source_tree.unlock)
+        tip = source_tree.commit('foo')
+        target = self.make_repository('target', format=target_fmt)
+        target.lock_write()
+        self.addCleanup(target.unlock)
+        source = source_tree.branch.repository
+        self.orig_pack = target.pack
+        target.pack = self.log_pack
+        target.fetch(source)
+        if expect_pack_called:
+            self.assertLength(1, self.calls)
+        else:
+            self.assertLength(0, self.calls)
+
+    def test_sink_format_hint_no(self):
         # When the target format says packing makes no difference, pack is not
         # called.
         self.run_stream('1.9', 'rich-root-pack', False)
 
-    def test_format_hint_yes(self):
+    def test_sink_format_hint_yes(self):
         # When the target format says packing makes a difference, pack is
         # called.
         self.run_stream('1.9', '2a', True)
 
-    def test_format_same_no(self):
+    def test_sink_format_same_no(self):
         # When the formats are the same, pack is not called.
         self.run_stream('2a', '2a', False)
+
+    def test_IDS_format_hint_no(self):
+        # When the target format says packing makes no difference, pack is not
+        # called.
+        self.run_fetch('1.9', 'rich-root-pack', False)
+
+    def test_IDS_format_hint_yes(self):
+        # When the target format says packing makes a difference, pack is
+        # called.
+        self.run_fetch('1.9', '2a', True)
+
+    def test_IDS_format_same_no(self):
+        # When the formats are the same, pack is not called.
+        self.run_fetch('2a', '2a', False)




More information about the bazaar-commits mailing list