Patchwork obsolete: extract encoding of marker for pushkey from the list key function

login
register
mail settings
Submitter Pierre-Yves David
Date Feb. 28, 2014, 4:17 a.m.
Message ID <c15a6fc0f9e646e9f4d9.1393561036@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/3806/
State Superseded
Commit dad29624b05663f7e785e333ad48d5a530dd5b37
Headers show

Comments

Pierre-Yves David - Feb. 28, 2014, 4:17 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1393560088 28800
#      Thu Feb 27 20:01:28 2014 -0800
# Node ID c15a6fc0f9e646e9f4d98088458b6f00a892c875
# Parent  710c2755e66a1322d78911a18362636b3b0ead2c
obsolete: extract encoding of marker for pushkey from the list key function

We now have a function taking a list and marker and returning an encoded
version. This will allow obsolescence marker exchange experimentation to easily
pushkey-encode markers to be pushed after selection.

Patch

diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -350,18 +350,19 @@  def _encodeonemarker(marker):
 # you have to take in account:
 # - the version header
 # - the base85 encoding
 _maxpayload = 5300
 
-def listmarkers(repo):
-    """List markers over pushkey"""
-    if not repo.obsstore:
-        return {}
+def _pushkeyescape(markers):
+    """encode markers into a dict suitable for pushkey exchange
+
+    - binary data are base86 encoded
+    - splited in chunk less than 5300 bytes"""
     keys = {}
     parts = []
     currentlen = _maxpayload * 2  # ensure we create a new part
-    for marker in  repo.obsstore:
+    for marker in markers:
         nextdata = _encodeonemarker(marker)
         if (len(nextdata) + currentlen > _maxpayload):
             currentpart = []
             currentlen = 0
             parts.append(currentpart)
@@ -370,10 +371,16 @@  def listmarkers(repo):
     for idx, part in enumerate(reversed(parts)):
         data = ''.join([_pack('>B', _fmversion)] + part)
         keys['dump%i' % idx] = base85.b85encode(data)
     return keys
 
+def listmarkers(repo):
+    """List markers over pushkey"""
+    if not repo.obsstore:
+        return {}
+    return _pushkeyescape(repo.obsstore)
+
 def pushmarker(repo, key, old, new):
     """Push markers over pushkey"""
     if not key.startswith('dump'):
         repo.ui.warn(_('unknown key: %r') % key)
         return 0