mercurial/transaction.py
changeset 44433 baf8c3f944eb
parent 44097 2f1d6180737f
child 44434 f6798c1a80fa
equal deleted inserted replaced
44432:a1908951ca42 44433:baf8c3f944eb
    28 # These are the file generators that should only be executed after the
    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
    29 # finalizers are done, since they rely on the output of the finalizers (like
    30 # the changelog having been written).
    30 # the changelog having been written).
    31 postfinalizegenerators = {b'bookmarks', b'dirstate'}
    31 postfinalizegenerators = {b'bookmarks', b'dirstate'}
    32 
    32 
    33 gengroupall = b'all'
    33 GEN_GROUP_ALL = b'all'
    34 gengroupprefinalize = b'prefinalize'
    34 GEN_GROUP_PRE_FINALIZE = b'prefinalize'
    35 gengrouppostfinalize = b'postfinalize'
    35 GEN_GROUP_POST_FINALIZE = b'postfinalize'
    36 
    36 
    37 
    37 
    38 def active(func):
    38 def active(func):
    39     def _active(self, *args, **kwds):
    39     def _active(self, *args, **kwds):
    40         if self._count == 0:
    40         if self._count == 0:
   350     def removefilegenerator(self, genid):
   350     def removefilegenerator(self, genid):
   351         """reverse of addfilegenerator, remove a file generator function"""
   351         """reverse of addfilegenerator, remove a file generator function"""
   352         if genid in self._filegenerators:
   352         if genid in self._filegenerators:
   353             del self._filegenerators[genid]
   353             del self._filegenerators[genid]
   354 
   354 
   355     def _generatefiles(self, suffix=b'', group=gengroupall):
   355     def _generatefiles(self, suffix=b'', group=GEN_GROUP_ALL):
   356         # write files registered for generation
   356         # write files registered for generation
   357         any = False
   357         any = False
   358         for id, entry in sorted(pycompat.iteritems(self._filegenerators)):
   358         for id, entry in sorted(pycompat.iteritems(self._filegenerators)):
   359             any = True
   359             any = True
   360             order, filenames, genfunc, location = entry
   360             order, filenames, genfunc, location = entry
   361 
   361 
   362             # for generation at closing, check if it's before or after finalize
   362             # for generation at closing, check if it's before or after finalize
   363             postfinalize = group == gengrouppostfinalize
   363             postfinalize = group == GEN_GROUP_POST_FINALIZE
   364             if (
   364             if (
   365                 group != gengroupall
   365                 group != GEN_GROUP_ALL
   366                 and (id in postfinalizegenerators) != postfinalize
   366                 and (id in postfinalizegenerators) != postfinalize
   367             ):
   367             ):
   368                 continue
   368                 continue
   369 
   369 
   370             vfs = self._vfsmap[location]
   370             vfs = self._vfsmap[location]
   503     def close(self):
   503     def close(self):
   504         '''commit the transaction'''
   504         '''commit the transaction'''
   505         if self._count == 1:
   505         if self._count == 1:
   506             self._validator(self)  # will raise exception if needed
   506             self._validator(self)  # will raise exception if needed
   507             self._validator = None  # Help prevent cycles.
   507             self._validator = None  # Help prevent cycles.
   508             self._generatefiles(group=gengroupprefinalize)
   508             self._generatefiles(group=GEN_GROUP_PRE_FINALIZE)
   509             while self._finalizecallback:
   509             while self._finalizecallback:
   510                 callbacks = self._finalizecallback
   510                 callbacks = self._finalizecallback
   511                 self._finalizecallback = {}
   511                 self._finalizecallback = {}
   512                 categories = sorted(callbacks)
   512                 categories = sorted(callbacks)
   513                 for cat in categories:
   513                 for cat in categories:
   514                     callbacks[cat](self)
   514                     callbacks[cat](self)
   515             # Prevent double usage and help clear cycles.
   515             # Prevent double usage and help clear cycles.
   516             self._finalizecallback = None
   516             self._finalizecallback = None
   517             self._generatefiles(group=gengrouppostfinalize)
   517             self._generatefiles(group=GEN_GROUP_POST_FINALIZE)
   518 
   518 
   519         self._count -= 1
   519         self._count -= 1
   520         if self._count != 0:
   520         if self._count != 0:
   521             return
   521             return
   522         self._file.close()
   522         self._file.close()