From a01040ed2ec1e4575947e6d589499a4c7315d90e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 20 Jan 2019 09:42:34 +0000 Subject: viewdiff: support diff-highlighting w/o coderepo Having diff highlighting alone is still useful, even if blob-resolution/recreation is too expensive or unfeasible. --- lib/PublicInbox/View.pm | 18 ++++++++++-------- lib/PublicInbox/ViewDiff.pm | 13 +++++++++---- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 0187ec33..41a45b0b 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -558,15 +558,17 @@ sub add_text_body { return attach_link($upfx, $ct, $p, $fn) unless defined $s; my ($diff, $spfx); - if ($ibx->{-repo_objs} && $s =~ /^(?:diff|---|\+{3}) /ms) { + if ($s =~ /^(?:diff|---|\+{3}) /ms) { $diff = []; - my $n_slash = $upfx =~ tr!/!/!; - if ($n_slash == 0) { - $spfx = '../'; - } elsif ($n_slash == 1) { - $spfx = ''; - } else { # nslash == 2 - $spfx = '../../'; + if ($ibx->{-repo_objs}) { + my $n_slash = $upfx =~ tr!/!/!; + if ($n_slash == 0) { + $spfx = '../'; + } elsif ($n_slash == 1) { + $spfx = ''; + } else { # nslash == 2 + $spfx = '../../'; + } } }; diff --git a/lib/PublicInbox/ViewDiff.pm b/lib/PublicInbox/ViewDiff.pm index 1aad2832..0d1aefb7 100644 --- a/lib/PublicInbox/ViewDiff.pm +++ b/lib/PublicInbox/ViewDiff.pm @@ -40,7 +40,8 @@ sub diff_hunk ($$$$) { my $oid_a = $dctx->{oid_a}; my $oid_b = $dctx->{oid_b}; - (defined($oid_a) && defined($oid_b)) or return "@@ $ca $cb @@"; + (defined($spfx) && defined($oid_a) && defined($oid_b)) or + return "@@ $ca $cb @@"; my ($n) = ($ca =~ /^-(\d+)/); $n = defined($n) ? do { ++$n; "#n$n" } : ''; @@ -53,6 +54,11 @@ sub diff_hunk ($$$$) { $rv .= qq( {Q}$n>$cb @@); } +sub oid ($$$) { + my ($dctx, $spfx, $oid) = @_; + defined($spfx) ? qq({Q}>$oid) : $oid; +} + sub flush_diff ($$$$) { my ($dst, $spfx, $linkify, $diff) = @_; my $state = DSTATE_INIT; @@ -90,11 +96,10 @@ sub flush_diff ($$$$) { } $$dst .= to_html($linkify, $s); } elsif ($s =~ s/^(index $OID_NULL\.\.)($OID_BLOB)\b//o) { - $$dst .= qq($1{Q}>$2); + $$dst .= $1 . oid($dctx, $spfx, $2); $$dst .= to_html($linkify, $s) ; } elsif ($s =~ s/^index ($OID_NULL)(\.\.$OID_BLOB)\b//o) { - $$dst .= 'index '; - $$dst .= qq({Q}>$1$2); + $$dst .= 'index ' . oid($dctx, $spfx, $1) . $2; $$dst .= to_html($linkify, $s); } elsif ($s =~ /^index ($OID_BLOB)\.\.($OID_BLOB)/o) { $dctx->{oid_a} = $1; -- cgit v1.2.3-24-ge0c7