+ } else { # commit message, notes, etc
+ $$dst .= $linkify->to_html($y);
+ }
+ }
+}
+
+sub flush_diff ($$$) {
+ my ($dst, $ctx, $cur) = @_;
+ state $LF = qr!\r?\n!;
+ state $ANY = qr![^\r\n]!;
+ state $FN = qr!(?:"?[^/\n]+/[^\r\n]+|/dev/null)!;
+
+ my @top = split(/(
+ (?: # begin header stuff, don't capture filenames, here,
+ # but instead wait for the --- and +++ lines.
+ (?:^diff\x20--git\x20$FN\x20$FN$LF)
+
+ # old mode || new mode || copy|rename|deleted|...
+ (?:^[a-z]$ANY+$LF)*
+ )? # end of optional stuff, everything below is required
+ ^index\x20($OID_BLOB)\.\.($OID_BLOB)$ANY*$LF
+ ^---\x20($FN)$LF
+ ^\+{3}\x20($FN)$LF)/smxo, $$cur);
+ $$cur = undef;
+
+ my $linkify = $ctx->{-linkify};
+ my $dctx; # {}, keys: Q, oid_a, oid_b
+
+ while (defined(my $x = shift @top)) {
+ if (scalar(@top) >= 4 &&
+ $top[1] =~ /\A$OID_BLOB\z/os &&
+ $top[0] =~ /\A$OID_BLOB\z/os) {
+ $dctx = diff_header($dst, \$x, $ctx, \@top);
+ } elsif ($dctx) {
+ my $after = '';
+ 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);
+ }