Mercurial > public > mercurial-scm > hg-stable
diff mercurial/branchmap.py @ 48363:8e5effbf52d0 stable
branchmap: stop writing cache for uncommitted data
If we are about to write the branch while a transaction is active. we delay
that write. After the transaction is closed, we flush all the write we delayed
(unless they have been written in between).
Differential Revision: https://phab.mercurial-scm.org/D12128
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 01 Feb 2022 15:19:50 +0100 |
parents | bea4717415c0 |
children | f8f2ecdde4b5 |
line wrap: on
line diff
--- a/mercurial/branchmap.py Mon Jan 31 19:28:58 2022 +0100 +++ b/mercurial/branchmap.py Tue Feb 01 15:19:50 2022 +0100 @@ -149,6 +149,13 @@ def clear(self): self._per_filter.clear() + def write_delayed(self, repo): + unfi = repo.unfiltered() + for filtername, cache in self._per_filter.items(): + if cache._delayed: + repo = unfi.filtered(filtername) + cache.write(repo) + def _unknownnode(node): """raises ValueError when branchcache found a node which does not exists""" @@ -199,6 +206,7 @@ has a given node or not. If it's not provided, we assume that every node we have exists in changelog""" self._repo = repo + self._delayed = False if tipnode is None: self.tipnode = repo.nullid else: @@ -403,6 +411,13 @@ ) def write(self, repo): + tr = repo.currenttransaction() + if not getattr(tr, 'finalized', True): + # Avoid premature writing. + # + # (The cache warming setup by localrepo will update the file later.) + self._delayed = True + return try: f = repo.cachevfs(self._filename(repo), b"w", atomictemp=True) cachekey = [hex(self.tipnode), b'%d' % self.tiprev] @@ -427,6 +442,7 @@ len(self._entries), nodecount, ) + self._delayed = False except (IOError, OSError, error.Abort) as inst: # Abort may be raised by read only opener, so log and continue repo.ui.debug(