Changeset 1637a77fa457…
Parent 7640d2b4051f…
by
Changes to 3 files · Browse files at 1637a77fa457 Showing diff from parent 7640d2b4051f Diff from another changeset...
@@ -20,6 +20,8 @@
* Allow overriding paths to executables in GitSSHClient.
(Ross Light, Jelmer Vernooij, #585204)
+
+ * Add PackBasedObjectStore.pack_loose_objects(). (Jelmer Vernooij)
TESTS
|
@@ -272,10 +272,27 @@ return self._pack_cache
def _iter_loose_objects(self):
+ """Iterate over the SHAs of all loose objects."""
raise NotImplementedError(self._iter_loose_objects)
def _get_loose_object(self, sha):
raise NotImplementedError(self._get_loose_object)
+
+ def _remove_loose_object(self, sha):
+ raise NotImplementedError(self._remove_loose_object)
+
+ def pack_loose_objects(self):
+ """Pack loose objects.
+
+ :return: Number of objects packed
+ """
+ objects = set()
+ for sha in self._iter_loose_objects():
+ objects.add((self._get_loose_object(sha), None))
+ self.add_objects(objects)
+ for obj, path in objects:
+ self._remove_loose_object(obj.id)
+ return len(objects)
def __iter__(self):
"""Iterate over the SHAs that are present in this store."""
@@ -385,6 +402,9 @@ return None
raise
+ def _remove_loose_object(self, sha):
+ os.remove(self._get_shafile_path(sha))
+
def move_in_thin_pack(self, path):
"""Move a specific file containing a pack into the pack directory.
|
@@ -83,7 +83,25 @@ self.store = MemoryObjectStore()
-class DiskObjectStoreTests(ObjectStoreTests, TestCase):
+class PackBasedObjectStoreTests(ObjectStoreTests):
+
+ def test_empty_packs(self):
+ o = DiskObjectStore(self.store_dir)
+ self.assertEquals([], o.packs)
+
+ def test_pack_loose_objects(self):
+ o = DiskObjectStore(self.store_dir)
+ b1 = make_object(Blob, data="yummy data")
+ o.add_object(b1)
+ b2 = make_object(Blob, data="more yummy data")
+ o.add_object(b2)
+ self.assertEquals([], o.packs)
+ self.assertEquals(2, o.pack_loose_objects())
+ self.assertNotEquals([], o.packs)
+ self.assertEquals(0, o.pack_loose_objects())
+
+
+class DiskObjectStoreTests(PackBasedObjectStoreTests, TestCase):
def setUp(self):
TestCase.setUp(self)
@@ -98,9 +116,4 @@ o = DiskObjectStore(self.store_dir)
self.assertEquals(os.path.join(self.store_dir, "pack"), o.pack_dir)
- def test_empty_packs(self):
- o = DiskObjectStore(self.store_dir)
- self.assertEquals([], o.packs)
-
-
# TODO: MissingObjectFinderTests
|
Loading...