]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
content_digest_dbg: more compact display w/ git_quote
authorEric Wong <e@80x24.org>
Wed, 26 Mar 2025 20:13:03 +0000 (20:13 +0000)
committerEric Wong <e@80x24.org>
Thu, 27 Mar 2025 08:52:52 +0000 (08:52 +0000)
Make WWW /$MSGID/d/ endpoints and `lei mail-diff' output
less verbose by getting rid of Data::Dumper in favor of
a lightly-modified git_quote output.  The extra [] pairs
from Data::Dumper were unnecessary noise and the quoting
used by git_quote should be more familiar to git users.
Unfortunately, git's escaping of NUL bytes to `\000' is
a bit noisy, so we'll undo that by substituting to `\0'.

lib/PublicInbox/ContentDigestDbg.pm

index 853624f13516dfb28a7c224fe062442215ddea8d..a3ab09c07205aa7fd94ba13da5e4cac67c17ba77 100644 (file)
@@ -2,19 +2,24 @@
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 package PublicInbox::ContentDigestDbg; # cf. PublicInbox::ContentDigest
 use v5.12;
-use Data::Dumper;
+use PublicInbox::Git qw(git_quote);
 use PublicInbox::SHA;
-$Data::Dumper::Useqq = $Data::Dumper::Terse = 1;
 
 sub new { bless [ PublicInbox::SHA->new(256), $_[1] ], __PACKAGE__ }
 
 sub add {
-       $_[0]->[0]->add($_[1]);
-       my @dbg = split(/^/sm, $_[1]);
-       if (@dbg && $dbg[0] =~ /\A(To|Cc)\0/) { # fold excessively long lines
+       my ($dig, $out) = @{$_[0]};
+       $dig->add($_[1]);
+       my @dbg = split /^/sm, $_[1];
+       # fold excessively long lines
+       @dbg && $dbg[0] =~ /\A(?:To|Cc)\0.*?\,/ and
                @dbg = map { split(/,/s, $_) } @dbg;
+       for (@dbg) {
+               $_ = git_quote($_);
+               s/\\000/\\0/g; # less ugly
+               # n.b. caller must (autodie) `close' to error check `say'
+               say $out ' ', $_;
        }
-       print { $_[0]->[1] } Dumper(\@dbg) or die "print $!";
 }
 
 sub hexdigest { $_[0]->[0]->hexdigest }