Răsfoiți Sursa

compat/test_pack: add test that proves we correctly handle medium-sized objects

What I mean by "medium" in this case is that they're big enough to
require three bytes worth of length information in a copy operation,
but not big enough to require decomposing a copy operation into
multiple sequential copy operations.

Change-Id: I82c28bf8bae5c5c9ed06b79f7380bcdcf4c501e3
Augie Fackler 10 ani în urmă
părinte
comite
c07d2eb9a1
1 a modificat fișierele cu 28 adăugiri și 0 ștergeri
  1. 28 0
      dulwich/tests/compat/test_pack.py

+ 28 - 0
dulwich/tests/compat/test_pack.py

@@ -91,3 +91,31 @@ class TestPack(PackTests):
         self.assertEqual(
             3, got_non_delta,
             'Expected 3 non-delta objects, got %d' % got_non_delta)
+
+    def test_delta_medium_object(self):
+        # This tests an object set that will have a copy operation
+        # 2**20 in size.
+        orig_pack = self.get_pack(pack1_sha)
+        orig_blob = orig_pack[a_sha]
+        new_blob = Blob()
+        new_blob.data = orig_blob.data + ('x' * 2 ** 20)
+        new_blob_2 = Blob()
+        new_blob_2.data = new_blob.data + 'y'
+        all_to_pack = list(orig_pack.pack_tuples()) + [(new_blob, None),
+                                                       (new_blob_2, None)]
+        pack_path = os.path.join(self._tempdir, "pack_with_deltas")
+        write_pack(pack_path, all_to_pack, deltify=True)
+        output = run_git_or_fail(['verify-pack', '-v', pack_path])
+        self.assertEqual(set(x[0].id for x in all_to_pack),
+                         _git_verify_pack_object_list(output))
+        # We specifically made a new blob that should be a delta
+        # against the blob a_sha, so make sure we really got only 3
+        # non-delta objects:
+        got_non_delta = int(_NON_DELTA_RE.search(output).group('non_delta'))
+        self.assertEqual(
+            3, got_non_delta,
+            'Expected 3 non-delta objects, got %d' % got_non_delta)
+        # We expect one object to have a delta chain length of two
+        # (new_blob_2), so let's verify that actually happens:
+        self.assertIn('chain length = 2', output)
+