Skip to content

Commit 5634cf2

Browse files
jnarebgitster
authored andcommitted
gitweb: Fix 'history' view for deleted files with history
When asked for history of a file which is not present in given branch ("HEAD", i.e. current branch, or given by transient $hash_hase ('hb') parameter), but is present deeper in the history (meaning that "git rev-list --full-history $hash_base -- $file_name" is not empty), and there is no $hash ('h') parameter set for a file, gitweb would spew multiple of "Use of uninitialized value" warnings, and some links would be missing. This commit fixes this bug. This bug occurs in the rare cases when "git log -- <path>" is empty and "git log --full-history -- <path>" is not, or to be more exact in the cases when full-history starts later than given branch. It can happen if you are using handcrafted gitwb URL, or if you follow generic 'history' link or bookmark for a file which got deleted. Gitweb tried to get file type ('tree', or 'blob', or even 'commit') from the commit we start searching from (where the file was not present), and not among found commits. This was the cause of "Use of uninitialized value" warnings. This commit also add tests for such situation to t9500 test. While we are it, return HTTP error if there is _no_ history; it means that file or directory was not found (for given branch). Also error out if type of item could not be found: it should not happen now, but better be sure. Signed-off-by: Jakub Narebski <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f01f815 commit 5634cf2

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

gitweb/gitweb.perl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5171,14 +5171,26 @@ sub git_history {
51715171
my $refs = git_get_references();
51725172
my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
51735173

5174+
my @commitlist = parse_commits($hash_base, 101, (100 * $page),
5175+
$file_name, "--full-history");
5176+
if (!@commitlist) {
5177+
die_error('404 Not Found', "No such file or directory on given branch");
5178+
}
5179+
51745180
if (!defined $hash && defined $file_name) {
5175-
$hash = git_get_hash_by_path($hash_base, $file_name);
5181+
# some commits could have deleted file in question,
5182+
# and not have it in tree, but one of them has to have it
5183+
for (my $i = 0; $i <= @commitlist; $i++) {
5184+
$hash = git_get_hash_by_path($commitlist[$i]{'id'}, $file_name);
5185+
last if defined $hash;
5186+
}
51765187
}
51775188
if (defined $hash) {
51785189
$ftype = git_get_type($hash);
51795190
}
5180-
5181-
my @commitlist = parse_commits($hash_base, 101, (100 * $page), $file_name, "--full-history");
5191+
if (!defined $ftype) {
5192+
die_error(undef, "Unknown type of object");
5193+
}
51825194

51835195
my $paging_nav = '';
51845196
if ($page > 0) {

t/t9500-gitweb-standalone-no-errors.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,22 @@ test_expect_success \
483483
'gitweb_run "p=.git;a=history;f=file"'
484484
test_debug 'cat gitweb.log'
485485

486+
test_expect_success \
487+
'logs: history (implicit HEAD, non-existent file)' \
488+
'gitweb_run "p=.git;a=history;f=non-existent"'
489+
test_debug 'cat gitweb.log'
490+
491+
test_expect_success \
492+
'logs: history (implicit HEAD, deleted file)' \
493+
'git checkout master &&
494+
echo "to be deleted" > deleted_file &&
495+
git add deleted_file &&
496+
git commit -m "Add file to be deleted" &&
497+
git rm deleted_file &&
498+
git commit -m "Delete file" &&
499+
gitweb_run "p=.git;a=history;f=deleted_file"'
500+
test_debug 'cat gitweb.log'
501+
486502
# ----------------------------------------------------------------------
487503
# feed generation
488504

0 commit comments

Comments
 (0)