use PublicInbox::Hval qw(ascii_html to_attr from_attr);
use PublicInbox::Git qw(git_unquote);
+# keep track of state so we can avoid redundant HTML tags for
+# identically-classed lines
sub DSTATE_INIT () { 0 }
sub DSTATE_STAT () { 1 }
sub DSTATE_HEAD () { 2 } # /^diff --git /, /^index /, /^--- /, /^\+\+\+ /
sub DSTATE_CTX () { 3 } # /^ /
sub DSTATE_ADD () { 4 } # /^\+/
sub DSTATE_DEL () { 5 } # /^\-/
+
+# maps the DSTATE_* to CSS class names compatible with what cgit uses:
my @state2class = (
'', # init
'', # stat
if ($s =~ /^---$/) {
to_state($dst, $state, DSTATE_STAT);
$$dst .= $s;
- } elsif ($s =~ /^ /) {
+ } elsif ($s =~ /^ / || ($s =~ /^$/ && $state >= DSTATE_CTX)) {
# works for common cases, but not weird/long filenames
if ($state == DSTATE_STAT &&
$s =~ /^ (.+)( +\| .*\z)/s) {
$$dst .= '</span>';
$state = DSTATE_CTX;
$$dst .= to_html($linkify, $s);
- } elsif ($s =~ m!^--- $PATH_A! ||
- $s =~ m!^\+{3} $PATH_B!) {
+ } elsif ($s =~ m!^--- (?:$PATH_A)! ||
+ $s =~ m!^\+{3} (?:$PATH_B)!) {
# color only (no oid link) if missing dctx->{oid_*}
$state <= DSTATE_STAT and
to_state($dst, $state, DSTATE_HEAD);