Переглянути джерело

Dpkg::Compression: Change default values depending on the compressor used

This makes dpkg-source use more appropriate default compression values
depending on the compressor used.

Prompted-by: Timo Juhani Lindfors <timo.lindfors@iki.fi>
Guillem Jover 15 роки тому
батько
коміт
36954c36ab
4 змінених файлів з 32 додано та 10 видалено
  1. 3 0
      debian/changelog
  2. 1 1
      man/dpkg-source.1
  3. 17 8
      scripts/Dpkg/Compression.pm
  4. 11 1
      scripts/t/850_Dpkg_Compression.t

+ 3 - 0
debian/changelog

@@ -193,6 +193,9 @@ dpkg (1.16.1) UNRELEASED; urgency=low
     Thanks to Jonathan Nieder <jrnieder@gmail.com>. Closes: #635683
     Thanks to Jonathan Nieder <jrnieder@gmail.com>. Closes: #635683
   * Clarify the default dpkg-deb compression-levels on the man page.
   * Clarify the default dpkg-deb compression-levels on the man page.
   * Clarify dpkg --update-avail usage error message. Closes: #628055
   * Clarify dpkg --update-avail usage error message. Closes: #628055
+  * Change Dpkg::Compression default values depending on the compressor
+    used, and as such dpkg-source inherits this functionality.
+    Prompted by Timo Juhani Lindfors <timo.lindfors@iki.fi>.
 
 
   [ Updated dpkg translations ]
   [ Updated dpkg translations ]
   * German (Sven Joachim). Closes: #620312
   * German (Sven Joachim). Closes: #620312

+ 1 - 1
man/dpkg-source.1

@@ -153,7 +153,7 @@ dpkg\-dev 1.15.5.
 Compression level to use. As with \fB\-Z\fP it only affects newly created
 Compression level to use. As with \fB\-Z\fP it only affects newly created
 files. Supported values are:
 files. Supported values are:
 .IR 1 " to " 9 ", " best ", and " fast .
 .IR 1 " to " 9 ", " best ", and " fast .
-\fI9\fP is the default.
+The default is \fI9\fP for gzip and bzip2, \fI6\fP for xz and lzma.
 .TP
 .TP
 .BR \-i "[\fIregexp\fP], " \-\-diff\-ignore [=\fIregexp\fP]
 .BR \-i "[\fIregexp\fP], " \-\-diff\-ignore [=\fIregexp\fP]
 You may specify a perl regular expression to match files you want
 You may specify a perl regular expression to match files you want

+ 17 - 8
scripts/Dpkg/Compression.pm

@@ -18,7 +18,7 @@ package Dpkg::Compression;
 use strict;
 use strict;
 use warnings;
 use warnings;
 
 
-our $VERSION = "1.00";
+our $VERSION = "1.01";
 
 
 use Dpkg::ErrorHandling;
 use Dpkg::ErrorHandling;
 use Dpkg::Gettext;
 use Dpkg::Gettext;
@@ -54,26 +54,30 @@ my $COMP = {
 	"file_ext" => "gz",
 	"file_ext" => "gz",
 	"comp_prog" => [ "gzip", "--no-name", "--rsyncable" ],
 	"comp_prog" => [ "gzip", "--no-name", "--rsyncable" ],
 	"decomp_prog" => [ "gunzip" ],
 	"decomp_prog" => [ "gunzip" ],
+	"default_level" => 9,
     },
     },
     "bzip2" => {
     "bzip2" => {
 	"file_ext" => "bz2",
 	"file_ext" => "bz2",
 	"comp_prog" => [ "bzip2" ],
 	"comp_prog" => [ "bzip2" ],
 	"decomp_prog" => [ "bunzip2" ],
 	"decomp_prog" => [ "bunzip2" ],
+	"default_level" => 9,
     },
     },
     "lzma" => {
     "lzma" => {
 	"file_ext" => "lzma",
 	"file_ext" => "lzma",
 	"comp_prog" => [ 'xz', '--format=lzma' ],
 	"comp_prog" => [ 'xz', '--format=lzma' ],
 	"decomp_prog" => [ 'unxz', '--format=lzma' ],
 	"decomp_prog" => [ 'unxz', '--format=lzma' ],
+	"default_level" => 6,
     },
     },
     "xz" => {
     "xz" => {
 	"file_ext" => "xz",
 	"file_ext" => "xz",
 	"comp_prog" => [ "xz" ],
 	"comp_prog" => [ "xz" ],
 	"decomp_prog" => [ "unxz" ],
 	"decomp_prog" => [ "unxz" ],
+	"default_level" => 6,
     },
     },
 };
 };
 
 
 our $default_compression = "gzip";
 our $default_compression = "gzip";
-our $default_compression_level = 9;
+our $default_compression_level = undef;
 
 
 =item $compression_re_file_ext
 =item $compression_re_file_ext
 
 
@@ -117,6 +121,7 @@ sub compression_is_supported {
 Returns the requested property of the compression method. Returns undef if
 Returns the requested property of the compression method. Returns undef if
 either the property or the compression method doesn't exist. Valid
 either the property or the compression method doesn't exist. Valid
 properties currently include "file_ext" for the file extension,
 properties currently include "file_ext" for the file extension,
+"default_level" for the default compression level,
 "comp_prog" for the name of the compression program and "decomp_prog" for
 "comp_prog" for the name of the compression program and "decomp_prog" for
 the name of the decompression program.
 the name of the decompression program.
 
 
@@ -173,25 +178,29 @@ sub compression_set_default {
 =item my $level = compression_get_default_level()
 =item my $level = compression_get_default_level()
 
 
 Return the default compression level used when compressing data. It's "9"
 Return the default compression level used when compressing data. It's "9"
-unless C<compression_set_default_level> has been used to change it.
+for "gzip" and "bzip2", "6" for "xz" and "lzma", unless
+C<compression_set_default_level> has been used to change it.
 
 
 =item compression_set_default_level($level)
 =item compression_set_default_level($level)
 
 
-Change the default compression level. Errors out if the
+Change the default compression level. Passing undef as the level will
+reset it to the compressor specific default, otherwise errors out if the
 level is not valid (see C<compression_is_valid_level>).
 level is not valid (see C<compression_is_valid_level>).
-either a number between 1 and 9 or "fast"
-or "best".
 
 
 =cut
 =cut
 
 
 sub compression_get_default_level {
 sub compression_get_default_level {
-    return $default_compression_level;
+    if (defined $default_compression_level) {
+        return $default_compression_level;
+    } else {
+        return compression_get_property($default_compression, "default_level");
+    }
 }
 }
 
 
 sub compression_set_default_level {
 sub compression_set_default_level {
     my ($level) = @_;
     my ($level) = @_;
     error(_g("%s is not a compression level"), $level)
     error(_g("%s is not a compression level"), $level)
-            unless compression_is_valid_level($level);
+            unless !defined($level) or compression_is_valid_level($level);
     $default_compression_level = $level;
     $default_compression_level = $level;
 }
 }
 
 

+ 11 - 1
scripts/t/850_Dpkg_Compression.t

@@ -13,11 +13,12 @@
 # You should have received a copy of the GNU General Public License
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
-use Test::More tests => 9;
+use Test::More tests => 13;
 
 
 use strict;
 use strict;
 use warnings;
 use warnings;
 
 
+use_ok('Dpkg::Compression');
 use_ok('Dpkg::Compression::FileHandle');
 use_ok('Dpkg::Compression::FileHandle');
 
 
 my $tmpdir = "t.tmp/850_Dpkg_Compression";
 my $tmpdir = "t.tmp/850_Dpkg_Compression";
@@ -84,6 +85,15 @@ sub test_read {
     is_deeply(\@lines, \@read, "$filename correctly read (IO::Handle methods)");
     is_deeply(\@lines, \@read, "$filename correctly read (IO::Handle methods)");
 }
 }
 
 
+# Test changing the default compression levels
+my $old_level = compression_get_default_level();
+compression_set_default_level(1);
+is(compression_get_default_level(), 1, "change default compression level");
+compression_set_default_level(5);
+is(compression_get_default_level(), 5, "change default compression level");
+compression_set_default_level(undef);
+is(compression_get_default_level(), $old_level, "reset default compression level");
+
 # Test write on uncompressed file
 # Test write on uncompressed file
 test_write("$tmpdir/myfile", \&check_uncompressed);
 test_write("$tmpdir/myfile", \&check_uncompressed);