# HG changeset patch # User Pierre-Yves David # Date 1710037504 -3600 # Node ID 0c684ca692a49bce0ad07cf9935a02807ac0fce6 # Parent 54f0dd7983460fe4a551183f6ac629149491d45c branchcache: explictly update disk state only if no transaction exist If a transaction exist the `write_dirty` call will eventually be done and the state will be synched on disk. It is better to no interfer with that. diff -r 54f0dd798346 -r 0c684ca692a4 mercurial/branchmap.py --- a/mercurial/branchmap.py Sun Mar 10 03:32:50 2024 +0100 +++ b/mercurial/branchmap.py Sun Mar 10 03:25:04 2024 +0100 @@ -85,7 +85,9 @@ bcache._filtername, repo.filtername, ) - bcache.sync_disk(repo) + tr = repo.currenttransaction() + if getattr(tr, 'finalized', True): + bcache.sync_disk(repo) def updatecache(self, repo): """Update the cache for the given filtered view on a repository""" @@ -603,12 +605,11 @@ repo.filtername, ) assert self._state == STATE_DIRTY, self._state + # This method should not be called during an open transaction tr = repo.currenttransaction() if not getattr(tr, 'finalized', True): - # Avoid premature writing. - # - # (The cache warming setup by localrepo will update the file later.) - return + msg = "writing branchcache in the middle of a transaction" + raise error.ProgrammingError(msg) try: filename = self._filename(repo) with repo.cachevfs(filename, b"w", atomictemp=True) as f: @@ -732,7 +733,12 @@ repo, self.tiprev, needobsolete=True ) self._state = STATE_DIRTY - self.write(repo) + tr = repo.currenttransaction() + if getattr(tr, 'finalized', True): + # Avoid premature writing. + # + # (The cache warming setup by localrepo will update the file later.) + self.write(repo) class remotebranchcache(_BaseBranchCache):