Rev 5166: (lifeless) Add --clean-obsolete-packs option to the pack command. (Parth Malwankar) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Apr 20 01:17:00 BST 2010


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5166 [merge]
revision-id: pqm at pqm.ubuntu.com-20100420001656-qq6or4qe130cvtlk
parent: pqm at pqm.ubuntu.com-20100419052704-s2a31e5qdj5spbx9
parent: parth.malwankar at gmail.com-20100419130430-njvxdaka6xbqwvjw
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2010-04-20 01:16:56 +0100
message:
  (lifeless) Add --clean-obsolete-packs option to the pack command. (Parth Malwankar)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
  bzrlib/repofmt/pack_repo.py    pack_repo.py-20070813041115-gjv5ma7ktfqwsjgn-1
  bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
  bzrlib/tests/blackbox/test_pack.py test_pack.py-20070712120702-0c7585lh56p894mo-1
=== modified file 'NEWS'
--- a/NEWS	2010-04-16 13:39:50 +0000
+++ b/NEWS	2010-04-19 13:04:30 +0000
@@ -19,6 +19,11 @@
 * ``bzr diff`` now supports a --format option, which can be used to 
   select alternative diff formats. (Jelmer Vernooij, #555994)
 
+* ``bzr pack`` now supports a ``--clean-obsolete-packs`` option that
+  can save disk space by deleting obsolete pack files created during the
+  pack operation.
+  (Parth Malwankar, #304320)
+
 Bug Fixes
 *********
 

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2010-04-15 15:03:15 +0000
+++ b/bzrlib/builtins.py	2010-04-19 13:04:30 +0000
@@ -4426,19 +4426,38 @@
 
 
 class cmd_pack(Command):
-    """Compress the data within a repository."""
+    """Compress the data within a repository.
+
+    This operation compresses the data within a bazaar repository. As
+    bazaar supports automatic packing of repository, this operation is
+    normally not required to be done manually.
+
+    During the pack operation, bazaar takes a backup of existing repository
+    data, i.e. pack files. This backup is eventually removed by bazaar
+    automatically when it is safe to do so. To save disk space by removing
+    the backed up pack files, the --clean-obsolete-packs option may be
+    used.
+
+    Warning: If you use --clean-obsolete-packs and your machine crashes
+    during or immediately after repacking, you may be left with a state
+    where the deletion has been written to disk but the new packs have not
+    been. In this case the repository may be unusable.
+    """
 
     _see_also = ['repositories']
     takes_args = ['branch_or_repo?']
+    takes_options = [
+        Option('clean-obsolete-packs', 'Delete obsolete packs to save disk space.'),
+        ]
 
-    def run(self, branch_or_repo='.'):
+    def run(self, branch_or_repo='.', clean_obsolete_packs=False):
         dir = bzrdir.BzrDir.open_containing(branch_or_repo)[0]
         try:
             branch = dir.open_branch()
             repository = branch.repository
         except errors.NotBranchError:
             repository = dir.open_repository()
-        repository.pack()
+        repository.pack(clean_obsolete_packs=clean_obsolete_packs)
 
 
 class cmd_plugins(Command):

=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2010-03-21 21:39:33 +0000
+++ b/bzrlib/remote.py	2010-04-19 13:04:30 +0000
@@ -1595,13 +1595,13 @@
         return self._real_repository.inventories
 
     @needs_write_lock
-    def pack(self, hint=None):
+    def pack(self, hint=None, clean_obsolete_packs=False):
         """Compress the data within the repository.
 
         This is not currently implemented within the smart server.
         """
         self._ensure_real()
-        return self._real_repository.pack(hint=hint)
+        return self._real_repository.pack(hint=hint, clean_obsolete_packs=clean_obsolete_packs)
 
     @property
     def revisions(self):

=== modified file 'bzrlib/repofmt/pack_repo.py'
--- a/bzrlib/repofmt/pack_repo.py	2010-03-17 11:37:38 +0000
+++ b/bzrlib/repofmt/pack_repo.py	2010-04-19 13:04:30 +0000
@@ -1560,7 +1560,7 @@
         """Is the collection already packed?"""
         return not (self.repo._format.pack_compresses or (len(self._names) > 1))
 
-    def pack(self, hint=None):
+    def pack(self, hint=None, clean_obsolete_packs=False):
         """Pack the pack collection totally."""
         self.ensure_loaded()
         total_packs = len(self._names)
@@ -1582,6 +1582,9 @@
                 pack_operations[-1][1].append(pack)
         self._execute_pack_operations(pack_operations, OptimisingPacker)
 
+        if clean_obsolete_packs:
+            self._clear_obsolete_packs()
+
     def plan_autopack_combinations(self, existing_packs, pack_distribution):
         """Plan a pack operation.
 
@@ -2375,13 +2378,13 @@
         raise NotImplementedError(self.dont_leave_lock_in_place)
 
     @needs_write_lock
-    def pack(self, hint=None):
+    def pack(self, hint=None, clean_obsolete_packs=False):
         """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._pack_collection.pack(hint=hint)
+        self._pack_collection.pack(hint=hint, clean_obsolete_packs=clean_obsolete_packs)
 
     @needs_write_lock
     def reconcile(self, other=None, thorough=False):

=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2010-04-10 18:03:54 +0000
+++ b/bzrlib/repository.py	2010-04-19 13:04:30 +0000
@@ -2581,7 +2581,7 @@
             keys = tsort.topo_sort(parent_map)
         return [None] + list(keys)
 
-    def pack(self, hint=None):
+    def pack(self, hint=None, clean_obsolete_packs=False):
         """Compress the data within the repository.
 
         This operation only makes sense for some repository types. For other
@@ -2597,6 +2597,9 @@
             obtained from the result of commit_write_group(). Out of
             date hints are simply ignored, because concurrent operations
             can obsolete them rapidly.
+
+        :param clean_obsolete_packs: Clean obsolete packs immediately after
+            the pack operation.
         """
 
     def get_transaction(self):

=== modified file 'bzrlib/tests/blackbox/test_pack.py'
--- a/bzrlib/tests/blackbox/test_pack.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/blackbox/test_pack.py	2010-03-25 08:20:15 +0000
@@ -16,12 +16,33 @@
 #
 
 """Tests of the 'bzr pack' command."""
+import os
 
 from bzrlib.tests.blackbox import ExternalBase
+from bzrlib.workingtree import WorkingTree
 
 
 class TestPack(ExternalBase):
 
+    def _make_versioned_file(self, path, line_prefix='line', total_lines=10):
+        self._make_file(path, line_prefix, total_lines, versioned=True)
+
+    def _make_file(self, path, line_prefix, total_lines, versioned):
+        text=''
+        for i in range(total_lines):
+            text += line_prefix + str(i+1) + "\n"
+
+        open(path, 'w').write(text)
+        if versioned:
+            self.run_bzr(['add', path])
+            self.run_bzr(['ci', '-m', '"' + path + '"'])
+
+    def _update_file(self, path, text, checkin=True):
+        """append text to file 'path' and check it in"""
+        open(path, 'a').write(text)
+        if checkin:
+            self.run_bzr(['ci', path, '-m', '"' + path + '"'])
+
     def test_pack_silent(self):
         """pack command has no intrinsic output."""
         self.make_branch('.')
@@ -42,3 +63,22 @@
         out, err = self.run_bzr('pack repository')
         self.assertEqual('', out)
         self.assertEqual('', err)
+
+    def test_pack_clean_obsolete_packs(self):
+        """Ensure --clean-obsolete-packs removes obsolete pack files
+        """
+        wd = 'foobar0'
+        wt = self.make_branch_and_tree(wd)
+        transport = wt.branch.repository.bzrdir.transport
+        os.chdir(wd)
+
+        # do multiple commits to ensure that obsolete packs are created
+        # by 'bzr pack'
+        self._make_versioned_file('file0.txt')
+        for i in range(5):
+            self._update_file('file0.txt', 'HELLO %d\n' % i)
+
+        out, err = self.run_bzr(['pack', '--clean-obsolete-packs'])
+
+        pack_names = transport.list_dir('repository/obsolete_packs')
+        self.assertTrue(len(pack_names) == 0)




More information about the bazaar-commits mailing list