branchcache: move head writing in a `_write_headers` method
Same rational: this will help having format variants.
--- a/mercurial/branchmap.py Mon Feb 26 15:25:41 2024 +0100
+++ b/mercurial/branchmap.py Mon Feb 26 15:26:08 2024 +0100
@@ -581,10 +581,7 @@
try:
filename = self._filename(repo)
with repo.cachevfs(filename, b"w", atomictemp=True) as f:
- cachekey = [hex(self.tipnode), b'%d' % self.tiprev]
- if self.filteredhash is not None:
- cachekey.append(hex(self.filteredhash))
- f.write(b" ".join(cachekey) + b'\n')
+ self._write_header(f)
nodecount = self._write_heads(f)
repo.ui.log(
b'branchcache',
@@ -601,6 +598,13 @@
% stringutil.forcebytestr(inst)
)
+ def _write_header(self, fp) -> None:
+ """write the branch cache header to a file"""
+ cachekey = [hex(self.tipnode), b'%d' % self.tiprev]
+ if self.filteredhash is not None:
+ cachekey.append(hex(self.filteredhash))
+ fp.write(b" ".join(cachekey) + b'\n')
+
def _write_heads(self, fp) -> int:
"""write list of heads to a file