Rev 4468: Cause StreamSink to partially pack repositories after cross format fetches when beneficial. in http://people.ubuntu.com/~robertc/baz2.0/pending/autopack-cross-format-fetch
Robert Collins
robertc at robertcollins.net
Mon Jun 22 06:27:10 BST 2009
At http://people.ubuntu.com/~robertc/baz2.0/pending/autopack-cross-format-fetch
------------------------------------------------------------
revno: 4468
revision-id: robertc at robertcollins.net-20090622052704-32rm1mbm9mgfk1v3
parent: robertc at robertcollins.net-20090622045621-plce53iif067uod1
committer: Robert Collins <robertc at robertcollins.net>
branch nick: autopack-cross-format-fetch
timestamp: Mon 2009-06-22 15:27:04 +1000
message:
Cause StreamSink to partially pack repositories after cross format fetches when beneficial.
=== modified file 'NEWS'
--- a/NEWS 2009-06-22 04:56:21 +0000
+++ b/NEWS 2009-06-22 05:27:04 +0000
@@ -83,6 +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)
+
Improvements
************
=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py 2009-06-22 02:25:09 +0000
+++ b/bzrlib/repository.py 2009-06-22 05:27:04 +0000
@@ -4047,7 +4047,10 @@
# missing keys can handle suspending a write group).
write_group_tokens = self.target_repo.suspend_write_group()
return write_group_tokens, missing_keys
- self.target_repo.commit_write_group()
+ hint = self.target_repo.commit_write_group()
+ if (to_serializer != src_serializer and
+ self.target_repo._format.pack_compresses):
+ self.target_repo.pack(hint=hint)
return [], set()
def _extract_and_insert_inventories(self, substream, serializer):
=== modified file 'bzrlib/tests/test_repository.py'
--- a/bzrlib/tests/test_repository.py 2009-06-22 04:56:21 +0000
+++ b/bzrlib/tests/test_repository.py 2009-06-22 05:27:04 +0000
@@ -1377,3 +1377,50 @@
self.assertTrue(new_pack.inventory_index._optimize_for_size)
self.assertTrue(new_pack.text_index._optimize_for_size)
self.assertTrue(new_pack.signature_index._optimize_for_size)
+
+
+class TestSinkPacks(TestCaseWithTransport):
+
+ def log_pack(self, hint=None):
+ self.calls.append(('pack', hint))
+ self.orig_pack(hint=hint)
+ if self.expect_hint:
+ self.assertTrue(hint)
+
+ def run_stream(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._get_source(target._format)
+ self.orig_pack = target.pack
+ target.pack = self.log_pack
+ search = target.search_missing_revision_ids(
+ source_tree.branch.repository, tip)
+ stream = source.get_stream(search)
+ from_format = source_tree.branch.repository._format
+ sink = target._get_sink()
+ sink.insert_stream(stream, from_format, [])
+ if expect_pack_called:
+ self.assertLength(1, self.calls)
+ else:
+ self.assertLength(0, self.calls)
+
+ def test_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):
+ # 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):
+ # When the formats are the same, pack is not called.
+ self.run_stream('2a', '2a', False)
More information about the bazaar-commits
mailing list