These constant are internal to the module and can be safely renamed. Having them
upper case help to clarify their "constant" status.
(This is a gratuitous cleanup I did while looking at something else.)
| hg-reviewers |
These constant are internal to the module and can be safely renamed. Having them
upper case help to clarify their "constant" status.
(This is a gratuitous cleanup I did while looking at something else.)
| No Linters Available |
| No Unit Test Coverage |
| Path | Packages | |||
|---|---|---|---|---|
| M | mercurial/transaction.py (16 lines) |
| Commit | Parents | Author | Summary | Date |
|---|---|---|---|---|
| 59cf49bb622b | a6fb134bd086 | Pierre-Yves David | Feb 27 2020, 6:02 PM |
| version = 2 | version = 2 | ||||
| # These are the file generators that should only be executed after the | # These are the file generators that should only be executed after the | ||||
| # finalizers are done, since they rely on the output of the finalizers (like | # finalizers are done, since they rely on the output of the finalizers (like | ||||
| # the changelog having been written). | # the changelog having been written). | ||||
| postfinalizegenerators = {b'bookmarks', b'dirstate'} | postfinalizegenerators = {b'bookmarks', b'dirstate'} | ||||
| gengroupall = b'all' | GEN_GROUP_ALL = b'all' | ||||
| gengroupprefinalize = b'prefinalize' | GEN_GROUP_PRE_FINALIZE = b'prefinalize' | ||||
| gengrouppostfinalize = b'postfinalize' | GEN_GROUP_POST_FINALIZE = b'postfinalize' | ||||
| def active(func): | def active(func): | ||||
| def _active(self, *args, **kwds): | def _active(self, *args, **kwds): | ||||
| if self._count == 0: | if self._count == 0: | ||||
| raise error.Abort( | raise error.Abort( | ||||
| _( | _( | ||||
| b'cannot use transaction when it is already committed/aborted' | b'cannot use transaction when it is already committed/aborted' | ||||
| self._filegenerators[genid] = (order, filenames, genfunc, location) | self._filegenerators[genid] = (order, filenames, genfunc, location) | ||||
| @active | @active | ||||
| def removefilegenerator(self, genid): | def removefilegenerator(self, genid): | ||||
| """reverse of addfilegenerator, remove a file generator function""" | """reverse of addfilegenerator, remove a file generator function""" | ||||
| if genid in self._filegenerators: | if genid in self._filegenerators: | ||||
| del self._filegenerators[genid] | del self._filegenerators[genid] | ||||
| def _generatefiles(self, suffix=b'', group=gengroupall): | def _generatefiles(self, suffix=b'', group=GEN_GROUP_ALL): | ||||
| # write files registered for generation | # write files registered for generation | ||||
| any = False | any = False | ||||
| for id, entry in sorted(pycompat.iteritems(self._filegenerators)): | for id, entry in sorted(pycompat.iteritems(self._filegenerators)): | ||||
| any = True | any = True | ||||
| order, filenames, genfunc, location = entry | order, filenames, genfunc, location = entry | ||||
| # for generation at closing, check if it's before or after finalize | # for generation at closing, check if it's before or after finalize | ||||
| postfinalize = group == gengrouppostfinalize | postfinalize = group == GEN_GROUP_POST_FINALIZE | ||||
| if ( | if ( | ||||
| group != gengroupall | group != GEN_GROUP_ALL | ||||
| and (id in postfinalizegenerators) != postfinalize | and (id in postfinalizegenerators) != postfinalize | ||||
| ): | ): | ||||
| continue | continue | ||||
| vfs = self._vfsmap[location] | vfs = self._vfsmap[location] | ||||
| files = [] | files = [] | ||||
| try: | try: | ||||
| for name in filenames: | for name in filenames: | ||||
| self._abortcallback[category] = callback | self._abortcallback[category] = callback | ||||
| @active | @active | ||||
| def close(self): | def close(self): | ||||
| '''commit the transaction''' | '''commit the transaction''' | ||||
| if self._count == 1: | if self._count == 1: | ||||
| self._validator(self) # will raise exception if needed | self._validator(self) # will raise exception if needed | ||||
| self._validator = None # Help prevent cycles. | self._validator = None # Help prevent cycles. | ||||
| self._generatefiles(group=gengroupprefinalize) | self._generatefiles(group=GEN_GROUP_PRE_FINALIZE) | ||||
| while self._finalizecallback: | while self._finalizecallback: | ||||
| callbacks = self._finalizecallback | callbacks = self._finalizecallback | ||||
| self._finalizecallback = {} | self._finalizecallback = {} | ||||
| categories = sorted(callbacks) | categories = sorted(callbacks) | ||||
| for cat in categories: | for cat in categories: | ||||
| callbacks[cat](self) | callbacks[cat](self) | ||||
| # Prevent double usage and help clear cycles. | # Prevent double usage and help clear cycles. | ||||
| self._finalizecallback = None | self._finalizecallback = None | ||||
| self._generatefiles(group=gengrouppostfinalize) | self._generatefiles(group=GEN_GROUP_POST_FINALIZE) | ||||
| self._count -= 1 | self._count -= 1 | ||||
| if self._count != 0: | if self._count != 0: | ||||
| return | return | ||||
| self._file.close() | self._file.close() | ||||
| self._backupsfile.close() | self._backupsfile.close() | ||||
| # cleanup temporary files | # cleanup temporary files | ||||
| for l, f, b, c in self._backupentries: | for l, f, b, c in self._backupentries: | ||||