Rev 2712: Implement the pack commands for knit repositories. in http://people.ubuntu.com/~robertc/baz2.0/repository
Robert Collins
robertc at robertcollins.net
Sun Aug 12 22:52:54 BST 2007
At http://people.ubuntu.com/~robertc/baz2.0/repository
------------------------------------------------------------
revno: 2712
revision-id: robertc at robertcollins.net-20070812215248-wbyd7fn23w79iy4u
parent: robertc at robertcollins.net-20070810075425-zkao68rr7t103y33
committer: Robert Collins <robertc at robertcollins.net>
branch nick: repository
timestamp: Mon 2007-08-13 07:52:48 +1000
message:
Implement the pack commands for knit repositories.
modified:
bzrlib/repofmt/knitrepo.py knitrepo.py-20070206081537-pyy4a00xdas0j4pf-1
bzrlib/tests/test_repository.py test_repository.py-20060131075918-65c555b881612f4d
=== modified file 'bzrlib/repofmt/knitrepo.py'
--- a/bzrlib/repofmt/knitrepo.py 2007-08-10 07:54:25 +0000
+++ b/bzrlib/repofmt/knitrepo.py 2007-08-12 21:52:48 +0000
@@ -325,7 +325,7 @@
return False
# XXX: the following may want to be a class, to pack with a given
# policy.
- mutter('Packing repository %s, which has %d pack files, '
+ mutter('Auto-packing repository %s, which has %d pack files, '
'containing %d revisions into %d packs.', self, total_packs,
total_revisions, self._max_pack_count(total_revisions))
# determine which packs need changing
@@ -350,23 +350,59 @@
existing_packs.append((revision_count, transport_and_name))
pack_operations = self.plan_autopack_combinations(
existing_packs, pack_distribution)
+ self._execute_pack_operations(pack_operations)
+ return True
+
+ def _execute_pack_operations(self, pack_operations):
+ """Execute a series of pack operations.
+
+ :param pack_operations: A list of [revision_count, packs_to_combine].
+ :return: None.
+ """
for revision_count, pack_details in pack_operations:
- if revision_count == 0:
+ # we may have no-ops from the setup logic
+ if len(pack_details) == 0:
continue
# have a progress bar?
self._combine_packs(pack_details)
for pack_detail in pack_details:
self._remove_pack_name(pack_detail[1])
-
# record the newly available packs and stop advertising the old
# packs
self.save()
-
# move the old packs out of the way
for revision_count, pack_details in pack_operations:
self._obsolete_packs(pack_details)
- return True
+ def pack(self):
+ """Pack the pack collection totally."""
+ self.ensure_loaded()
+ try:
+ total_packs = len(self._names)
+ if total_packs < 2:
+ return
+ if self.repo._revision_all_indices is None:
+ # trigger creation of the all revision index.
+ self.repo._revision_store.get_revision_file(self.repo.get_transaction())
+ total_revisions = len(list(self.repo._revision_all_indices.iter_all_entries()))
+ # XXX: the following may want to be a class, to pack with a given
+ # policy.
+ mutter('Packing repository %s, which has %d pack files, '
+ 'containing %d revisions into %d packs.', self, total_packs,
+ total_revisions, self._max_pack_count(total_revisions))
+ # determine which packs need changing
+ pack_distribution = [1]
+ pack_operations = [[0, []]]
+ for index, transport_and_name in self.repo._revision_pack_map.iteritems():
+ if index is None:
+ continue
+ revision_count = len(list(index.iter_all_entries()))
+ pack_operations[-1][0] += revision_count
+ pack_operations[-1][1].append(transport_and_name)
+ self._execute_pack_operations(pack_operations)
+ finally:
+ if not self.repo.is_in_write_group():
+ self.reset()
def plan_autopack_combinations(self, existing_packs, pack_distribution):
if len(existing_packs) <= len(pack_distribution):
@@ -1201,6 +1237,15 @@
return self._inv_thunk.get_weave()
@needs_write_lock
+ def pack(self):
+ """Compress the data within the repository.
+
+ This will pack all the data to a single pack. In future it may
+ recompress deltas or do other such expensive operations.
+ """
+ self._packs.pack()
+
+ @needs_write_lock
def reconcile(self, other=None, thorough=False):
"""Reconcile this repository."""
from bzrlib.reconcile import PackReconciler
@@ -1306,6 +1351,15 @@
return self._inv_thunk.get_weave()
@needs_write_lock
+ def pack(self):
+ """Compress the data within the repository.
+
+ This will pack all the data to a single pack. In future it may
+ recompress deltas or do other such expensive operations.
+ """
+ self._packs.pack()
+
+ @needs_write_lock
def reconcile(self, other=None, thorough=False):
"""Reconcile this repository."""
from bzrlib.reconcile import PackReconciler
=== modified file 'bzrlib/tests/test_repository.py'
--- a/bzrlib/tests/test_repository.py 2007-08-10 07:54:25 +0000
+++ b/bzrlib/tests/test_repository.py 2007-08-12 21:52:48 +0000
@@ -684,6 +684,18 @@
pack_names = [node[1][0] for node in index.iter_all_entries()]
self.assertTrue(large_pack_name in pack_names)
+ def test_pack_after_two_commits_packs_everything(self):
+ format = self.get_format()
+ tree = self.make_branch_and_tree('.', format=format)
+ trans = tree.branch.repository.bzrdir.get_repository_transport(None)
+ tree.commit('start')
+ tree.commit('more work')
+ tree.branch.repository.pack()
+ # there should be 1 packs:
+ index = GraphIndex(trans.clone('indices'), 'index')
+ self.assertEqual(1, len(list(index.iter_all_entries())))
+ self.assertEqual(2, len(tree.branch.repository.all_revision_ids()))
+
# TESTS TO WRITE:
# XXX: signatures must be preserved. add a test.
# XXX: packs w/o revisions are ignored by autopack
More information about the bazaar-commits
mailing list