- anchor1($dst, $ctx, $linkify, $pb, $s) and next;
- $$dst .= to_html($linkify, $s);
- } elsif ($s =~ s/^(index $OID_NULL\.\.)($OID_BLOB)\b//o) {
- $$dst .= $1 . oid($dctx, $spfx, $2);
- $dctx = { Q => '' };
- $$dst .= to_html($linkify, $s) ;
- } elsif ($s =~ s/^index ($OID_BLOB)(\.\.$OID_NULL)\b//o) {
- $$dst .= 'index ' . oid($dctx, $spfx, $1) . $2;
- $dctx = { Q => '' };
- $$dst .= to_html($linkify, $s);
- } elsif ($s =~ /^index ($OID_BLOB)\.\.($OID_BLOB)/o) {
- $dctx->{oid_a} = $1;
- $dctx->{oid_b} = $2;
- $$dst .= to_html($linkify, $s);
- } elsif ($s =~ s/^@@ (\S+) (\S+) @@//) {
- $$dst .= '</span>' if $state2class[$state];
- $$dst .= qq(<span\nclass="hunk">);
- $$dst .= diff_hunk($dctx, $spfx, $1, $2);
- $$dst .= '</span>';
- $state = DSTATE_CTX;
- $$dst .= to_html($linkify, $s);
- } elsif ($s =~ m!^--- (?:$PATH_A)!o ||
- $s =~ m!^\+{3} (?:$PATH_B)!o) {
- # color only (no oid link) if missing dctx->{oid_*}
- $state <= DSTATE_STAT and
- to_state($dst, $state, DSTATE_HEAD);
- $$dst .= to_html($linkify, $s);
- } elsif ($s =~ /^\+/) {
- if ($state != DSTATE_ADD && $state > DSTATE_STAT) {
- to_state($dst, $state, DSTATE_ADD);
- }
- $$dst .= to_html($linkify, $s);
- } elsif ($s =~ /^-/) {
- if ($state != DSTATE_DEL && $state > DSTATE_STAT) {
- to_state($dst, $state, DSTATE_DEL);
+ } else { # commit message, notes, etc
+ $$dst .= $linkify->to_html($y);
+ }
+ }
+}
+
+# callers must do CRLF => LF conversion before calling this
+sub flush_diff ($$) {
+ my ($ctx, $cur) = @_;
+
+ my @top = split($EXTRACT_DIFFS, $$cur);
+ undef $$cur; # free memory
+
+ my $linkify = $ctx->{-linkify};
+ my $dst = $ctx->{obuf};
+ my $dctx; # {}, keys: Q, oid_a, oid_b
+
+ while (defined(my $x = shift @top)) {
+ if (scalar(@top) >= 4 &&
+ $top[1] =~ $IS_OID &&
+ $top[0] =~ $IS_OID) {
+ $dctx = diff_header(\$x, $ctx, \@top);
+ } elsif ($dctx) {
+ my $after = '';
+
+ # Quiet "Complex regular subexpression recursion limit"
+ # warning. Perl will truncate matches upon hitting
+ # that limit, giving us more (and shorter) scalars than
+ # would be ideal, but otherwise it's harmless.
+ #
+ # We could replace the `+' metacharacter with `{1,100}'
+ # to limit the matches ourselves to 100, but we can
+ # let Perl do it for us, quietly.
+ no warnings 'regexp';
+
+ for my $s (split(/((?:(?:^\+[^\n]*\n)+)|
+ (?:(?:^-[^\n]*\n)+)|
+ (?:^@@ [^\n]+\n))/xsm, $x)) {
+ if (!defined($dctx)) {
+ $after .= $s;
+ } elsif ($s =~ s/\A@@ (\S+) (\S+) @@//) {
+ $$dst .= qq(<span\nclass="hunk">);
+ diff_hunk($dst, $dctx, $1, $2);
+ $$dst .= $linkify->to_html($s);
+ $$dst .= '</span>';
+ } elsif ($s =~ /\A\+/) {
+ $$dst .= qq(<span\nclass="add">);
+ $$dst .= $linkify->to_html($s);
+ $$dst .= '</span>';
+ } elsif ($s =~ /\A-- $/sm) { # email sig starts
+ $dctx = undef;
+ $after .= $s;
+ } elsif ($s =~ /\A-/) {
+ $$dst .= qq(<span\nclass="del">);
+ $$dst .= $linkify->to_html($s);
+ $$dst .= '</span>';
+ } else {
+ $$dst .= $linkify->to_html($s);
+ }