22 util, |
22 util, |
23 ) |
23 ) |
24 from .utils import stringutil |
24 from .utils import stringutil |
25 |
25 |
26 version = 2 |
26 version = 2 |
27 |
|
28 # These are the file generators that should only be executed after the |
|
29 # finalizers are done, since they rely on the output of the finalizers (like |
|
30 # the changelog having been written). |
|
31 postfinalizegenerators = {b'bookmarks', b'dirstate'} |
|
32 |
27 |
33 GEN_GROUP_ALL = b'all' |
28 GEN_GROUP_ALL = b'all' |
34 GEN_GROUP_PRE_FINALIZE = b'prefinalize' |
29 GEN_GROUP_PRE_FINALIZE = b'prefinalize' |
35 GEN_GROUP_POST_FINALIZE = b'postfinalize' |
30 GEN_GROUP_POST_FINALIZE = b'postfinalize' |
36 |
31 |
332 """ |
327 """ |
333 self._addbackupentry((location, b'', tmpfile, False)) |
328 self._addbackupentry((location, b'', tmpfile, False)) |
334 |
329 |
335 @active |
330 @active |
336 def addfilegenerator( |
331 def addfilegenerator( |
337 self, genid, filenames, genfunc, order=0, location=b'' |
332 self, |
|
333 genid, |
|
334 filenames, |
|
335 genfunc, |
|
336 order=0, |
|
337 location=b'', |
|
338 post_finalize=False, |
338 ): |
339 ): |
339 """add a function to generates some files at transaction commit |
340 """add a function to generates some files at transaction commit |
340 |
341 |
341 The `genfunc` argument is a function capable of generating proper |
342 The `genfunc` argument is a function capable of generating proper |
342 content of each entry in the `filename` tuple. |
343 content of each entry in the `filename` tuple. |
355 generator will be executed. |
356 generator will be executed. |
356 |
357 |
357 The `location` arguments may be used to indicate the files are located |
358 The `location` arguments may be used to indicate the files are located |
358 outside of the the standard directory for transaction. It should match |
359 outside of the the standard directory for transaction. It should match |
359 one of the key of the `transaction.vfsmap` dictionary. |
360 one of the key of the `transaction.vfsmap` dictionary. |
|
361 |
|
362 The `post_finalize` argument can be set to `True` for file generation |
|
363 that must be run after the transaction has been finalized. |
360 """ |
364 """ |
361 # For now, we are unable to do proper backup and restore of custom vfs |
365 # For now, we are unable to do proper backup and restore of custom vfs |
362 # but for bookmarks that are handled outside this mechanism. |
366 # but for bookmarks that are handled outside this mechanism. |
363 self._filegenerators[genid] = (order, filenames, genfunc, location) |
367 entry = (order, filenames, genfunc, location, post_finalize) |
|
368 self._filegenerators[genid] = entry |
364 |
369 |
365 @active |
370 @active |
366 def removefilegenerator(self, genid): |
371 def removefilegenerator(self, genid): |
367 """reverse of addfilegenerator, remove a file generator function""" |
372 """reverse of addfilegenerator, remove a file generator function""" |
368 if genid in self._filegenerators: |
373 if genid in self._filegenerators: |
378 skip_pre = group == GEN_GROUP_POST_FINALIZE |
383 skip_pre = group == GEN_GROUP_POST_FINALIZE |
379 skip_post = group == GEN_GROUP_PRE_FINALIZE |
384 skip_post = group == GEN_GROUP_PRE_FINALIZE |
380 |
385 |
381 for id, entry in sorted(pycompat.iteritems(self._filegenerators)): |
386 for id, entry in sorted(pycompat.iteritems(self._filegenerators)): |
382 any = True |
387 any = True |
383 order, filenames, genfunc, location = entry |
388 order, filenames, genfunc, location, post_finalize = entry |
384 |
389 |
385 # for generation at closing, check if it's before or after finalize |
390 # for generation at closing, check if it's before or after finalize |
386 is_post = id in postfinalizegenerators |
391 if skip_post and post_finalize: |
387 if skip_post and is_post: |
|
388 continue |
392 continue |
389 elif skip_pre and not is_post: |
393 elif skip_pre and not post_finalize: |
390 continue |
394 continue |
391 |
395 |
392 vfs = self._vfsmap[location] |
396 vfs = self._vfsmap[location] |
393 files = [] |
397 files = [] |
394 try: |
398 try: |