changeset 1980:dfb796786337

use HG10UN header for uncompressed bundle - use HG10UN instead of HG11 for uncompressed bundles header - check HG10BZ for compressed bundle - better error handling for invalid header some notes: - people who created uncompressed bundle will no longer be able to use them (it could be fixed with hand-editing) - older hg cannot detect an uncompressed bundle (bzip2 decompression will fail).
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Tue, 21 Mar 2006 06:03:33 +0100
parents d545fa1426b9
children 736b6c96bbbc
files mercurial/bundlerepo.py mercurial/commands.py
diffstat 2 files changed, 23 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bundlerepo.py	Mon Mar 20 17:14:58 2006 +0100
+++ b/mercurial/bundlerepo.py	Tue Mar 21 06:03:33 2006 +0100
@@ -174,12 +174,20 @@
         f = open(bundlename, "rb")
         s = os.fstat(f.fileno())
         self.bundlefile = f
-        header = self.bundlefile.read(4)
-        if header == "HG10":
+        header = self.bundlefile.read(6)
+        if not header.startswith("HG"):
+            raise util.Abort(_("%s: not a Mercurial bundle file") % bundlename)
+        elif not header.startswith("HG10"):
+            raise util.Abort(_("%s: unknown bundle version") % bundlename)
+        elif header == "HG10BZ":
             raise util.Abort(_("%s: compressed bundle not supported")
                              % bundlename)
-        elif header != "HG11":
-            raise util.Abort(_("%s: not a Mercurial bundle file") % bundlename)
+        elif header == "HG10UN":
+            # uncompressed bundle supported
+            pass
+        else:
+            raise util.Abort(_("%s: unknown bundle compression type")
+                             % bundlename)
         self.changelog = bundlechangelog(self.opener, self.bundlefile)
         self.manifest = bundlemanifest(self.opener, self.bundlefile,
                                        self.changelog.rev)
--- a/mercurial/commands.py	Mon Mar 20 17:14:58 2006 +0100
+++ b/mercurial/commands.py	Tue Mar 21 06:03:33 2006 +0100
@@ -304,7 +304,7 @@
             fh.write("HG10")
             z = bz2.BZ2Compressor(9)
         else:
-            fh.write("HG11")
+            fh.write("HG10UN")
             z = nocompress()
         while 1:
             chunk = cg.read(4096)
@@ -2569,18 +2569,24 @@
     """
     f = urllib.urlopen(fname)
 
-    header = f.read(4)
-    if header == "HG10":
+    header = f.read(6)
+    if not header.startswith("HG"):
+        raise util.Abort(_("%s: not a Mercurial bundle file") % fname)
+    elif not header.startswith("HG10"):
+        raise util.Abort(_("%s: unknown bundle version") % fname)
+    elif header == "HG10BZ":
         def generator(f):
             zd = bz2.BZ2Decompressor()
+            zd.decompress("BZ")
             for chunk in f:
                 yield zd.decompress(chunk)
-    elif header == "HG11":
+    elif header == "HG10UN":
         def generator(f):
             for chunk in f:
                 yield chunk
     else:
-        raise util.Abort(_("%s: not a Mercurial bundle file") % fname)
+        raise util.Abort(_("%s: unknown bundle compression type")
+                         % fname)
     gen = generator(util.filechunkiter(f, 4096))
     if repo.addchangegroup(util.chunkbuffer(gen)):
         return 1