Rev 2711: Finish autopack corner cases. in http://people.ubuntu.com/~robertc/baz2.0/repository

Robert Collins robertc at robertcollins.net
Fri Aug 10 08:54:27 BST 2007


At http://people.ubuntu.com/~robertc/baz2.0/repository

------------------------------------------------------------
revno: 2711
revision-id: robertc at robertcollins.net-20070810075425-zkao68rr7t103y33
parent: robertc at robertcollins.net-20070810063212-a25zyg08g7ws7qxw
committer: Robert Collins <robertc at robertcollins.net>
branch nick: repository
timestamp: Fri 2007-08-10 17:54:25 +1000
message:
  Finish autopack corner cases.
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 06:32:12 +0000
+++ b/bzrlib/repofmt/knitrepo.py	2007-08-10 07:54:25 +0000
@@ -348,6 +348,29 @@
                 # a matching distribution.
                 continue
             existing_packs.append((revision_count, transport_and_name))
+        pack_operations = self.plan_autopack_combinations(
+            existing_packs, pack_distribution)
+        for revision_count, pack_details in pack_operations:
+            if revision_count == 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 plan_autopack_combinations(self, existing_packs, pack_distribution):
+        if len(existing_packs) <= len(pack_distribution):
+            return []
         existing_packs.sort(reverse=True)
         pack_operations = [[0, []]]
         # plan out what packs to keep, and what to reorganise
@@ -358,9 +381,16 @@
             # distribution chart
             next_pack_rev_count, next_pack_details = existing_packs.pop(0)
             if next_pack_rev_count >= pack_distribution[0]:
-                # don't shrink packs, we want to aggregate them
-                #raise NotImplementedError
-                return False
+                # this is already packed 'better' than this, so we can
+                # not waste time packing it.
+                while next_pack_rev_count > 0:
+                    next_pack_rev_count -= pack_distribution[0]
+                    if next_pack_rev_count >= 0:
+                        # more to go
+                        del pack_distribution[0]
+                    else:
+                        # didn't use that entire bucket up
+                        pack_distribution[0] = -next_pack_rev_count
             else:
                 # add the revisions we're going to add to the next output pack
                 pack_operations[-1][0] += next_pack_rev_count
@@ -370,24 +400,8 @@
                     # this pack is used up, shift left.
                     del pack_distribution[0]
                     pack_operations.append([0, []])
-
-        for revision_count, pack_details in pack_operations:
-            if revision_count == 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
+        
+        return pack_operations
 
     def _combine_packs(self, pack_details):
         """Combine the data from the packs listed in pack_details.
@@ -1173,7 +1187,7 @@
             if not self._packs.autopack():
                 self._packs.save()
         else:
-            # can the pending upload
+            # remove the pending upload
             self._upload_transport.delete(self._open_pack_tuple[1])
         self._revision_store.reset()
         self.weave_store.reset()
@@ -1278,7 +1292,7 @@
             if not self._packs.autopack():
                 self._packs.save()
         else:
-            # can the pending upload
+            # remove the pending upload
             self._upload_transport.delete(self._open_pack_tuple[1])
         self._revision_store.reset()
         self.weave_store.reset()

=== modified file 'bzrlib/tests/test_repository.py'
--- a/bzrlib/tests/test_repository.py	2007-08-10 06:32:12 +0000
+++ b/bzrlib/tests/test_repository.py	2007-08-10 07:54:25 +0000
@@ -774,6 +774,37 @@
         self.assertEqual([100, 100, 1], packs.pack_distribution(201))
         self.assertEqual([100, 100, 10, 1], packs.pack_distribution(211))
 
+    def test_plan_pack_operations_2009_revisions_skip_all_packs(self):
+        format = self.get_format()
+        repo = self.make_repository('.', format=format)
+        packs = repo._packs
+        existing_packs = [(2000, "big"), (9, "medium")]
+        # rev count - 2009 -> 2x1000 + 9x1
+        pack_operations = packs.plan_autopack_combinations(
+            existing_packs, [1000, 1000, 1, 1, 1, 1, 1, 1, 1, 1, 1])
+        self.assertEqual([], pack_operations)
+
+    def test_plan_pack_operations_2010_revisions_skip_all_packs(self):
+        format = self.get_format()
+        repo = self.make_repository('.', format=format)
+        packs = repo._packs
+        existing_packs = [(2000, "big"), (9, "medium"), (1, "single")]
+        # rev count - 2010 -> 2x1000 + 1x10
+        pack_operations = packs.plan_autopack_combinations(
+            existing_packs, [1000, 1000, 10])
+        self.assertEqual([], pack_operations)
+
+    def test_plan_pack_operations_2010_combines_smallest_two(self):
+        format = self.get_format()
+        repo = self.make_repository('.', format=format)
+        packs = repo._packs
+        existing_packs = [(1999, "big"), (9, "medium"), (1, "single2"),
+            (1, "single1")]
+        # rev count - 2010 -> 2x1000 + 1x10 (3)
+        pack_operations = packs.plan_autopack_combinations(
+            existing_packs, [1000, 1000, 10])
+        self.assertEqual([[2, ["single2", "single1"]], [0, []]], pack_operations)
+
 
 class TestExperimentalSubtrees(TestExperimentalNoSubtrees):
 



More information about the bazaar-commits mailing list