about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-05-16 01:23:29 +0000
committerEric Wong <e@80x24.org>2019-05-16 01:28:33 +0000
commit1a67b91c1326efa372d1ec957e2494849d894f0b (patch)
tree379f4f22bb009d6c9064c55c2144ee6d5ac8da42 /lib
parentb6f480ed58abc5ae2a426ef4f792621b9d3cf283 (diff)
downloadpublic-inbox-1a67b91c1326efa372d1ec957e2494849d894f0b.tar.gz
"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.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/View.pm4
-rw-r--r--lib/PublicInbox/ViewDiff.pm6
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 47a2046e..35e171b0 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 6b8d9437..e9cfc368 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;