Mercurial > public > mercurial-scm > hg
diff mercurial/branching/rev_cache.py @ 51970: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 |
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))