bundle2: prepare readbundle to return more that one type of bundle
authorPierre-Yves David <pierre-yves.david@fb.com>
Tue, 15 Apr 2014 13:42:45 -0400
changeset 21065 f9a9a6d63e89
parent 21064 4d9d490d7bbe
child 21066 5ecfe76d0d96
bundle2: prepare readbundle to return more that one type of bundle We first read 4 bytes to get the `HG10` bytes then we read the compression scheme if this is `HG10`. This prepares the code for the arrival of `HG20` handling.
mercurial/exchange.py
--- a/mercurial/exchange.py	Mon Apr 14 15:45:30 2014 -0400
+++ b/mercurial/exchange.py	Tue Apr 15 13:42:45 2014 -0400
@@ -12,23 +12,28 @@
 import discovery, phases, obsolete, bookmarks, bundle2
 
 def readbundle(ui, fh, fname, vfs=None):
-    header = changegroup.readexactly(fh, 6)
+    header = changegroup.readexactly(fh, 4)
 
+    alg = None
     if not fname:
         fname = "stream"
         if not header.startswith('HG') and header.startswith('\0'):
             fh = changegroup.headerlessfixup(fh, header)
-            header = "HG10UN"
+            header = "HG10"
+            alg = 'UN'
     elif vfs:
         fname = vfs.join(fname)
 
-    magic, version, alg = header[0:2], header[2:4], header[4:6]
+    magic, version = header[0:2], header[2:4]
 
     if magic != 'HG':
         raise util.Abort(_('%s: not a Mercurial bundle') % fname)
-    if version != '10':
+    if version == '10':
+        if alg is None:
+            alg = changegroup.readexactly(fh, 2)
+        return changegroup.unbundle10(fh, alg)
+    else:
         raise util.Abort(_('%s: unknown bundle version %s') % (fname, version))
-    return changegroup.unbundle10(fh, alg)
 
 
 class pushoperation(object):