+ } 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);
+ }