diff mercurial/obsolete.py @ 17295:1f08ecc7febb stable

pushkey: splits obsolete marker exchange into multiple keys Obsolete markers are now exchanged in smaller pieces that fit in a http header. This changes is done to avoid 400 bad request error when exchanging obsolete puskey over http. The last key pushed is always hold by the "dump0" key to ensure an easy place to hook for people who need it.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Fri, 27 Jul 2012 18:32:56 +0200
parents 67f56ff5afcd
children a1f8869f2eee
line wrap: on
line diff
--- a/mercurial/obsolete.py	Thu Jul 26 16:41:42 2012 +0200
+++ b/mercurial/obsolete.py	Fri Jul 27 18:32:56 2012 +0200
@@ -234,24 +234,45 @@
     if addheader:
         yield _pack('>B', _fmversion)
     for marker in markers:
-        pre, sucs, flags, metadata = marker
-        nbsuc = len(sucs)
-        format = _fmfixed + (_fmnode * nbsuc)
-        data = [nbsuc, len(metadata), flags, pre]
-        data.extend(sucs)
-        yield _pack(format, *data)
-        yield metadata
+        yield _encodeonemarker(marker)
+
+
+def _encodeonemarker(marker):
+    pre, sucs, flags, metadata = marker
+    nbsuc = len(sucs)
+    format = _fmfixed + (_fmnode * nbsuc)
+    data = [nbsuc, len(metadata), flags, pre]
+    data.extend(sucs)
+    return _pack(format, *data) + metadata
+
+# arbitrary picked to fit into 8K limit from HTTP server
+# 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 {}
-    markers = _encodemarkers(repo.obsstore, True)
-    return {'dump': base85.b85encode(''.join(markers))}
+    keys = {}
+    parts = []
+    currentlen = _maxpayload * 2  # ensure we create a new part
+    for marker in  repo.obsstore:
+        nextdata = _encodeonemarker(marker)
+        if (len(nextdata) + currentlen > _maxpayload):
+            currentpart = []
+            currentlen = 0
+            parts.append(currentpart)
+        currentpart.append(nextdata)
+    for idx, part in enumerate(reversed(parts)):
+        data = ''.join([_pack('>B', _fmversion)] + part)
+        keys['dump%i' % idx] = base85.b85encode(data)
+    return keys
 
 def pushmarker(repo, key, old, new):
     """Push markers over pushkey"""
-    if key != 'dump':
+    if not key.startswith('dump'):
         repo.ui.warn(_('unknown key: %r') % key)
         return 0
     if old: