avoid redundancies in pristine-gz
authorJoey Hess <joey@gnu.kitenet.net>
Mon, 13 Apr 2009 18:52:42 +0000 (14:52 -0400)
committerJoey Hess <joey@gnu.kitenet.net>
Mon, 13 Apr 2009 18:52:42 +0000 (14:52 -0400)
Refactoring to avoid need to explicitly return the same args that were just
tested.

pristine-gz

index e43bec79c67f09560a783791819c7853486a56d9..3844fc4e0881eb303eed14ee55bcd315ce8f10bc 100755 (executable)
@@ -221,15 +221,6 @@ sub comparefiles {
        return $? >> 8;
 }
 
-sub testvariant {
-       my ($orig, $tempin, $tempout, @args) = @_;
-       # Use the variant of gzip defined by @args to compress $tempin to
-       # $tempout and compare the result to $orig
-
-       doit_redir($tempin, $tempout, 'zgz', @args, '-c');
-       return !comparefiles($orig, $tempout);
-}
-
 sub reproducegz {
        my ($orig, $tempin, $tempout) = (shift, shift, shift);
        doit_redir($orig, $tempin, "gzip", "-dc");
@@ -244,12 +235,13 @@ sub reproducegz {
        my @args = predictgzipargs($flags, $timestamp, $level);
        my @extraargs = ("-F", $name, "-T", $timestamp);
 
+       my @try;
+
        if ($os == GZIP_OS_UNIX) {
                # for 98% of the cases the simple heuristic above works
-               testvariant($orig, $tempin, $tempout, '--gnu', @args, @extraargs)
-                       && return $name, $timestamp, '--gnu', @args;
-               testvariant($orig, $tempin, $tempout, '--gnu', @args, @extraargs, '--rsyncable')
-                       && return $name, $timestamp, '--gnu', @args, '--rsyncable';
+               # and it was produced by gnu gzip.
+               push @try, ['--gnu', @args];
+               push @try, ['--gnu', @args, '--rsyncable'];
        }
 
        if ($name =~ /\//) {
@@ -266,22 +258,26 @@ sub reproducegz {
        # gzip which is using the zlib library; try with our version of
        # bsd-gzip with added support for the undocumented GNU gzip options
        # -m and -M
-       testvariant($orig, $tempin, $tempout, @args, @extraargs)
-               && return $name, $timestamp, @args;
+       push @try, [@args];
 
        # apparently, there is an old version of bsd-gzip (or a similar tool
        # based on zlib) that creates gz using maximum compression (-9) but
        # does not indicate so in the headers. surprisingly, there are many
        # .gz out there.
-       testvariant($orig, $tempin, $tempout, @args, @extraargs, '--quirk', 'buggy-bsd')
-               && return $name. $timestamp, @args, '--quirk', 'buggy-bsd';
+       push @try, [@args, '--quirk', 'buggy-bsd'];
 
        # Windows' NTFS gzip implementation; quirk is really really evil
        # it should be the last test: it can result in a corrupted archive!
        if ($os == GZIP_OS_NTFS) {
                pop @args; pop @args; # ntfs quirk implies NTFS osflag
-               testvariant($orig, $tempin, $tempout, @args, @extraargs, '--quirk', 'ntfs')
-                       && return $name, $timestamp, @args, '--quirk', 'ntfs';
+               push @try, [@args, '--quirk', 'ntfs'];
+       }
+
+       foreach my $variant (@try) {
+               doit_redir($tempin, $tempout, 'zgz', @$variant, @extraargs, '-c');
+               if (!comparefiles($orig, $tempout)) {
+                       return $name, $timestamp, @$variant;
+               }
        }
 
        print STDERR "pristine-gz failed to reproduce build of $orig\n";