mercurial/phases.py
changeset 34319 5779d096a696
parent 33460 57a017f79e96
child 34320 12c42bcd4133
--- a/mercurial/phases.py	Tue Sep 19 22:08:09 2017 +0200
+++ b/mercurial/phases.py	Tue Sep 19 22:01:31 2017 +0200
@@ -103,6 +103,7 @@
 from __future__ import absolute_import
 
 import errno
+import struct
 
 from .i18n import _
 from .node import (
@@ -119,6 +120,8 @@
     util,
 )
 
+_fphasesentry = struct.Struct('>i20s')
+
 allphases = public, draft, secret = range(3)
 trackedphases = allphases[1:]
 phasenames = ['public', 'draft', 'secret']
@@ -154,6 +157,18 @@
         dirty = True
     return roots, dirty
 
+def binaryencode(phasemapping):
+    """encode a 'phase -> nodes' mapping into a binary stream
+
+    Since phases are integer the mapping is actually a python list:
+    [[PUBLIC_HEADS], [DRAFTS_HEADS], [SECRET_HEADS]]
+    """
+    binarydata = []
+    for phase, nodes in enumerate(phasemapping):
+        for head in nodes:
+            binarydata.append(_fphasesentry.pack(phase, head))
+    return ''.join(binarydata)
+
 def _trackphasechange(data, rev, old, new):
     """add a phase move the <data> dictionnary