Changeset f280b90eb105…
Parent 43ee2c4e9b91…
by
Changes to 4 files · Browse files at f280b90eb105 Showing diff from parent 43ee2c4e9b91 Diff from another changeset...
@@ -126,7 +126,7 @@
def cleanup_mode(mode):
- if stat.S_ISLNK(fsmode)
+ if stat.S_ISLNK(fsmode):
mode = stat.S_IFLNK
else:
mode = stat.S_IFREG
|
@@ -112,7 +112,7 @@ return iter(MissingObjectFinder(self, wants, graph_walker, progress).next, None)
-class ObjectStore(BaseObjectStore):
+class DiskObjectStore(BaseObjectStore):
"""Git-style object store that exists on disk."""
def __init__(self, path):
@@ -300,6 +300,41 @@ commit()
+class MemoryObjectStore(BaseObjectStore):
+
+ def __init__(self):
+ super(MemoryObjectStore, self).__init__()
+ self._data = {}
+
+ def __contains__(self, sha):
+ return sha in self._data
+
+ def __iter__(self):
+ """Iterate over the SHAs that are present in this store."""
+ return self._data.iterkeys()
+
+ def get_raw(self, name):
+ """Obtain the raw text for an object.
+
+ :param name: sha for the object.
+ :return: tuple with object type and object contents.
+ """
+ return self[sha].as_raw_string()
+
+ def add_object(self, obj):
+ """Add a single object to this object store.
+
+ """
+ self._dict[obj.id] = obj
+
+ def add_objects(self, objects):
+ """Add a set of objects to this object store.
+
+ :param objects: Iterable over a list of objects.
+ """
+ for obj in objects:
+ self._data[obj.id] = obj
+
class ObjectImporter(object):
"""Interface for importing objects."""
|
@@ -31,7 +31,7 @@ NotTreeError,
)
from dulwich.object_store import (
- ObjectStore,
+ DiskObjectStore,
)
from dulwich.objects import (
Blob,
@@ -163,7 +163,7 @@ @property
def object_store(self):
if self._object_store is None:
- self._object_store = ObjectStore(self.object_dir())
+ self._object_store = DiskObjectStore(self.object_dir())
return self._object_store
def pack_dir(self):
|
@@ -18,24 +18,34 @@
from unittest import TestCase
-from dulwich.object_store import ObjectStore
+from dulwich.object_store import (
+ DiskObjectStore,
+ MemoryObjectStore,
+ )
-class ObjectStoreTests(TestCase):
+class DiskObjectStoreTests(TestCase):
def test_pack_dir(self):
- o = ObjectStore("foo")
+ o = DiskObjectStore("foo")
self.assertEquals("foo/pack", o.pack_dir)
def test_empty_packs(self):
- o = ObjectStore("foo")
+ o = DiskObjectStore("foo")
self.assertEquals([], o.packs)
def test_add_objects_empty(self):
- o = ObjectStore("foo")
+ o = DiskObjectStore("foo")
o.add_objects([])
def test_add_commit(self):
- o = ObjectStore("foo")
+ o = DiskObjectStore("foo")
# TODO: Argh, no way to construct Git commit objects without
# access to a serialized form.
o.add_objects([])
+
+
+class MemoryObjectStoreTests(TestCase):
+
+ def test_iter(self):
+ store = MemoryObjectStore()
+ self.assertEquals([], list(store))
|
Loading...