]> Sergey Matveev's repositories - public-inbox.git/commitdiff
view: perform highlighting for space-prefixed diffs
authorEric Wong <e@80x24.org>
Thu, 16 May 2019 01:23:29 +0000 (01:23 +0000)
committerEric Wong <e@80x24.org>
Thu, 16 May 2019 01:28:33 +0000 (01:28 +0000)
"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
lib/PublicInbox/ViewDiff.pm

index 47a2046e43da31d8533268a56ad6c4d290e50168..35e171b06959e364437c3f884919cd4e8439b104 100644 (file)
@@ -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);
index 6b8d94372405486ca2223e0fc057e79cb24691ac..e9cfc3687ba392f2858f7570908196af75163e2f 100644 (file)
@@ -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;