* Allow overriding paths to executables in GitSSHClient.
(Ross Light, Jelmer Vernooij, #585204)
+ * Add PackBasedObjectStore.pack_loose_objects(). (Jelmer Vernooij)
+
TESTS
* Add tests for sorted_tree_items and C implementation. (Dave Borowitz)
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."""
iterables = self.packs + [self._iter_loose_objects()]
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.
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)
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