Patchwork [4,of,7,bundle2] phases: move the binary decoding function in the phases module

login
register
mail settings
Submitter Boris Feld
Date Sept. 28, 2017, 5:08 a.m.
Message ID <6bd13c121a92e5871f08.1506575319@FB>
Download mbox | patch
Permalink /patch/24198/
State Accepted
Headers show

Comments

Boris Feld - Sept. 28, 2017, 5:08 a.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1505852621 -7200
#      Tue Sep 19 22:23:41 2017 +0200
# Node ID 6bd13c121a92e5871f0874dc4d6db4ea9d2406f9
# Parent  856f40d4b1a1ac8f77c314719eb399ea043e5923
# EXP-Topic b2.phases
phases: move the binary decoding function in the phases module

We move the decoding function near the encoding one in a place where they can
be reused in other place (current target, 'exchange.py').

Patch

diff -r 856f40d4b1a1 -r 6bd13c121a92 mercurial/bundle2.py
--- a/mercurial/bundle2.py	Tue Sep 19 22:01:31 2017 +0200
+++ b/mercurial/bundle2.py	Tue Sep 19 22:23:41 2017 +0200
@@ -1836,23 +1836,10 @@ 
                 kwargs[key] = inpart.params[key]
         raise error.PushkeyFailed(partid=str(inpart.id), **kwargs)
 
-def _readphaseheads(inpart):
-    headsbyphase = [[] for i in phases.allphases]
-    entrysize = phases._fphasesentry.size
-    while True:
-        entry = inpart.read(entrysize)
-        if len(entry) < entrysize:
-            if entry:
-                raise error.Abort(_('bad phase-heads bundle part'))
-            break
-        phase, node = phases._fphasesentry.unpack(entry)
-        headsbyphase[phase].append(node)
-    return headsbyphase
-
 @parthandler('phase-heads')
 def handlephases(op, inpart):
     """apply phases from bundle part to repo"""
-    headsbyphase = _readphaseheads(inpart)
+    headsbyphase = phases.binarydecode(inpart)
     phases.updatephases(op.repo.unfiltered(), op.gettransaction(), headsbyphase)
     op.records.add('phase-heads', {})
 
diff -r 856f40d4b1a1 -r 6bd13c121a92 mercurial/debugcommands.py
--- a/mercurial/debugcommands.py	Tue Sep 19 22:01:31 2017 +0200
+++ b/mercurial/debugcommands.py	Tue Sep 19 22:23:41 2017 +0200
@@ -310,7 +310,7 @@ 
 def _debugphaseheads(ui, data, indent=0):
     """display version and markers contained in 'data'"""
     indent_string = ' ' * indent
-    headsbyphase = bundle2._readphaseheads(data)
+    headsbyphase = phases.binarydecode(data)
     for phase in phases.allphases:
         for head in headsbyphase[phase]:
             ui.write(indent_string)
diff -r 856f40d4b1a1 -r 6bd13c121a92 mercurial/phases.py
--- a/mercurial/phases.py	Tue Sep 19 22:01:31 2017 +0200
+++ b/mercurial/phases.py	Tue Sep 19 22:23:41 2017 +0200
@@ -169,6 +169,22 @@ 
             binarydata.append(_fphasesentry.pack(phase, head))
     return ''.join(binarydata)
 
+def binarydecode(stream):
+    """decode a binary stream into a 'phase -> nodes' mapping
+
+    Since phases are integer the mapping is actually a python list."""
+    headsbyphase = [[] for i in allphases]
+    entrysize = _fphasesentry.size
+    while True:
+        entry = stream.read(entrysize)
+        if len(entry) < entrysize:
+            if entry:
+                raise error.Abort(_('bad phase-heads stream'))
+            break
+        phase, node = _fphasesentry.unpack(entry)
+        headsbyphase[phase].append(node)
+    return headsbyphase
+
 def _trackphasechange(data, rev, old, new):
     """add a phase move the <data> dictionnary