From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 0E3C11F461 for ; Thu, 16 May 2019 01:29:12 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] view: perform highlighting for space-prefixed diffs Date: Thu, 16 May 2019 01:29:12 +0000 Message-Id: <20190516012912.15783-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: "git format-patch --interdiff" and similar can prefix diffs with leading white space. Teach our diff parser to account for it and set appropriate CSS classes for them. --- lib/PublicInbox/View.pm | 4 +++- lib/PublicInbox/ViewDiff.pm | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 47a2046..35e171b 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -568,7 +568,9 @@ sub add_text_body { # always support diff-highlighting, but we can't linkify hunk # headers for solver unless some coderepo are configured: my $diff; - if ($s =~ /^(?:diff|---|\+{3}) /ms) { + if ($s =~ /^([ \t]*)(?:diff|---|\+{3}) /ms) { + $ctx->{-dpfx} = $1 if $1; # for format-patch --interdiff output + # diffstat anchors do not link across attachments or messages: $idx[0] = $upfx . $idx[0] if $upfx ne ''; $ctx->{-apfx} = join('/', @idx); diff --git a/lib/PublicInbox/ViewDiff.pm b/lib/PublicInbox/ViewDiff.pm index 6b8d943..e9cfc36 100644 --- a/lib/PublicInbox/ViewDiff.pm +++ b/lib/PublicInbox/ViewDiff.pm @@ -141,8 +141,14 @@ sub flush_diff ($$$) { my $spfx = $ctx->{-spfx}; my $state = DSTATE_INIT; my $dctx = { Q => '' }; # {}, keys: oid_a, oid_b, path_a, path_b + my $dpfx = $ctx->{-dpfx}; # leading spaces for interdiff + my $dpfx_re = qr/\A$dpfx/ if defined $dpfx; foreach my $s (@$diff) { + if (defined($dpfx)) { + $s =~ s/$dpfx_re//; + $$dst .= $dpfx; + } if ($s =~ /^---$/) { to_state($dst, $state, DSTATE_STAT); $$dst .= $s; -- EW