Kiln » Dependencies » Dulwich Read More
Clone URL:  
Pushed to one repository · View In Graph Contained in master

Add MemoryObjectStore.

Changeset f280b90eb105

Parent 43ee2c4e9b91

by Jelmer Vernooij

Changes to 4 files · Browse files at f280b90eb105 Showing diff from parent 43ee2c4e9b91 Diff from another changeset...

Change 1 of 1 Show Entire File dulwich/​index.py Stacked
 
126
127
128
129
 
130
131
132
 
126
127
128
 
129
130
131
132
@@ -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
113
114
115
 
116
117
118
 
300
301
302
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
303
304
305
 
112
113
114
 
115
116
117
118
 
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
@@ -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."""
Change 1 of 2 Show Entire File dulwich/​repo.py Stacked
 
31
32
33
34
 
35
36
37
 
163
164
165
166
 
167
168
169
 
31
32
33
 
34
35
36
37
 
163
164
165
 
166
167
168
169
@@ -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
19
20
21
 
 
 
 
22
23
 
24
25
26
 
27
28
29
30
 
31
32
33
34
 
35
36
37
38
 
39
40
41
 
 
 
 
 
 
 
 
18
19
20
 
21
22
23
24
25
 
26
27
28
 
29
30
31
32
 
33
34
35
36
 
37
38
39
40
 
41
42
43
44
45
46
47
48
49
50
51
@@ -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))