Bug#749044: dpkg: please do not produce a trailing space after the fieldname of multiline fields
Package: dpkg Version: 1.17.9 Severity: wishlist Tags: patch Hi, dpkg produces an unnecessary whitespace after the fieldname of multiline fields. Not having this extra whitespace would save 16kb of an uncompressed Sources file. Here is a simple patch and updated testcase: diff --git a/scripts/Dpkg/Control/HashCore.pm b/scripts/Dpkg/Control/HashCore.pm index 6d6f1c5..155c8ce 100644 --- a/scripts/Dpkg/Control/HashCore.pm +++ b/scripts/Dpkg/Control/HashCore.pm @@ -358,12 +358,18 @@ sub output { $value .= \n $_; } } +# do not print a trailing space if value starts with a newline +if ($value =~ /^\n/) { +$value = $key:$value\n; +} else { +$value = $key: $value\n; +} # Print it out if ($fh) { - print { $fh } $key: $value\n + print { $fh } $value or syserr(_g('write error on control data')); } - $str .= $key: $value\n if defined wantarray; + $str .= $value if defined wantarray; } } return $str; diff --git a/scripts/t/Dpkg_Changelog.t b/scripts/t/Dpkg_Changelog.t index 43bccea..d6372a2 100644 --- a/scripts/t/Dpkg_Changelog.t +++ b/scripts/t/Dpkg_Changelog.t @@ -173,7 +173,7 @@ Urgency: high Maintainer: Frank Lichtenheld fr...@lichtenheld.de Date: Sun, 13 Jan 2008 15:49:19 +0100 Closes: 100 111 222 -Changes: +Changes: fields (2.0-0etch1) stable; urgency=low . * Upload to stable (Closes: #111, #222) @@ -214,7 +214,7 @@ Urgency: medium Maintainer: Frank Lichtenheld dj...@debian.org Date: Sun, 12 Jan 2008 15:49:19 +0100 Closes: 111 222 -Changes: +Changes: fields (2.0-1) unstable frozen; urgency=medium . [ Frank Lichtenheld ] @@ -244,7 +244,7 @@ Distribution: unstable Urgency: low Maintainer: Frank Lichtenheld fr...@lichtenheld.de Date: Sun, 11 Jan 2008 15:49:19 +0100 -Changes: +Changes: fields (2.0~b1-1) unstable; urgency=low,xc-userfield=foobar . * Beta @@ -257,7 +257,7 @@ Urgency: high Maintainer: Frank Lichtenheld dj...@debian.org Date: Sun, 10 Jan 2008 15:49:19 +0100 Closes: 100 -Changes: +Changes: fields (1.0) experimental; urgency=high,xb-userfield2=foobar . * First upload (Closes: #100) -- To UNSUBSCRIBE, email to debian-dpkg-bugs-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Bug#749044: dpkg: please do not produce a trailing space after the fieldname of multiline fields
Hi! On Fri, 2014-05-23 at 13:23:33 +0200, Johannes Schauer wrote: Package: dpkg Version: 1.17.9 Severity: wishlist Tags: patch dpkg produces an unnecessary whitespace after the fieldname of multiline fields. Not having this extra whitespace would save 16kb of an uncompressed Sources file. Yeah, that has bothered me for a while, had pending on fixing it, thanks! Here is a simple patch and updated testcase: I'm merging this now for 1.17.10, although I think I'll be changing it a bit, as it seems it could be done in a different way. Thanks, Guillem -- To UNSUBSCRIBE, email to debian-dpkg-bugs-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Bug#749044: dpkg: please do not produce a trailing space after the fieldname of multiline fields
Hi, Quoting Guillem Jover (2014-05-23 15:57:08) Here's what I'm going to include in the next push. It also covers a case that was not handled in the supplied patch. :) oh super! Thanks for handling this that fast :D cheers, josch -- To UNSUBSCRIBE, email to debian-dpkg-bugs-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Bug#749044: dpkg: please do not produce a trailing space after the fieldname of multiline fields
On Fri, 2014-05-23 at 13:34:27 +0200, Guillem Jover wrote: On Fri, 2014-05-23 at 13:23:33 +0200, Johannes Schauer wrote: Here is a simple patch and updated testcase: I'm merging this now for 1.17.10, although I think I'll be changing it a bit, as it seems it could be done in a different way. Here's what I'm going to include in the next push. It also covers a case that was not handled in the supplied patch. :) Thanks, Guillem diff --git a/scripts/Dpkg/Control/HashCore.pm b/scripts/Dpkg/Control/HashCore.pm index af41c7e..d45e688 100644 --- a/scripts/Dpkg/Control/HashCore.pm +++ b/scripts/Dpkg/Control/HashCore.pm @@ -349,22 +349,25 @@ sub output { # Skip whitespace-only fields next if $$self-{drop_empty} and $value !~ m/\S/; # Escape data to follow control file syntax - my @lines = split(/\n/, $value); - $value = (scalar @lines) ? shift @lines : ''; + my ($first_line, @lines) = split /\n/, $value; + + my $kv = $key:; + $kv .= . $first_line if $first_line; + $kv .= \n; foreach (@lines) { s/\s+$//; if (/^$/ or /^\.+$/) { - $value .= \n .$_; + $kv .= .$_\n; } else { - $value .= \n $_; + $kv .= $_\n; } } # Print it out if ($fh) { - print { $fh } $key: $value\n + print { $fh } $kv or syserr(_g('write error on control data')); } - $str .= $key: $value\n if defined wantarray; + $str .= $kv if defined wantarray; } } return $str; diff --git a/scripts/t/Dpkg_Changelog.t b/scripts/t/Dpkg_Changelog.t index 6fe3407..6a7fb42 100644 --- a/scripts/t/Dpkg_Changelog.t +++ b/scripts/t/Dpkg_Changelog.t @@ -173,7 +173,7 @@ Urgency: high Maintainer: Frank Lichtenheld fr...@lichtenheld.de Date: Sun, 13 Jan 2008 15:49:19 +0100 Closes: 100 111 222 -Changes: +Changes: fields (2.0-0etch1) stable; urgency=low . * Upload to stable (Closes: #111, #222) @@ -214,7 +214,7 @@ Urgency: medium Maintainer: Frank Lichtenheld dj...@debian.org Date: Sun, 12 Jan 2008 15:49:19 +0100 Closes: 111 222 -Changes: +Changes: fields (2.0-1) unstable frozen; urgency=medium . [ Frank Lichtenheld ] @@ -244,7 +244,7 @@ Distribution: unstable Urgency: low Maintainer: Frank Lichtenheld fr...@lichtenheld.de Date: Sun, 11 Jan 2008 15:49:19 +0100 -Changes: +Changes: fields (2.0~b1-1) unstable; urgency=low,xc-userfield=foobar . * Beta @@ -257,7 +257,7 @@ Urgency: high Maintainer: Frank Lichtenheld dj...@debian.org Date: Sun, 10 Jan 2008 15:49:19 +0100 Closes: 100 -Changes: +Changes: fields (1.0) experimental; urgency=high,xb-userfield2=foobar . * First upload (Closes: #100) diff --git a/scripts/t/Dpkg_Control.t b/scripts/t/Dpkg_Control.t index 8668b56..2e842d8 100644 --- a/scripts/t/Dpkg_Control.t +++ b/scripts/t/Dpkg_Control.t @@ -53,7 +53,7 @@ Long-Field: line1 line 3 line 3 line 3 .. line 4 -Empty-Field: +Empty-Field: Package: mypackage1 Architecture: any