Rev 2949: * Obsolete packs are now cleaned up by pack and autopack operations. in http://people.ubuntu.com/~robertc/baz2.0/pack-unlink-old-packs

Robert Collins robertc at robertcollins.net
Mon Oct 29 20:45:31 GMT 2007


At http://people.ubuntu.com/~robertc/baz2.0/pack-unlink-old-packs

------------------------------------------------------------
revno: 2949
revision-id:robertc at robertcollins.net-20071029204506-19todg20tf48abis
parent: pqm at pqm.ubuntu.com-20071029050400-j2jmz8smj2yecfrr
committer: Robert Collins <robertc at robertcollins.net>
branch nick: pack-unlink-old-packs
timestamp: Tue 2007-10-30 07:45:06 +1100
message:
  * Obsolete packs are now cleaned up by pack and autopack operations.
    (Robert Collins, #153789)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/repofmt/pack_repo.py    pack_repo.py-20070813041115-gjv5ma7ktfqwsjgn-1
  bzrlib/tests/test_repository.py test_repository.py-20060131075918-65c555b881612f4d
=== modified file 'NEWS'
--- a/NEWS	2007-10-26 08:56:09 +0000
+++ b/NEWS	2007-10-29 20:45:06 +0000
@@ -121,6 +121,9 @@
    * Make sure to use ``O_BINARY`` when opening files to check their
      sha1sum. (Alexander Belchenko, John Arbash Meinel, #153493)
 
+   * Obsolete packs are now cleaned up by pack and autopack operations.
+     (Robert Collins, #153789)
+
    * Fix a problem with Win32 handling of the executable bit.
      (John Arbash Meinel, #149113)
 

=== modified file 'bzrlib/repofmt/pack_repo.py'
--- a/bzrlib/repofmt/pack_repo.py	2007-10-29 04:00:19 +0000
+++ b/bzrlib/repofmt/pack_repo.py	2007-10-29 20:45:06 +0000
@@ -751,7 +751,7 @@
                 self._remove_pack_from_memory(pack)
         # record the newly available packs and stop advertising the old
         # packs
-        self._save_pack_names()
+        self._save_pack_names(clear_obsolete_packs=True)
         # Move the old packs out of the way now they are no longer referenced.
         for revision_count, packs in pack_operations:
             self._obsolete_packs(packs)
@@ -1136,13 +1136,16 @@
         """Release the mutex around the pack-names index."""
         self.repo.control_files.unlock()
 
-    def _save_pack_names(self):
+    def _save_pack_names(self, clear_obsolete_packs=False):
         """Save the list of packs.
 
         This will take out the mutex around the pack names list for the
         duration of the method call. If concurrent updates have been made, a
         three-way merge between the current list and the current in memory list
         is performed.
+
+        :param clear_obsolete_packs: If True, clear out the contents of the
+            obsolete_packs directory.
         """
         self.lock_names()
         try:
@@ -1168,6 +1171,10 @@
             self.transport.put_file('pack-names', builder.finish())
             # move the baseline forward
             self._packs_at_load = disk_nodes
+            # now clear out the obsolete packs directory
+            if clear_obsolete_packs:
+                self.transport.clone('obsolete_packs').delete_multi(
+                    self.transport.list_dir('obsolete_packs'))
         finally:
             self._unlock_names()
         # synchronise the memory packs list with what we just wrote:

=== modified file 'bzrlib/tests/test_repository.py'
--- a/bzrlib/tests/test_repository.py	2007-10-25 07:34:32 +0000
+++ b/bzrlib/tests/test_repository.py	2007-10-29 20:45:06 +0000
@@ -888,6 +888,9 @@
         # there should be 9 packs:
         index = GraphIndex(trans, 'pack-names', None)
         self.assertEqual(9, len(list(index.iter_all_entries())))
+        # insert some files in obsolete_packs which should be removed by pack.
+        trans.put_bytes('obsolete_packs/foo', '123')
+        trans.put_bytes('obsolete_packs/bar', '321')
         # committing one more should coalesce to 1 of 10.
         tree.commit('commit triggering pack')
         index = GraphIndex(trans, 'pack-names', None)
@@ -896,6 +899,11 @@
         tree = tree.bzrdir.open_workingtree()
         check_result = tree.branch.repository.check(
             [tree.branch.last_revision()])
+        # We should have 50 (10x5) files in the obsolete_packs directory.
+        obsolete_files = list(trans.list_dir('obsolete_packs'))
+        self.assertFalse('foo' in obsolete_files)
+        self.assertFalse('bar' in obsolete_files)
+        self.assertEqual(50, len(obsolete_files))
         # XXX: Todo check packs obsoleted correctly - old packs and indices
         # in the obsolete_packs directory.
         large_pack_name = list(index.iter_all_entries())[0][1][0]



More information about the bazaar-commits mailing list