Kiln » Dependencies » Dulwich Read More
Clone URL:  
Pushed to one repository · View In Graph Contained in master-1, master-0, and 0.9.4

Add abort return value to ObjectStore.add_pack.

Changeset 9e63bab0fe9f

Parent d80294d93a5d

by Jelmer Vernooij

Changes to 4 files · Browse files at 9e63bab0fe9f Showing diff from parent d80294d93a5d Diff from another changeset...

Change 1 of 1 Show Entire File NEWS Stacked
 
37
38
39
 
 
 
 
40
41
42
 
37
38
39
40
41
42
43
44
45
46
@@ -37,6 +37,10 @@
  API CHANGES     * SSHVendor.connect_ssh has been renamed to SSHVendor.run_command. + (Jelmer Vernooij) + + * ObjectStore.add_pack() now returns a 3-tuple. The last element will be an + abort() method that can be used to cancel the pack operation.   (Jelmer Vernooij)    0.9.0 2013-05-31
Change 1 of 1 Show Entire File dulwich/​client.py Stacked
 
202
203
204
205
206
207
208
 
 
 
 
 
 
 
 
 
209
210
211
 
202
203
204
 
 
 
 
205
206
207
208
209
210
211
212
213
214
215
216
@@ -202,10 +202,15 @@
  """   if determine_wants is None:   determine_wants = target.object_store.determine_wants_all - f, commit = target.object_store.add_pack() - result = self.fetch_pack(path, determine_wants, - target.get_graph_walker(), f.write, progress) - commit() + f, commit, abort = target.object_store.add_pack() + try: + result = self.fetch_pack(path, determine_wants, + target.get_graph_walker(), f.write, progress) + except: + abort() + raise + else: + commit()   return result     def fetch_pack(self, path, determine_wants, graph_walker, pack_data,
 
381
382
383
384
385
386
 
 
 
 
 
 
 
 
387
388
389
 
618
619
620
621
622
 
 
 
623
624
625
 
631
632
633
634
 
 
 
 
635
636
637
 
742
743
744
745
 
 
 
746
747
748
 
779
780
781
782
783
784
785
786
787
 
 
 
 
 
 
 
 
 
 
 
788
789
790
 
381
382
383
 
 
 
384
385
386
387
388
389
390
391
392
393
394
 
623
624
625
 
 
626
627
628
629
630
631
 
637
638
639
 
640
641
642
643
644
645
646
 
751
752
753
 
754
755
756
757
758
759
 
790
791
792
 
 
 
 
 
 
793
794
795
796
797
798
799
800
801
802
803
804
805
806
@@ -381,9 +381,14 @@
  if len(objects) == 0:   # Don't bother writing an empty pack file   return - f, commit = self.add_pack() - write_pack_objects(f, objects) - return commit() + f, commit, abort = self.add_pack() + try: + write_pack_objects(f, objects) + except: + abort() + raise + else: + return commit()      class DiskObjectStore(PackBasedObjectStore): @@ -618,8 +623,9 @@
  def add_pack(self):   """Add a new pack to this object store.   - :return: Fileobject to write to and a commit function to - call when the pack is finished. + :return: Fileobject to write to, a commit function to + call when the pack is finished and an abort + function.   """   fd, path = tempfile.mkstemp(dir=self.pack_dir, suffix=".pack")   f = os.fdopen(fd, 'wb') @@ -631,7 +637,10 @@
  else:   os.remove(path)   return None - return f, commit + def abort(): + f.close() + os.remove(path) + return f, commit, abort     def add_object(self, obj):   """Add a single object to this object store. @@ -742,7 +751,9 @@
  f.close()   for obj in PackInflater.for_pack_data(p):   self._data[obj.id] = obj - return f, commit + def abort(): + pass + return f, commit, abort     def _complete_thin_pack(self, f, indexer):   """Complete a thin pack by adding external references. @@ -779,12 +790,17 @@
  :param read_some: Read function that returns at least one byte, but may   not return the number of bytes requested.   """ - f, commit = self.add_pack() - indexer = PackIndexer(f, resolve_ext_ref=self.get_raw) - copier = PackStreamCopier(read_all, read_some, f, delta_iter=indexer) - copier.verify() - self._complete_thin_pack(f, indexer) - commit() + f, commit, abort = self.add_pack() + try: + indexer = PackIndexer(f, resolve_ext_ref=self.get_raw) + copier = PackStreamCopier(read_all, read_some, f, delta_iter=indexer) + copier.verify() + self._complete_thin_pack(f, indexer) + except: + abort() + raise + else: + commit()      class ObjectImporter(object):
 
197
198
199
200
201
202
203
 
 
 
 
 
 
 
 
 
204
205
206
 
290
291
292
293
294
295
296
 
 
 
 
 
 
 
 
 
297
298
299
 
197
198
199
 
 
 
 
200
201
202
203
204
205
206
207
208
209
210
211
 
295
296
297
 
 
 
 
298
299
300
301
302
303
304
305
306
307
308
309
@@ -197,10 +197,15 @@
    def test_add_pack(self):   o = MemoryObjectStore() - f, commit = o.add_pack() - b = make_object(Blob, data="more yummy data") - write_pack_objects(f, [(b, None)]) - commit() + f, commit, abort = o.add_pack() + try: + b = make_object(Blob, data="more yummy data") + write_pack_objects(f, [(b, None)]) + except: + abort() + raise + else: + commit()     def test_add_thin_pack(self):   o = MemoryObjectStore() @@ -290,10 +295,15 @@
    def test_add_pack(self):   o = DiskObjectStore(self.store_dir) - f, commit = o.add_pack() - b = make_object(Blob, data="more yummy data") - write_pack_objects(f, [(b, None)]) - commit() + f, commit, abort = o.add_pack() + try: + b = make_object(Blob, data="more yummy data") + write_pack_objects(f, [(b, None)]) + except: + abort() + raise + else: + commit()     def test_add_thin_pack(self):   o = DiskObjectStore(self.store_dir)