diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py --- a/mercurial/branchmap.py +++ b/mercurial/branchmap.py @@ -97,9 +97,6 @@ def updatecache(repo): partial.update(repo, revs) partial.write(repo) - if repo._revbranchcache is not None: - repo._revbranchcache.write() - assert partial.validfor(repo), filtername repo._branchcaches[repo.filtername] = partial diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -303,7 +303,11 @@ class localrepository(object): self.names = namespaces.namespaces() def close(self): - pass + self._writecaches() + + def _writecaches(self): + if self._revbranchcache: + self._revbranchcache.write() def _restrictcapabilities(self, caps): # bundle2 is not ready for prime time, drop it unless explicitly diff --git a/tests/test-branches.t b/tests/test-branches.t --- a/tests/test-branches.t +++ b/tests/test-branches.t @@ -561,8 +561,8 @@ no errors when revbranchcache is not wri recovery from invalid cache revs file with trailing data $ echo >> .hg/cache/rbc-revs-v1 $ rm -f .hg/cache/branch* && hg head a -T '{rev}\n' --debug + 5 truncating cache/rbc-revs-v1 to 120 - 5 $ f --size .hg/cache/rbc-revs* .hg/cache/rbc-revs-v1: size=120 recovery from invalid cache file with partial last record @@ -571,8 +571,8 @@ recovery from invalid cache file with pa $ f --size .hg/cache/rbc-revs* .hg/cache/rbc-revs-v1: size=119 $ rm -f .hg/cache/branch* && hg head a -T '{rev}\n' --debug + 5 truncating cache/rbc-revs-v1 to 112 - 5 $ f --size .hg/cache/rbc-revs* .hg/cache/rbc-revs-v1: size=120 recovery from invalid cache file with missing record - no truncation @@ -590,11 +590,11 @@ recovery from invalid cache file with so $ f -qDB 112 rbc-revs-v1 >> .hg/cache/rbc-revs-v1 $ f --size .hg/cache/rbc-revs* .hg/cache/rbc-revs-v1: size=120 - $ hg log -r 'branch(.)' -T '{rev} ' - 3 4 8 9 10 11 12 13 (no-eol) + $ hg log -r 'branch(.)' -T '{rev} ' --debug + 3 4 8 9 10 11 12 13 truncating cache/rbc-revs-v1 to 8 $ rm -f .hg/cache/branch* && hg head a -T '{rev}\n' --debug - truncating cache/rbc-revs-v1 to 8 5 + truncating cache/rbc-revs-v1 to 104 $ f --size --hexdump --bytes=16 .hg/cache/rbc-revs* .hg/cache/rbc-revs-v1: size=120 0000: 19 70 9c 5a 00 00 00 00 dd 6b 44 0d 00 00 00 01 |.p.Z.....kD.....| diff --git a/tests/test-rebase-conflicts.t b/tests/test-rebase-conflicts.t --- a/tests/test-rebase-conflicts.t +++ b/tests/test-rebase-conflicts.t @@ -322,6 +322,6 @@ Check that the right ancestors is used w files: 1/1 chunks (100.00%) added 2 changesets with 2 changes to 1 files invalid branchheads cache (served): tip differs - truncating cache/rbc-revs-v1 to 72 rebase completed updating the branch cache + truncating cache/rbc-revs-v1 to 72