diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index fde804593b..8c2d9b8eef 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -2339,12 +2339,14 @@ sub format_extended_diff_header_line { $line .= $cgi->a({-href=>$to->{'href'}, -class=>"path"}, esc_path($to->{'file'})); } - # match single - if ($line =~ m/\s(\d{6})$/) { - $line .= ' (' . - file_type_long($1) . - ')'; + + # Temporarily remove a trailing so an index line ends with its + # object IDs and can be shortened below. + my $mode; + if ($line =~ s/\s(\d{6})$//) { + $mode = $1; } + # match if ($line =~ oid_nlen_prefix_infix_regex($sha1_len, "index ", ",") | $line =~ oid_nlen_prefix_infix_regex($sha256_len, "index ", ",")) { @@ -2388,6 +2390,12 @@ sub format_extended_diff_header_line { my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'}); $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!; } + if (defined $mode) { + $line .= " $mode" . + ' (' . + file_type_long($mode) . + ')'; + } return $line . "
\n"; } diff --git a/t/t9502-gitweb-standalone-parse-output.sh b/t/t9502-gitweb-standalone-parse-output.sh index 9587ce212a..00cf077e52 100755 --- a/t/t9502-gitweb-standalone-parse-output.sh +++ b/t/t9502-gitweb-standalone-parse-output.sh @@ -115,6 +115,19 @@ test_expect_success 'snapshot: hierarchical branch name (xx/test)' ' ' test_debug 'cat gitweb.headers' +test_expect_success 'commitdiff: index line shortens hashes with mode' ' + old_blob=$(git rev-parse HEAD:foo) && + old_short=$(git rev-parse --short=7 HEAD:foo) && + echo changed >foo && + git commit -am "change foo" && + new_blob=$(git rev-parse HEAD:foo) && + new_short=$(git rev-parse --short=7 HEAD:foo) && + gitweb_run "p=.git;a=commitdiff;h=HEAD" && + test_grep ">${old_short}\\.\\.]*>${new_short} 100644 (file)" \ + gitweb.body && + test_grep ! "index ${old_blob}\\.\\.${new_blob} 100644" gitweb.body +' + # ---------------------------------------------------------------------- # forks of projects