# HG changeset patch # User Pierre-Yves David # Date 2024-02-26 14:26:08 # Node ID 9007387a227c0c884423a6b4b66a3cad18917eec # Parent 09782c0970358b85fd8632a46c701e1e7450f739 branchcache: move head writing in a `_write_headers` method Same rational: this will help having format variants. diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py --- a/mercurial/branchmap.py +++ b/mercurial/branchmap.py @@ -581,10 +581,7 @@ class branchcache(_BaseBranchCache): 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 @@ class branchcache(_BaseBranchCache): % 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