# HG changeset patch # User Pierre-Yves David # Date 1708957541 -3600 # Node ID 09782c0970358b85fd8632a46c701e1e7450f739 # Parent 87b830e4de35cea6e64bfad87572e354816da771 branchcache: move head writing in a `_write_heads` method Same rational: this will help having format variants. diff -r 87b830e4de35 -r 09782c097035 mercurial/branchmap.py --- a/mercurial/branchmap.py Mon Feb 26 15:23:45 2024 +0100 +++ b/mercurial/branchmap.py Mon Feb 26 15:25:41 2024 +0100 @@ -585,16 +585,7 @@ if self.filteredhash is not None: cachekey.append(hex(self.filteredhash)) f.write(b" ".join(cachekey) + b'\n') - nodecount = 0 - for label, nodes in sorted(self._entries.items()): - label = encoding.fromlocal(label) - for node in nodes: - nodecount += 1 - if node in self._closednodes: - state = b'c' - else: - state = b'o' - f.write(b"%s %s %s\n" % (hex(node), state, label)) + nodecount = self._write_heads(f) repo.ui.log( b'branchcache', b'wrote %s with %d labels and %d nodes\n', @@ -610,6 +601,22 @@ % stringutil.forcebytestr(inst) ) + def _write_heads(self, fp) -> int: + """write list of heads to a file + + Return the number of heads written.""" + nodecount = 0 + for label, nodes in sorted(self._entries.items()): + label = encoding.fromlocal(label) + for node in nodes: + nodecount += 1 + if node in self._closednodes: + state = b'c' + else: + state = b'o' + fp.write(b"%s %s %s\n" % (hex(node), state, label)) + return nodecount + def _verifybranch(self, branch): """verify head nodes for the given branch.""" if not self._verify_node: