git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH (BUGFIX)] gitweb: Fix "Use of uninitialized value" error in 'history' view
@ 2008-04-04 14:23 Jakub Narebski
  2008-04-05  7:51 ` Junio C Hamano
  2008-04-05 16:43 ` Gerrit Pape
  0 siblings, 2 replies; 8+ messages in thread
From: Jakub Narebski @ 2008-04-04 14:23 UTC (permalink / raw)
  To: git

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@gmail.com>
---
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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2008-04-06 10:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-04 14:23 [PATCH (BUGFIX)] gitweb: Fix "Use of uninitialized value" error in 'history' view Jakub Narebski
2008-04-05  7:51 ` Junio C Hamano
2008-04-05  8:09   ` Jakub Narebski
2008-04-05 16:43 ` Gerrit Pape
2008-04-05 17:16   ` Jakub Narebski
2008-04-05 17:38     ` Jakub Narebski
2008-04-05 20:13       ` [PATCH] Revert "gitweb: Add 'status_str' to parse_difftree_raw_line output" Jakub Narebski
2008-04-06 10:22     ` [PATCH (BUGFIX)] gitweb: Fix "Use of uninitialized value" error in 'history' view Gerrit Pape

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).