comparison mercurial/branchmap.py @ 51495:0c684ca692a4

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.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sun, 10 Mar 2024 03:25:04 +0100
parents 54f0dd798346
children 0239ebdd0740
comparison
equal deleted inserted replaced
51494:54f0dd798346 51495:0c684ca692a4
83 bcache = self._per_filter[repo.filtername] 83 bcache = self._per_filter[repo.filtername]
84 assert bcache._filtername == repo.filtername, ( 84 assert bcache._filtername == repo.filtername, (
85 bcache._filtername, 85 bcache._filtername,
86 repo.filtername, 86 repo.filtername,
87 ) 87 )
88 bcache.sync_disk(repo) 88 tr = repo.currenttransaction()
89 if getattr(tr, 'finalized', True):
90 bcache.sync_disk(repo)
89 91
90 def updatecache(self, repo): 92 def updatecache(self, repo):
91 """Update the cache for the given filtered view on a repository""" 93 """Update the cache for the given filtered view on a repository"""
92 # This can trigger updates for the caches for subsets of the filtered 94 # This can trigger updates for the caches for subsets of the filtered
93 # view, e.g. when there is no cache for this filtered view or the cache 95 # view, e.g. when there is no cache for this filtered view or the cache
601 assert self._filtername == repo.filtername, ( 603 assert self._filtername == repo.filtername, (
602 self._filtername, 604 self._filtername,
603 repo.filtername, 605 repo.filtername,
604 ) 606 )
605 assert self._state == STATE_DIRTY, self._state 607 assert self._state == STATE_DIRTY, self._state
608 # This method should not be called during an open transaction
606 tr = repo.currenttransaction() 609 tr = repo.currenttransaction()
607 if not getattr(tr, 'finalized', True): 610 if not getattr(tr, 'finalized', True):
608 # Avoid premature writing. 611 msg = "writing branchcache in the middle of a transaction"
609 # 612 raise error.ProgrammingError(msg)
610 # (The cache warming setup by localrepo will update the file later.)
611 return
612 try: 613 try:
613 filename = self._filename(repo) 614 filename = self._filename(repo)
614 with repo.cachevfs(filename, b"w", atomictemp=True) as f: 615 with repo.cachevfs(filename, b"w", atomictemp=True) as f:
615 self._write_header(f) 616 self._write_header(f)
616 nodecount = self._write_heads(f) 617 nodecount = self._write_heads(f)
730 self.tiprev = tiprev 731 self.tiprev = tiprev
731 self.filteredhash = scmutil.filteredhash( 732 self.filteredhash = scmutil.filteredhash(
732 repo, self.tiprev, needobsolete=True 733 repo, self.tiprev, needobsolete=True
733 ) 734 )
734 self._state = STATE_DIRTY 735 self._state = STATE_DIRTY
735 self.write(repo) 736 tr = repo.currenttransaction()
737 if getattr(tr, 'finalized', True):
738 # Avoid premature writing.
739 #
740 # (The cache warming setup by localrepo will update the file later.)
741 self.write(repo)
736 742
737 743
738 class remotebranchcache(_BaseBranchCache): 744 class remotebranchcache(_BaseBranchCache):
739 """Branchmap info for a remote connection, should not write locally""" 745 """Branchmap info for a remote connection, should not write locally"""
740 746