changeset 51902:1eb2317c1762

rev-branch-cache: issue more truthful "truncating" message First, don't pretend it truncate to 40 when it actually truncate to 0. Second, don't pretend to truncate to 0 when the file is already empty/missing.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 24 Sep 2024 00:01:30 +0200
parents f0e07efc199f
children 9f7cf869e9f4
files mercurial/branching/rev_cache.py tests/test-branches.t
diffstat 2 files changed, 8 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/branching/rev_cache.py	Sun Sep 22 15:55:46 2024 +0200
+++ b/mercurial/branching/rev_cache.py	Tue Sep 24 00:01:30 2024 +0200
@@ -336,14 +336,14 @@
         """write the new revs to revbranchcache"""
         revs = min(len(repo.changelog), len(self._rbcrevs) // _rbcrecsize)
         with repo.cachevfs.open(_rbcrevs, b'ab') as f:
-            if f.tell() != start:
-                repo.ui.debug(
-                    b"truncating cache/%s to %d\n" % (_rbcrevs, start)
-                )
+            current_size = f.tell()
+            if current_size < start:
+                start = 0
+            if current_size != start:
+                msg = b"truncating cache/%s to %d\n"
+                msg %= (_rbcrevs, start)
+                repo.ui.debug(msg)
                 f.seek(start)
-                if f.tell() != start:
-                    start = 0
-                    f.seek(start)
                 f.truncate()
             end = revs * _rbcrecsize
             f.write(self._rbcrevs.slice(start, end))
--- a/tests/test-branches.t	Sun Sep 22 15:55:46 2024 +0200
+++ b/tests/test-branches.t	Tue Sep 24 00:01:30 2024 +0200
@@ -905,7 +905,7 @@
   $ echo > .hg/cache/rbc-names-v1
   $ hg log -r '5:&branch(.)' -T '{rev} ' --debug
   referenced branch names not found - rebuilding revision branch cache from scratch
-  8 9 10 11 12 13 truncating cache/rbc-revs-v1 to 40
+  8 9 10 11 12 13  (no-eol)
   $ f --size .hg/cache/rbc-names-*
   .hg/cache/rbc-names-v1: size=84
   $ grep "i-will-regret-this" .hg/cache/rbc-names-* > /dev/null