add --quirk suse, which affects --old-bzip2 mode to inexactly replicate suse bzip2
authorJoey Hess <joey@kitenet.net>
Mon, 12 Sep 2011 20:06:02 +0000 (16:06 -0400)
committerJoey Hess <joey@kitenet.net>
Mon, 12 Sep 2011 20:06:02 +0000 (16:06 -0400)
Suse's bzip2 is modifed for some reason to use a huffman table of 17 bytes.

While suse has a newer bzip2 than the version in old-bzip2, it was most
expedient to keep only one copy of bzip2 in zgz, and parameterize it to
emulate suse's patched newer version. This is done by using the blocksort
code from bzip 1.0.5.

This does not 100% replicate the output of suse's bzip2, but the
differences seem to just be in some preliminary header info, and are
quite small. So this will be combined with using xdelta.

zgz/old-bzip2/bzip2.c
zgz/old-bzip2/bzlib_private.h
zgz/old-bzip2/compress.c
zgz/zgz.c

index 6bf70df3d3558c57940680fb6adc022a411825aa..1667463dfaee21a54be9b9c6ac7468c7cd092936 100644 (file)
@@ -170,8 +170,11 @@ void compressStream ( FILE *stream, FILE *zStream )
    /*notreached*/
 }
 
-void old_bzip2(int level) {
+int quirk_suse = 0;
+
+void old_bzip2(int level, int qs) {
        workFactor = 30;
+       quirk_suse = qs;
        blockSize100k = level;
 
        compressStream(stdin, stdout);
index 8e934800e6566edeec001307fcc047642d958a45..e2e1553eb6b15ead7222454b3115d85057bdcefd 100644 (file)
@@ -296,6 +296,8 @@ typedef
 
 extern void 
 blockSort ( EState* );
+extern void 
+blockSort_10 ( EState* );
 
 extern void 
 compressBlock ( EState*, Bool );
index 7b192c341065796ec766a6b619b493d19fadec9e..0828998fa78c69cacf8b06c08c3157ed94664f68 100644 (file)
@@ -552,6 +552,7 @@ void sendMTFValues ( EState* s )
       VPrintf1( "codes %d\n", s->numZ-nBytes );
 }
 
+extern int quirk_suse;
 
 /*---------------------------------------------------*/
 void compressBlock ( EState* s, Bool is_last_block )
@@ -568,7 +569,10 @@ void compressBlock ( EState* s, Bool is_last_block )
                    "combined CRC = 0x%8x, size = %d\n",
                    s->blockNo, s->blockCRC, s->combinedCRC, s->nblock );
 
-      blockSort ( s );
+      if (quirk_suse)
+             blockSort_10 ( s );
+      else
+             blockSort ( s );
    }
 
    s->zbits = (UChar*) (&((UInt16*)s->arr2)[s->nblock]);
index f2eb05b4cb7f9eeae46f1cc500390d3922b8bd1d..cbd71392368fcc25aca4f7005e56444653a211c3 100644 (file)
--- a/zgz/zgz.c
+++ b/zgz/zgz.c
@@ -73,7 +73,7 @@
 #include <time.h>
 
 extern void gnuzip(int in, int out, char *origname, unsigned long timestamp, int level, int osflag, int rsync, int newrsync);
-extern void old_bzip2(int level);
+extern void old_bzip2(int level, int suse_quirk);
 
 #define BUFLEN         (64 * 1024)
 
@@ -181,6 +181,7 @@ main(int argc, char **argv)
        int mflag = 0;
        int fflag = 0;
        int xflag = -1;
+       int suse_quirk = 0;
        int ntfs_quirk = 0;
        int level = 6;
        int osflag = GZIP_OS_UNIX;
@@ -269,6 +270,9 @@ main(int argc, char **argv)
                                /* maximum compression but without indicating so */
                                level = 9;
                                xflag = 0;
+                       } else if (strcmp(optarg, "suse") == 0) {
+                               /* SuSe's patched bzip2. (Inexact emulation.) */
+                               suse_quirk = 1;
                        } else {
                                fprintf(stderr, "%s: unknown quirk!\n", progname);
                                usage();
@@ -324,11 +328,7 @@ main(int argc, char **argv)
                }
                gnuzip(STDIN_FILENO, STDOUT_FILENO, origname, timestamp, level, osflag, rsync, new_rsync);
        } else if (bzold) {
-               if (quirks) {
-                       fprintf(stderr, "%s: quirks not supported with --old-bzip\n", progname);
-                       return 1;
-               }
-               old_bzip2(level);
+               old_bzip2(level, suse_quirk);
        } else {
                if (rsync || new_rsync) {
                        fprintf(stderr, "%s: --rsyncable not supported with --zlib\n", progname);
@@ -530,7 +530,7 @@ usage(void)
     " -R --rsyncable           make rsync-friendly archive\n"
     " -r --new-rsyncable       make rsync-friendly archive (new version)\n"
     " \nzlib-specific options:\n"
-    " -k --quirk QUIRK         enable a format quirk (buggy-bsd, ntfs, perl)\n");
+    " -k --quirk QUIRK         enable a format quirk (buggy-bsd, ntfs, perl, suse)\n");
        exit(0);
 }