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

Move some of the finding missing objects code to object_store.

Changeset c34d66fd9445

Parent 86f2e56a9792

by Jelmer Vernooij

Changes to 2 files · Browse files at c34d66fd9445 Showing diff from parent 86f2e56a9792 Diff from another changeset...

 
66
67
68
 
69
70
71
 
75
76
77
 
78
79
80
 
226
227
228
 
 
 
229
230
231
 
238
239
240
 
 
 
 
 
 
 
 
 
 
 
 
 
241
242
243
 
316
317
318
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
67
68
69
70
71
72
 
76
77
78
79
80
81
82
 
228
229
230
231
232
233
234
235
236
 
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
 
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
@@ -66,6 +66,7 @@
  return ObjectStoreIterator(self, shas)     def __contains__(self, sha): + """Check if a particular object is present by SHA1."""   for pack in self.packs:   if sha in pack:   return True @@ -75,6 +76,7 @@
  return False     def __iter__(self): + """Iterate over the SHAs that are present in this store."""   iterables = self.packs + [self._iter_shafile_shas()]   return itertools.chain(*iterables)   @@ -226,6 +228,9 @@
  return f, commit     def add_object(self, obj): + """Add a single object to this object store. + + """   self._add_shafile(obj.id, obj)     def add_objects(self, objects): @@ -238,6 +243,19 @@
  f, commit = self.add_pack()   write_pack_data(f, objects, len(objects))   commit() + + def find_missing_objects(self, wants, graph_walker, progress): + """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): @@ -316,3 +334,60 @@
  continue   mode, sha = obj[p]   return lookup_obj(sha) + + +class MissingObjectFinder(object): + """Find the objects missing from another object store. + + :param object_store: Object store containing at least all objects to be + sent + :param wants: SHA1s of commits to send + :param graph_walker: graph walker object used to see what the remote + repo has and misses + :param progress: Optional function to report progress to. + """ + + def __init__(self, object_store, wants, graph_walker, progress=None): + self.sha_done = set() + self.objects_to_send = set([(w, None) for w in wants]) + self.object_store = object_store + if progress is None: + self.progress = lambda x: None + else: + self.progress = progress + ref = graph_walker.next() + while ref: + if ref in self.object_store: + graph_walker.ack(ref) + ref = graph_walker.next() + + def add_todo(self, entries): + self.objects_to_send.update([e for e in entries if not e in self.sha_done]) + + def parse_tree(self, tree): + self.add_todo([(sha, name) for (mode, name, sha) in tree.entries()]) + + def parse_commit(self, commit): + self.add_todo([(commit.tree, "")]) + self.add_todo([(p, None) for p in commit.parents]) + + def parse_tag(self, tag): + self.add_todo([(tag.object[1], None)]) + + def next(self): + if not self.objects_to_send: + return None + (sha, name) = self.objects_to_send.pop() + o = self.object_store[sha] + if isinstance(o, Commit): + self.parse_commit(o) + elif isinstance(o, Tree): + self.parse_tree(o) + elif isinstance(o, Tag): + self.parse_tag(o) + self.sha_done.add((sha, name)) + self.progress("counting objects: %d\r" % len(self.sha_done)) + return (sha, name) + + +
Change 1 of 2 Show Entire File dulwich/​repo.py Stacked
 
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
 
186
187
188
 
189
190
191
192
 
 
193
194
195
 
88
89
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
92
93
 
132
133
134
135
136
137
 
 
138
139
140
141
142
@@ -88,60 +88,6 @@
  yield tuple(l.rstrip("\n").split(" ", 2))     -class MissingObjectFinder(object): - """Find the objects missing from another git repository. - - :param object_store: Object store containing at least all objects to be - sent - :param wants: SHA1s of commits to send - :param graph_walker: graph walker object used to see what the remote - repo has and misses - :param progress: Optional function to report progress to. - """ - - def __init__(self, object_store, wants, graph_walker, progress=None): - self.sha_done = set() - self.objects_to_send = set([(w, None) for w in wants]) - self.object_store = object_store - if progress is None: - self.progress = lambda x: None - else: - self.progress = progress - ref = graph_walker.next() - while ref: - if ref in self.object_store: - graph_walker.ack(ref) - ref = graph_walker.next() - - def add_todo(self, entries): - self.objects_to_send.update([e for e in entries if not e in self.sha_done]) - - def parse_tree(self, tree): - self.add_todo([(sha, name) for (mode, name, sha) in tree.entries()]) - - def parse_commit(self, commit): - self.add_todo([(commit.tree, "")]) - self.add_todo([(p, None) for p in commit.parents]) - - def parse_tag(self, tag): - self.add_todo([(tag.object[1], None)]) - - def next(self): - if not self.objects_to_send: - return None - (sha, name) = self.objects_to_send.pop() - o = self.object_store[sha] - if isinstance(o, Commit): - self.parse_commit(o) - elif isinstance(o, Tree): - self.parse_tree(o) - elif isinstance(o, Tag): - self.parse_tag(o) - self.sha_done.add((sha, name)) - self.progress("counting objects: %d\r" % len(self.sha_done)) - return (sha, name) - -  class Repo(object):   """A local git repository."""   @@ -186,10 +132,11 @@
  that a revision is present.   :param progress: Simple progress function that will be called with   updated progress strings. + :return: Iterator over (sha, path) pairs.   """   wants = determine_wants(self.get_refs()) - return iter(MissingObjectFinder(self.object_store, wants, graph_walker, - progress).next, None) + return self.object_store.find_missing_objects(wants, + graph_walker, progress)     def fetch_objects(self, determine_wants, graph_walker, progress):   """Fetch the missing objects required for a set of revisions.