Mercurial > hg
comparison mercurial/repair.py @ 28868:445a25bb70be
obsstore: move delete function from obsstore class to repair module
Since one of the original patches was accepted already and people on the
mailing list still have suggestions as to how this should be improved, I'm
implementing those suggestions in the following patches (this and the ones that
might follow).
author | Kostia Balytskyi <ikostia@fb.com> |
---|---|
date | Tue, 12 Apr 2016 04:06:50 -0700 |
parents | ae53ecc47414 |
children | bf7b8157c483 |
comparison
equal
deleted
inserted
replaced
28867:ffcc649a4e8f | 28868:445a25bb70be |
---|---|
15 from . import ( | 15 from . import ( |
16 bundle2, | 16 bundle2, |
17 changegroup, | 17 changegroup, |
18 error, | 18 error, |
19 exchange, | 19 exchange, |
20 obsolete, | |
20 util, | 21 util, |
21 ) | 22 ) |
22 | 23 |
23 def _bundle(repo, bases, heads, node, suffix, compress=True): | 24 def _bundle(repo, bases, heads, node, suffix, compress=True): |
24 """create a bundle with the specified revisions as a backup""" | 25 """create a bundle with the specified revisions as a backup""" |
311 """ | 312 """ |
312 return repo.revs("ancestors(bookmark(%s)) - " | 313 return repo.revs("ancestors(bookmark(%s)) - " |
313 "ancestors(head() and not bookmark(%s)) - " | 314 "ancestors(head() and not bookmark(%s)) - " |
314 "ancestors(bookmark() and not bookmark(%s))", | 315 "ancestors(bookmark() and not bookmark(%s))", |
315 mark, mark, mark) | 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 |