Mercurial > public > mercurial-scm > hg-stable
diff mercurial/transaction.py @ 52768:a7dcb7c1ff5a
typing: add a transaction protocol
This allow us to remove the "external" import from
mercurial/interfaces/dirstate.py, cutting one of the circular import route.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 07 Feb 2025 13:48:50 +0100 |
parents | ae2848198462 |
children |
line wrap: on
line diff
--- a/mercurial/transaction.py Fri Feb 07 16:40:49 2025 +0100 +++ b/mercurial/transaction.py Fri Feb 07 13:48:50 2025 +0100 @@ -21,7 +21,6 @@ Collection, List, Optional, - Tuple, Union, ) @@ -29,6 +28,7 @@ from .interfaces.types import ( CallbackCategoryT, HgPathT, + TransactionT, VfsKeyT, ) from . import ( @@ -38,6 +38,7 @@ util, ) from .utils import stringutil +from .interfaces import transaction as itxn version = 2 @@ -45,8 +46,6 @@ GEN_GROUP_PRE_FINALIZE = b'prefinalize' GEN_GROUP_POST_FINALIZE = b'postfinalize' -JournalEntryT = Tuple[HgPathT, int] - def active(func): def _active(self, *args, **kwds): @@ -240,7 +239,7 @@ pass -class transaction(util.transactional): +class transaction(util.transactional, itxn.ITransaction): def __init__( self, report, @@ -573,7 +572,7 @@ return self._offsetmap.get(file) @active - def readjournal(self) -> List[JournalEntryT]: + def readjournal(self) -> List[itxn.JournalEntryT]: self._file.seek(0) entries = [] for l in self._file.readlines(): @@ -604,7 +603,7 @@ self._file.flush() @active - def nest(self, name: bytes = b'<unnamed>') -> transaction: + def nest(self, name: bytes = b'<unnamed>') -> TransactionT: self._count += 1 self._usages += 1 self._names.append(name) @@ -625,7 +624,7 @@ def addpending( self, category: CallbackCategoryT, - callback: Callable[[transaction], None], + callback: Callable[[TransactionT], None], ) -> None: """add a callback to be called when the transaction is pending @@ -658,7 +657,7 @@ def addfinalize( self, category: CallbackCategoryT, - callback: Callable[[transaction], None], + callback: Callable[[TransactionT], None], ) -> None: """add a callback to be called when the transaction is closed @@ -673,7 +672,7 @@ def addpostclose( self, category: CallbackCategoryT, - callback: Callable[[transaction], None], + callback: Callable[[TransactionT], None], ) -> None: """add or replace a callback to be called after the transaction closed @@ -688,7 +687,7 @@ def getpostclose( self, category: CallbackCategoryT, - ) -> Optional[Callable[[transaction], None]]: + ) -> Optional[Callable[[TransactionT], None]]: """return a postclose callback added before, or None""" return self._postclosecallback.get(category, None) @@ -696,7 +695,7 @@ def addabort( self, category: CallbackCategoryT, - callback: Callable[[transaction], None], + callback: Callable[[TransactionT], None], ) -> None: """add a callback to be called when the transaction is aborted. @@ -711,7 +710,7 @@ def addvalidator( self, category: CallbackCategoryT, - callback: Callable[[transaction], None], + callback: Callable[[TransactionT], None], ) -> None: """adds a callback to be called when validating the transaction.