{"thread":{"id":"13089","subject":"[PATCH (resend)] gitweb: Fix 'history' view for deleted files with history","startedAt":"2008-04-13T12:12:15Z","lastAt":"2008-04-19T08:25:33Z","messageCount":3,"participants":["Jakub Narebski","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"74253","messageId":"20080413121018.3951.45328.stgit@localhost.localdomain","threadId":"13089","inReplyTo":null,"subject":"[PATCH (resend)] gitweb: Fix 'history' view for deleted files with history","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-04-13T12:12:15Z","receivedAt":"2008-04-13T12:12:15Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"When asked for history of a file which is not present in given branch\n(\"HEAD\", i.e. current branch, or given by transient $hash_hase ('hb')\nparameter), but is present deeper in the history (meaning that \"git\nrev-list --full-history $hash_base -- $file_name\" is not empty), and\nthere is no $hash ('h') parameter set for a file, gitweb would spew\nmultiple of \"Use of uninitialized value\" warnings, and some links\nwould be missing.  This commit fixes this bug.\n\nThis bug occurs in the rare cases when \"git log -- <path>\" is empty\nand \"git log --full-history -- <path>\" is not, or to be more exact in\nthe cases when full-history starts later than given branch.  It can\nhappen if you are using handcrafted gitwb URL, or if you follow\ngeneric 'history' link or bookmark for a file which got deleted.\n\nGitweb tried to get file type ('tree', or 'blob', or even 'commit')\nfrom the commit we start searching from (where the file was not\npresent), and not among found commits.  This was the cause of \"Use of\nuninitialized value\" warnings.\n\nThis commit also add tests for such situation to t9500 test.\n\n\nWhile we are it, return HTTP error if there is _no_ history; it means\nthat file or directory was not found (for given branch).  Also error\nout if type of item could not be found: it should not happen now, but\nbetter be sure.\n\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nResend after 1.5.5 release, this time with the test added (which fails\nbefore this patch, and succeds after it).\n\nCommit message was slightly reworded, and improved.\n\n gitweb/gitweb.perl                     |   18 +++++++++++++++---\n t/t9500-gitweb-standalone-no-errors.sh |   16 ++++++++++++++++\n 2 files changed, 31 insertions(+), 3 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex e69d7fd..a48bebb 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -5176,14 +5176,26 @@ sub git_history {\n \tmy $refs = git_get_references();\n \tmy $limit = sprintf(\"--max-count=%i\", (100 * ($page+1)));\n \n+\tmy @commitlist = parse_commits($hash_base, 101, (100 * $page),\n+\t                               $file_name, \"--full-history\");\n+\tif (!@commitlist) {\n+\t\tdie_error('404 Not Found', \"No such file or directory on given branch\");\n+\t}\n+\n \tif (!defined $hash && defined $file_name) {\n-\t\t$hash = git_get_hash_by_path($hash_base, $file_name);\n+\t\t# some commits could have deleted file in question,\n+\t\t# and not have it in tree, but one of them has to have it\n+\t\tfor (my $i = 0; $i <= @commitlist; $i++) {\n+\t\t\t$hash = git_get_hash_by_path($commitlist[$i]{'id'}, $file_name);\n+\t\t\tlast if defined $hash;\n+\t\t}\n \t}\n \tif (defined $hash) {\n \t\t$ftype = git_get_type($hash);\n \t}\n-\n-\tmy @commitlist = parse_commits($hash_base, 101, (100 * $page), $file_name, \"--full-history\");\n+\tif (!defined $ftype) {\n+\t\tdie_error(undef, \"Unknown type of object\");\n+\t}\n \n \tmy $paging_nav = '';\n \tif ($page > 0) {\ndiff --git a/t/t9500-gitweb-standalone-no-errors.sh b/t/t9500-gitweb-standalone-no-errors.sh\nindex 796cd7d..061a259 100755\n--- a/t/t9500-gitweb-standalone-no-errors.sh\n+++ b/t/t9500-gitweb-standalone-no-errors.sh\n@@ -483,6 +483,22 @@ test_expect_success \\\n \t'gitweb_run \"p=.git;a=history;f=file\"'\n test_debug 'cat gitweb.log'\n \n+test_expect_success \\\n+\t'logs: history (implicit HEAD, non-existent file)' \\\n+\t'gitweb_run \"p=.git;a=history;f=non-existent\"'\n+test_debug 'cat gitweb.log'\n+\n+test_expect_success \\\n+\t'logs: history (implicit HEAD, deleted file)' \\\n+\t'git checkout master &&\n+\t echo \"to be deleted\" > deleted_file &&\n+\t git add deleted_file &&\n+\t git commit -m \"Add file to be deleted\" &&\n+\t git rm deleted_file &&\n+\t git commit -m \"Delete file\" &&\n+\t gitweb_run \"p=.git;a=history;f=deleted_file\"'\n+test_debug 'cat gitweb.log'\n+\n # ----------------------------------------------------------------------\n # feed generation\n \n"},{"id":"74744","messageId":"m31w52s1g7.fsf@localhost.localdomain","threadId":"13089","inReplyTo":"20080413121018.3951.45328.stgit@localhost.localdomain","subject":"Re: [PATCH (resend)] gitweb: Fix 'history' view for deleted files with history","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-04-19T08:17:54Z","receivedAt":"2008-04-19T08:17:54Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"What about this patch?  Was it simply overlooked, or does it need some\ncorrections either in patch itself, or in commit message (commit\ndescription)?\n\nI have added test which shows this bug, and information when can it\noccur (besides handcrafting gitweb URLs).\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"74751","messageId":"7v7ieufdz6.fsf@gitster.siamese.dyndns.org","threadId":"13089","inReplyTo":"m31w52s1g7.fsf@localhost.localdomain","subject":"Re: [PATCH (resend)] gitweb: Fix 'history' view for deleted files with history","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-04-19T08:25:33Z","receivedAt":"2008-04-19T08:25:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"I was in a belated merge binge tonight, and applied this to maint.  Sorry\nit took too long but I have simply been very busy.\n"}]}