use base qw(Exporter);
our @EXPORT_OK = qw(flush_diff);
use URI::Escape qw(uri_escape_utf8);
-use PublicInbox::Hval qw(ascii_html to_attr from_attr);
+use PublicInbox::Hval qw(ascii_html to_attr);
use PublicInbox::Git qw(git_unquote);
# keep track of state so we can avoid redundant HTML tags for
my $PATH_A = '"?a/.+|/dev/null';
my $PATH_B = '"?b/.+|/dev/null';
+# cf. git diff.c :: get_compact_summary
+my $DIFFSTAT_COMMENT = qr/\((?:new|gone|(?:(?:new|mode) [\+\-][lx]))\)/;
+
sub to_html ($$) {
$_[0]->linkify_1($_[1]);
$_[0]->linkify_2(ascii_html($_[1]));
# So only do best-effort handling of renames for common cases;
# which works well in practice. If projects put "=>", or trailing
# spaces in filenames, oh well :P
- $fn =~ s/ +\z//s;
+ $fn =~ s/(?: *$DIFFSTAT_COMMENT)? *\z//so;
$fn =~ s/{(?:.+) => (.+)}/$1/ or $fn =~ s/.* => (.+)/$1/;
$fn = git_unquote($fn);
if (my $attr = to_attr($ctx->{-apfx}.$fn)) {
$ctx->{-anchors}->{$attr} = 1;
+ my $spaces = ($orig =~ s/( +)\z//) ? $1 : '';
$$dst .= " <a\nid=i$attr\nhref=#$attr>" .
- ascii_html($orig) . '</a>'.
+ ascii_html($orig) . '</a>' . $spaces .
to_html($linkify, $rest);
return 1;
}