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

Add base class for ObjectStore with just the interface.

Changeset 9766154d0437

Parent e603229a17a9

by Jelmer Vernooij

Changes to 2 files · Browse files at 9766154d0437 Showing diff from parent e603229a17a9 Diff from another changeset...

Change 1 of 1 Show Entire File dulwich/​client.py Stacked
 
148
149
150
151
 
152
153
154
 
148
149
150
 
151
152
153
154
@@ -148,7 +148,7 @@
    # read the final confirmation sha   client_sha = self.proto.read(20) - if not client_sha in (None, sha) + if not client_sha in (None, sha):   raise ChecksumMismatch(sha, client_sha)     return changed_refs
 
50
51
52
53
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
56
57
 
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
 
157
158
159
160
161
162
163
164
165
166
 
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
 
50
51
52
 
 
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
 
123
124
125
 
 
 
 
 
 
 
 
 
 
126
127
128
 
209
210
211
 
 
 
 
212
213
214
 
299
300
301
 
 
 
 
 
 
 
 
 
 
 
 
302
303
304
@@ -50,8 +50,70 @@
   PACKDIR = 'pack'   -class ObjectStore(object): - """Object store.""" + +class BaseObjectStore(object): + """Object store interface.""" + + def determine_wants_all(self, refs): + return [sha for (ref, sha) in refs.iteritems() if not sha in self and not ref.endswith("^{}")] + + def iter_shas(self, shas): + """Iterate over the objects for the specified shas. + + :param shas: Iterable object with SHAs + """ + return ObjectStoreIterator(self, shas) + + def __contains__(self, sha): + """Check if a particular object is present by SHA1.""" + raise NotImplementedError(self.__contains__) + + 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. + """ + raise NotImplementedError(self.get_raw) + + def __getitem__(self, sha): + """Obtain an object by SHA1.""" + type, uncomp = self.get_raw(sha) + return ShaFile.from_raw_string(type, uncomp) + + def __iter__(self): + """Iterate over the SHAs that are present in this store.""" + raise NotImplementedError(self.__iter__) + + def add_object(self, obj): + """Add a single object to this object store. + + """ + raise NotImplementedError(self.add_object) + + def add_objects(self, objects): + """Add a set of objects to this object store. + + :param objects: Iterable over a list of objects. + """ + raise NotImplementedError(self.add_objects) + + def find_missing_objects(self, wants, graph_walker, progress=None): + """Find the missing objects required for a set of revisions. + + :param wants: Iterable over SHAs of objects to fetch. + :param graph_walker: Object that can iterate over the list of revisions + to fetch and has an "ack" method that will be called to acknowledge + that a revision is present. + :param progress: Simple progress function that will be called with + updated progress strings. + :return: Iterator over (sha, path) pairs. + """ + return iter(MissingObjectFinder(self, wants, graph_walker, progress).next, None) + + +class ObjectStore(BaseObjectStore): + """Git-style object store that exists on disk."""     def __init__(self, path):   """Open an object store. @@ -61,16 +123,6 @@
  self.path = path   self._pack_cache = None   self.pack_dir = os.path.join(self.path, PACKDIR) - - def determine_wants_all(self, refs): - return [sha for (ref, sha) in refs.iteritems() if not sha in self and not ref.endswith("^{}")] - - def iter_shas(self, shas): - """Iterate over the objects for the specified shas. - - :param shas: Iterable object with SHAs - """ - return ObjectStoreIterator(self, shas)     def __contains__(self, sha):   """Check if a particular object is present by SHA1.""" @@ -157,10 +209,6 @@
  return ret.type, ret.as_raw_string()   raise KeyError(hexsha)   - def __getitem__(self, sha): - type, uncomp = self.get_raw(sha) - return ShaFile.from_raw_string(type, uncomp) -   def move_in_thin_pack(self, path):   """Move a specific file containing a pack into the pack directory.   @@ -251,18 +299,6 @@
  write_pack_data(f, objects, len(objects))   commit()   - def find_missing_objects(self, wants, graph_walker, progress=None): - """Find the missing objects required for a set of revisions. - - :param wants: Iterable over SHAs of objects to fetch. - :param graph_walker: Object that can iterate over the list of revisions - to fetch and has an "ack" method that will be called to acknowledge - that a revision is present. - :param progress: Simple progress function that will be called with - updated progress strings. - :return: Iterator over (sha, path) pairs. - """ - return iter(MissingObjectFinder(self, wants, graph_walker, progress).next, None)      class ObjectImporter(object):