[PATCH (BUGFIX)] gitweb: Fix "Use of uninitialized value" error in 'history' view

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When asked for history of a file with no $hash ('h') parameter set,
and which file is not present in current branch ("HEAD" or given by
$hash_hase ('hb') parameter), but is present deeper in the full
history of a branch, 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.  Gitweb tried to get
file type (it means if it is 'tree' or 'blob' or even 'commit', as
'history' view is for single path which can be any of given types)
from the commit we start searching from, and not among found commits.

While we are it, return 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 <jnareb@xxxxxxxxx>
---
There should be no noticeable changes in performance for situation
when bug described above does not occur; gitweb would use one git
command invocation than strictly necessary in the situation which
previosly generated bug.  As it should be rare situation (handcrafted
URL, or "current version" URL for file which got deleted) I think it
is not worth complicating the code to avoid it.

BTW. the t9500-gitweb-standalone-no-errors test does not catch this
bug, unfortunately...

 gitweb/gitweb.perl |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 50922bc..1be75c6 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -5238,14 +5238,26 @@ sub git_history {
 	my $refs = git_get_references();
 	my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
 
+	my @commitlist = parse_commits($hash_base, 101, (100 * $page),
+	                               $file_name, "--full-history");
+	if (!@commitlist) {
+		die_error(undef, "No such path");
+	}
+
 	if (!defined $hash && defined $file_name) {
-		$hash = git_get_hash_by_path($hash_base, $file_name);
+		# some commits could have deleted file in question,
+		# and not have it in tree, but one of them has to have it
+		for (my $i = 0; $i <= @commitlist; $i++) {
+			$hash = git_get_hash_by_path($commitlist[$i]{'id'}, $file_name);
+			last if defined $hash;
+		}
 	}
 	if (defined $hash) {
 		$ftype = git_get_type($hash);
 	}
-
-	my @commitlist = parse_commits($hash_base, 101, (100 * $page), $file_name, "--full-history");
+	if (!defined $ftype) {
+		die_error(undef, "Unknown type of object");
+	}
 
 	my $paging_nav = '';
 	if ($page > 0) {
-- 
1.5.4.4

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux