Skip to content

Commit 4132c8e

Browse files
committed
Merge branch 'tl/gitweb-shorten-hashes-with-modes' into jch
The object ID shortening and linking in the 'commitdiff' view of 'gitweb' has been corrected to work even when the index line carries a trailing file mode. * tl/gitweb-shorten-hashes-with-modes: gitweb: shorten index hashes with trailing file modes
2 parents 564f54e + fda513d commit 4132c8e

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

gitweb/gitweb.perl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,12 +2339,14 @@ sub format_extended_diff_header_line {
23392339
$line .= $cgi->a({-href=>$to->{'href'}, -class=>"path"},
23402340
esc_path($to->{'file'}));
23412341
}
2342-
# match single <mode>
2343-
if ($line =~ m/\s(\d{6})$/) {
2344-
$line .= '<span class="info"> (' .
2345-
file_type_long($1) .
2346-
')</span>';
2342+
2343+
# Temporarily remove a trailing <mode> so an index line ends with its
2344+
# object IDs and can be shortened below.
2345+
my $mode;
2346+
if ($line =~ s/\s(\d{6})$//) {
2347+
$mode = $1;
23472348
}
2349+
23482350
# match <hash>
23492351
if ($line =~ oid_nlen_prefix_infix_regex($sha1_len, "index ", ",") |
23502352
$line =~ oid_nlen_prefix_infix_regex($sha256_len, "index ", ",")) {
@@ -2388,6 +2390,12 @@ sub format_extended_diff_header_line {
23882390
my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
23892391
$line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
23902392
}
2393+
if (defined $mode) {
2394+
$line .= " $mode" .
2395+
'<span class="info"> (' .
2396+
file_type_long($mode) .
2397+
')</span>';
2398+
}
23912399

23922400
return $line . "<br/>\n";
23932401
}

t/t9502-gitweb-standalone-parse-output.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,19 @@ test_expect_success 'snapshot: hierarchical branch name (xx/test)' '
115115
'
116116
test_debug 'cat gitweb.headers'
117117

118+
test_expect_success 'commitdiff: index line shortens hashes with mode' '
119+
old_blob=$(git rev-parse HEAD:foo) &&
120+
old_short=$(git rev-parse --short=7 HEAD:foo) &&
121+
echo changed >foo &&
122+
git commit -am "change foo" &&
123+
new_blob=$(git rev-parse HEAD:foo) &&
124+
new_short=$(git rev-parse --short=7 HEAD:foo) &&
125+
gitweb_run "p=.git;a=commitdiff;h=HEAD" &&
126+
test_grep ">${old_short}</a>\\.\\.<a [^>]*>${new_short}</a> 100644<span class=\"info\"> (file)</span>" \
127+
gitweb.body &&
128+
test_grep ! "index ${old_blob}\\.\\.${new_blob} 100644" gitweb.body
129+
'
130+
118131
# ----------------------------------------------------------------------
119132
# forks of projects
120133

0 commit comments

Comments
 (0)