branchcache: move head writing in a `_write_headers` method
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 26 Feb 2024 15:26:08 +0100
changeset 51465 9007387a227c
parent 51464 09782c097035
child 51468 4188a0570ba1
branchcache: move head writing in a `_write_headers` method Same rational: this will help having format variants.
mercurial/branchmap.py
--- 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