xz: try levels 6 and 9
authorJoey Hess <joey@kitenet.net>
Tue, 31 Jan 2012 20:13:21 +0000 (16:13 -0400)
committerJoey Hess <joey@kitenet.net>
Tue, 31 Jan 2012 20:13:21 +0000 (16:13 -0400)
debian/changelog
debian/control
pristine-xz

index 3133f38..cbb9ed9 100644 (file)
@@ -1,6 +1,8 @@
 pristine-tar (1.18) UNRELEASED; urgency=low
 
-  * pristine-xz: A very simplistic xz recreator.
+  * pristine-xz: A simplistic xz recreator, supporting only the
+    most common xz files. Current success rate on the Debian corpus: 70%.
+    Closes: #499489
 
  -- Joey Hess <joeyh@debian.org>  Mon, 09 Jan 2012 12:36:57 -0400
 
index 2a392a2..e38eaa5 100644 (file)
@@ -12,7 +12,7 @@ Package: pristine-tar
 Architecture: any
 Section: utils
 Depends: xdelta, ${shlibs:Depends}, ${misc:Depends}, perl-modules
-Recommends: pbzip2, bzip2
+Recommends: pbzip2, bzip2, xz-utils
 Description: regenerate pristine tarballs
  pristine-tar can regenerate a pristine upstream tarball using only a small
  binary delta file and a revision control checkout of the upstream branch.
index a0365b3..678193e 100755 (executable)
@@ -108,21 +108,25 @@ sub readxz {
                error "This is not a valid xz archive.";
        }
 
-       # XXX This is the default compression level; we don't currently have
-       # a way to guess the level from the file format, as this level only
-       # presets several other tunables. Correct handling would involve
-       # finding as many preset values as possible, and reconstructing the
-       # compression level from that.
-       my $level = 6;
-
-       return ($level);
+       # XXX We don't currently have a way to guess the level from the
+       # file format, as this level only presets several other tunables.
+       # Correct handling would involve finding as many preset values as
+       # possible, and reconstructing the compression level from that.
+       #
+       # So far in the wild only these levels have been seen.
+       # (Note that level 9 can use a lot of memory.)
+       my $possible_levels = [6, 9];
+
+       return ($possible_levels);
 }
 
 sub predictxzargs {
-       my ($level, $program) = @_;
-
-       my @args=["-z", "-$level"];
+       my ($possible_levels, $program) = @_;
 
+       my @args;
+       foreach my $level (@$possible_levels) {
+               push @args, ["-z", "-$level"];
+       }
        return @args;
 }
 
@@ -154,13 +158,12 @@ sub reproducexz {
        doit_redir($orig, $tmpin, "xz", "-dc");
 
        # read fields from xz headers
-       my ($level) = readxz($orig);
-       debug("level: $level");
+       my ($possible_levels) = readxz($orig);
 
        foreach my $program (@supported_xz_programs) {
                # try to guess the xz arguments that are needed by the
                # header information
-               foreach my $args (predictxzargs($level, $program)) {
+               foreach my $args (predictxzargs($possible_levels, $program)) {
                        testvariant($orig, $tmpin, $program, @$args)
                                && return $program, @$args;
                }
@@ -183,7 +186,7 @@ sub genxz {
        while (@params) {
                my $param=shift @params;
 
-               next if $param=~/^(-[1-9])$/;
+               next if $param=~/^(-[0-9])$/;
                next if $param eq '-z';
                die "paranoia check failed on params from delta (@params)";
        }