changeset 51464:09782c097035

branchcache: move head writing in a `_write_heads` method Same rational: this will help having format variants.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 26 Feb 2024 15:25:41 +0100
parents 87b830e4de35
children 9007387a227c
files mercurial/branchmap.py
diffstat 1 files changed, 17 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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: