changeset 51530:9007387a227c

branchcache: move head writing in a `_write_headers` method Same rational: this will help having format variants.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 26 Feb 2024 15:26:08 +0100
parents 09782c097035
children 4188a0570ba1
files mercurial/branchmap.py
diffstat 1 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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