bundle2: extract capabilities decoding
authorPierre-Yves David <pierre-yves.david@fb.com>
Thu, 17 Apr 2014 01:09:05 -0400
changeset 21138 f469879d27ec
parent 21137 341a083603a5
child 21139 2b8c82f7f11d
bundle2: extract capabilities decoding We'll need to reuse this in more places (at least pull and push).
mercurial/bundle2.py
--- a/mercurial/bundle2.py	Thu Apr 17 01:03:33 2014 -0400
+++ b/mercurial/bundle2.py	Thu Apr 17 01:09:05 2014 -0400
@@ -333,6 +333,29 @@
         raise
     return op
 
+def decodecaps(blob):
+    """decode a bundle2 caps bytes blob into a dictionnary
+
+    The blob is a list of capabilities (one per line)
+    Capabilities may have values using a line of the form::
+
+        capability=value1,value2,value3
+
+    The values are always a list."""
+    caps = {}
+    for line in blob.splitlines():
+        if not line:
+            continue
+        if '=' not in line:
+            key, vals = line, ()
+        else:
+            key, vals = line.split('=', 1)
+            vals = vals.split(',')
+        key = urllib.unquote(key)
+        vals = [urllib.unquote(v) for v in vals]
+        caps[key] = vals
+    return caps
+
 class bundle20(object):
     """represent an outgoing bundle2 container
 
@@ -697,24 +720,8 @@
 def handlereplycaps(op, inpart):
     """Notify that a reply bundle should be created
 
-    The part payload is a list of capabilities (one per line)
-    Capabilities may have values using a line of form::
-
-        capability=value1,value2,value3
-
-    The value are alway a list."""
-    caps = {}
-    for line in inpart.read().splitlines():
-        if not line:
-            continue
-        if '=' not in line:
-            key, vals = line, ()
-        else:
-            key, vals = line.split('=', 1)
-            vals = vals.split(',')
-        key = urllib.unquote(key)
-        vals = [urllib.unquote(v) for v in vals]
-        caps[key] = vals
+    The payload contains the capabilities information for the reply"""
+    caps = decodecaps(inpart.read())
     if op.reply is None:
         op.reply = bundle20(op.ui, caps)