git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH (resend)] gitweb: Fix 'history' view for deleted files with history
@ 2008-04-13 12:12 Jakub Narebski
  2008-04-19  8:17 ` Jakub Narebski
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Narebski @ 2008-04-13 12:12 UTC (permalink / raw)
  To: git

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 <jnareb@gmail.com>
---
Resend after 1.5.5 release, this time with the test added (which fails
before this patch, and succeds after it).

Commit message was slightly reworded, and improved.

 gitweb/gitweb.perl                     |   18 +++++++++++++++---
 t/t9500-gitweb-standalone-no-errors.sh |   16 ++++++++++++++++
 2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index e69d7fd..a48bebb 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -5176,14 +5176,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('404 Not Found', "No such file or directory on given branch");
+	}
+
 	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) {
diff --git a/t/t9500-gitweb-standalone-no-errors.sh b/t/t9500-gitweb-standalone-no-errors.sh
index 796cd7d..061a259 100755
--- a/t/t9500-gitweb-standalone-no-errors.sh
+++ b/t/t9500-gitweb-standalone-no-errors.sh
@@ -483,6 +483,22 @@ test_expect_success \
 	'gitweb_run "p=.git;a=history;f=file"'
 test_debug 'cat gitweb.log'
 
+test_expect_success \
+	'logs: history (implicit HEAD, non-existent file)' \
+	'gitweb_run "p=.git;a=history;f=non-existent"'
+test_debug 'cat gitweb.log'
+
+test_expect_success \
+	'logs: history (implicit HEAD, deleted file)' \
+	'git checkout master &&
+	 echo "to be deleted" > deleted_file &&
+	 git add deleted_file &&
+	 git commit -m "Add file to be deleted" &&
+	 git rm deleted_file &&
+	 git commit -m "Delete file" &&
+	 gitweb_run "p=.git;a=history;f=deleted_file"'
+test_debug 'cat gitweb.log'
+
 # ----------------------------------------------------------------------
 # feed generation
 

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

* Re: [PATCH (resend)] gitweb: Fix 'history' view for deleted files with history
  2008-04-13 12:12 [PATCH (resend)] gitweb: Fix 'history' view for deleted files with history Jakub Narebski
@ 2008-04-19  8:17 ` Jakub Narebski
  2008-04-19  8:25   ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Narebski @ 2008-04-19  8:17 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

What about this patch?  Was it simply overlooked, or does it need some
corrections either in patch itself, or in commit message (commit
description)?

I have added test which shows this bug, and information when can it
occur (besides handcrafting gitweb URLs).
-- 
Jakub Narebski
Poland
ShadeHawk on #git

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

* Re: [PATCH (resend)] gitweb: Fix 'history' view for deleted files with history
  2008-04-19  8:17 ` Jakub Narebski
@ 2008-04-19  8:25   ` Junio C Hamano
  0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2008-04-19  8:25 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: git

I was in a belated merge binge tonight, and applied this to maint.  Sorry
it took too long but I have simply been very busy.

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

end of thread, other threads:[~2008-04-19  8:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-13 12:12 [PATCH (resend)] gitweb: Fix 'history' view for deleted files with history Jakub Narebski
2008-04-19  8:17 ` Jakub Narebski
2008-04-19  8:25   ` Junio C Hamano

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).