changeset 52004:4c885d5ff132

rev-branch-cache: stop pretending we will overwrite data when we don't We were issuing a message about overwriting data even when we were about to write 0 bytes in pratice. This is silly. Instead we point at the extra data remaining in the file (in case someone is using debug to debug something).
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 27 Sep 2024 15:01:43 +0200
parents bb281ecf4036
children 76416b6e9d9b
files mercurial/branching/rev_cache.py tests/test-branches.t
diffstat 2 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/branching/rev_cache.py	Fri Sep 27 15:05:26 2024 +0200
+++ b/mercurial/branching/rev_cache.py	Fri Sep 27 15:01:43 2024 +0200
@@ -397,11 +397,15 @@
                 start = 0
             if current_size != start:
                 threshold = current_size * REWRITE_RATIO
-                if (max(end, current_size) - start) < threshold:
-                    # end affected, let overwrite the bad value
-                    overwritten = min(end, current_size) - start
+                overwritten = min(end, current_size) - start
+                if (max(end, current_size) - start) >= threshold:
+                    start = 0
+                    dbg = b"resetting content of cache/%s\n" % _rbcrevs
+                    repo.ui.debug(dbg)
+                elif overwritten > 0:
+                    # end affected, let us overwrite the bad value
                     dbg = b"overwriting %d bytes from %d in cache/%s"
-                    dbg %= (overwritten, start, _rbcrevs)
+                    dbg %= (current_size - start, start, _rbcrevs)
                     if end < current_size:
                         extra = b" leaving (%d trailing bytes)"
                         extra %= current_size - end
@@ -409,9 +413,12 @@
                     dbg += b'\n'
                     repo.ui.debug(dbg)
                 else:
-                    start = 0
-                    dbg = b"resetting content of cache/%s\n" % _rbcrevs
+                    # extra untouched data at the end, lets warn about them
+                    assert start == end  # since don't write anything
+                    dbg = b"cache/%s contains %d unknown trailing bytes\n"
+                    dbg %= (_rbcrevs, current_size - start)
                     repo.ui.debug(dbg)
+
             if start > 0:
                 f.seek(start)
                 f.write(self._rbcrevs.slice(start, end))
--- a/tests/test-branches.t	Fri Sep 27 15:05:26 2024 +0200
+++ b/tests/test-branches.t	Fri Sep 27 15:01:43 2024 +0200
@@ -835,7 +835,7 @@
   $ echo >> .hg/cache/rbc-revs-v2
   $ rm -f .hg/cache/branch* && hg head a -T '{rev}\n' --debug
   5
-  overwriting 0 bytes from 160 in cache/rbc-revs-v2 leaving (2 trailing bytes)
+  cache/rbc-revs-v2 contains 2 unknown trailing bytes
   $ f --size .hg/cache/rbc-revs*
   .hg/cache/rbc-revs-v2: size=162