##// END OF EJS Templates
obsstore: move delete function from obsstore class to repair module...
Kostia Balytskyi -
r28868:445a25bb default
parent child Browse files
Show More
@@ -3076,7 +3076,7 b' def debugobsolete(ui, repo, precursor=No'
3076 3076 'of transaction.'))
3077 3077
3078 3078 with repo.lock():
3079 n = repo.obsstore.delete(indices)
3079 n = repair.deleteobsmarkers(repo.obsstore, indices)
3080 3080 ui.write(_('deleted %i obsolescense markers\n') % n)
3081 3081
3082 3082 return
@@ -628,30 +628,6 b' class obsstore(object):'
628 628 transaction.hookargs['new_obsmarkers'] = str(previous + len(new))
629 629 return len(new)
630 630
631 def delete(self, indices):
632 """Delete some obsmarkers from store and return how many were deleted
633
634 Indices is a list of ints which are the indices
635 of the markers to be deleted."""
636 if not indices:
637 # we don't want to rewrite the obsstore with the same content
638 return
639
640 left = []
641 current = self._all
642 n = 0
643 for i, m in enumerate(current):
644 if i in indices:
645 n += 1
646 continue
647 left.append(m)
648
649 newobsstore = self.svfs('obsstore', 'w', atomictemp=True)
650 for bytes in encodemarkers(left, True, self._version):
651 newobsstore.write(bytes)
652 newobsstore.close()
653 return n
654
655 631 def mergemarkers(self, transaction, data):
656 632 """merge a binary stream of markers inside the obsstore
657 633
@@ -17,6 +17,7 b' from . import ('
17 17 changegroup,
18 18 error,
19 19 exchange,
20 obsolete,
20 21 util,
21 22 )
22 23
@@ -313,3 +314,32 b' def stripbmrevset(repo, mark):'
313 314 "ancestors(head() and not bookmark(%s)) - "
314 315 "ancestors(bookmark() and not bookmark(%s))",
315 316 mark, mark, mark)
317
318 def deleteobsmarkers(obsstore, indices):
319 """Delete some obsmarkers from obsstore and return how many were deleted
320
321 'indices' is a list of ints which are the indices
322 of the markers to be deleted.
323
324 Every invocation of this function completely rewrites the obsstore file,
325 skipping the markers we want to be removed. The new temporary file is
326 created, remaining markers are written there and on .close() this file
327 gets atomically renamed to obsstore, thus guaranteeing consistency."""
328 if not indices:
329 # we don't want to rewrite the obsstore with the same content
330 return
331
332 left = []
333 current = obsstore._all
334 n = 0
335 for i, m in enumerate(current):
336 if i in indices:
337 n += 1
338 continue
339 left.append(m)
340
341 newobsstorefile = obsstore.svfs('obsstore', 'w', atomictemp=True)
342 for bytes in obsolete.encodemarkers(left, True, obsstore._version):
343 newobsstorefile.write(bytes)
344 newobsstorefile.close()
345 return n
General Comments 0
You need to be logged in to leave comments. Login now