{"thread":{"id":"29456","subject":"Fwd: Git-web error","startedAt":"2012-01-27T18:15:01Z","lastAt":"2012-02-15T10:04:54Z","messageCount":14,"participants":["rajesh boyapati","Jakub Narebski","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"183195","messageId":"61c866a5-31a0-4994-ae29-2086f18e707b@o9g2000yqa.googlegroups.com","threadId":"29456","inReplyTo":"5fa08a8b-f0a2-4796-bf0d-06a8f13bf703@b23g2000yqn.googlegroups.com","subject":"Fwd: Git-web error","fromName":"rajesh boyapati","fromEmail":"boyapatisrajesh@gmail.com","sentAt":"2012-01-27T18:15:01Z","receivedAt":"2012-01-27T18:15:01Z","isPatch":false,"sender":{"key":"boyapatisrajesh@gmail.com","avatar":null},"body":"\n\n\n---------- Forwarded message ----------\nFrom: rajesh boyapati <boyapatisraj...@gmail.com>\nDate: Jan 25, 7:10 pm\nSubject: Git-web error\nTo: Repo and Gerrit Discussion\n\n\nHi,\n\nWe integrated git-web to our gerrit Code-review.\nI installed gitweb using the command:\n$ sudo apt-get install gitweb\nThen I configured gitweb to our gerrit using the command:\n$ git config --file $SITE_PATH/etc/gerrit.config gitweb.cgi /usr/lib/\ncgi-bin/gitweb.cgi\nNow the gitweb is added to gerrit.config and in gerrit config file, it\nlooks like\n[gitweb]\n        cgi = /usr/lib/cgi-bin/gitweb.cgi\nThen, restarted gerrit server.\n\nWhen I go to one of the projects in gerrit through gitweb and when I\nclick \"summary\", I am getting the below error.\nIf I click other tabs(log, shortlog, commit, tree,etc) after clicking\n\"summary\", I am getting following error in error-log.\nIf I click other tabs(log, shortlog, commit, tree,etc) before clicking\n\"summary\", everything works fine.\n\nError:\n=================================================================\n[2012-01-25 18:50:32,334] ERROR\ncom.google.gerrit.httpd.gitweb.GitWebServlet : CGI: [Wed Jan 25\n18:50:32 2012] gitweb.cgi: Use of uninitialized value $head in string\neq at /usr/lib/cgi-bin/gitweb.cgi line 4720.\n[2012-01-25 18:50:35,658] ERROR\ncom.google.gerrit.httpd.gitweb.GitWebServlet : CGI: [Wed Jan 25\n18:50:35 2012] gitweb.cgi: Use of uninitialized value $commit_id in\nopen at /usr/lib/cgi-bin/gitweb.cgi line 2817.\n[2012-01-25 18:50:35,660] ERROR\ncom.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: bad\nrevision ''\n[2012-01-25 18:50:39,209] ERROR\ncom.google.gerrit.httpd.gitweb.GitWebServlet : CGI: [Wed Jan 25\n18:50:39 2012] gitweb.cgi: Use of uninitialized value $commit_id in\nopen at /usr/lib/cgi-bin/gitweb.cgi line 2817.\n[2012-01-25 18:50:39,210] ERROR\ncom.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: bad\nrevision ''\n[2012-01-25 18:50:40,656] ERROR\ncom.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: bad\nrevision 'HEAD'\n[2012-01-25 18:53:17,097] ERROR\ncom.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: bad\nrevision 'HEAD'\n[2012-01-25 18:53:17,113] ERROR\ncom.google.gerrit.httpd.gitweb.GitWebServlet : CGI: [Wed Jan 25\n18:53:17 2012] gitweb.cgi: Use of uninitialized value $head in string\neq at /usr/lib/cgi-bin/gitweb.cgi line 4720.\n=================================================================\n\nCan any one help me on how to resolve this issue?.\n\nThanks,\nRajesh.\n"},{"id":"183203","messageId":"m362fwesdw.fsf_-_@localhost.localdomain","threadId":"29456","inReplyTo":"61c866a5-31a0-4994-ae29-2086f18e707b@o9g2000yqa.googlegroups.com","subject":"Re: Fwd: Gitweb error","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2012-01-27T21:39:58Z","receivedAt":"2012-01-27T21:39:58Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"rajesh boyapati <boyapatisrajesh@gmail.com> writes:\n\n> We integrated git-web to our gerrit Code-review.\n> I installed gitweb using the command:\n> $ sudo apt-get install gitweb\n> Then I configured gitweb to our gerrit using the command:\n> $ git config --file $SITE_PATH/etc/gerrit.config gitweb.cgi /usr/lib/\n> cgi-bin/gitweb.cgi\n> Now the gitweb is added to gerrit.config and in gerrit config file, it\n> looks like\n> [gitweb]\n>         cgi = /usr/lib/cgi-bin/gitweb.cgi\n> Then, restarted gerrit server.\n\nThis combination of gitweb (which version?) and Gerrit can be hard to\ndebug, unfortunately.\n \n> When I go to one of the projects in gerrit through gitweb and when I\n> click \"summary\", I am getting the below error.\n> If I click other tabs(log, shortlog, commit, tree,etc) after clicking\n> \"summary\", I am getting following error in error-log.\n> If I click other tabs(log, shortlog, commit, tree,etc) before clicking\n> \"summary\", everything works fine.\n> \n> Error:\n> =================================================================\n> [2012-01-25 18:50:32,334] ERROR\n> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: [Wed Jan 25\n> 18:50:32 2012] gitweb.cgi: Use of uninitialized value $head in string\n> eq at /usr/lib/cgi-bin/gitweb.cgi line 4720.\n\nCould you show this line and about 3 lines of context in your\ngitweb.cgi?\n\n> [2012-01-25 18:50:35,658] ERROR\n> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: [Wed Jan 25\n> 18:50:35 2012] gitweb.cgi: Use of uninitialized value $commit_id in\n> open at /usr/lib/cgi-bin/gitweb.cgi line 2817.\n\nSame here.\n\n> [2012-01-25 18:50:35,660] ERROR\n> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: bad\n> revision ''\n\nIt looks like gitweb incorrectly gets empty revision\nparameter... strange.\n\n\n-- \nJakub Narebski\n"},{"id":"183234","messageId":"201201290137.17556.jnareb@gmail.com","threadId":"29456","inReplyTo":"CA+EqV8w5qz+iwg_PPB4M5Q-LS48B=yncR9UdR-r58BLtAEPPrA@mail.gmail.com","subject":"Re: Fwd: Gitweb error","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2012-01-29T00:37:16Z","receivedAt":"2012-01-29T00:37:16Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"On Fri, 27 Jan 2012, rajesh boyapati wrote:\n> On Fri, Jan 27, 2012 at 3:39 PM, Jakub Narebski <jnareb@gmail.com> wrote:\n> > rajesh boyapati <boyapatisrajesh@gmail.com> writes:\n\n> > > When I go to one of the projects in gerrit through gitweb and when I\n> > > click \"summary\", I am getting the below error.\n> > > If I click other tabs(log, shortlog, commit, tree,etc) after clicking\n> > > \"summary\", I am getting following error in error-log.\n> > > If I click other tabs(log, shortlog, commit, tree,etc) before clicking\n> > > \"summary\", everything works fine.\n\nIt is strange that you get an intermittent error like this, and make\nit even harder to debug - HTTP is stateless.\n\n> > > Error:\n> > > =================================================================\n> > > [2012-01-25 18:50:32,334] ERROR\n> > > com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: [Wed Jan 25\n> > > 18:50:32 2012] gitweb.cgi: Use of uninitialized value $head in string\n> > > eq at /usr/lib/cgi-bin/gitweb.cgi line 4720.\n> >\n> > Could you show this line and about 3 lines of context in your\n> > gitweb.cgi?\n> >\n> \n>     my $alternate = 1;\n>     for (my $i = $from; $i <= $to; $i++) {\n>         my $entry = $headlist->[$i];\n>         my %ref = %$entry;\n>         my $curr = $ref{'id'} eq $head;\n>         if ($alternate) {\n>             print \"<tr class=\\\"dark\\\">\\n\";\n>         } else {\n>             print \"<tr class=\\\"light\\\">\\n\";\n>         }\n>         $alternate ^= 1;\n \nHmmmm... I see that we do not check if $head is defined here before using\nit.  This can happen legitimately if we are on yet to be born orphan branch\n(so $head, which should be named $head_at, is undefined) but there exist\nother branches (so $headlist is not empty).\n\nBut I don't think it is what happened in your case, is it?\n\n[...]\n-- \nJakub Narebski\nPoland\n"},{"id":"183362","messageId":"201201302008.48421.jnareb@gmail.com","threadId":"29456","inReplyTo":"CA+EqV8xB6vcDrqM3EY7uRfu0c7sOj6FbMXci+5w2qgi5RSWrbw@mail.gmail.com","subject":"Re: Fwd: Gitweb error","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2012-01-30T19:08:48Z","receivedAt":"2012-01-30T19:08:48Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"On Mon, 30 Jan 2012, rajesh boyapati wrote:\n> 2012/1/28 Jakub Narebski <jnareb@gmail.com>\n>> On Fri, 27 Jan 2012, rajesh boyapati wrote:\n\n>>>     my $alternate = 1;\n>>>     for (my $i = $from; $i <= $to; $i++) {\n>>>         my $entry = $headlist->[$i];\n>>>         my %ref = %$entry;\n>>>         my $curr = $ref{'id'} eq $head;\n>>>         if ($alternate) {\n>>>             print \"<tr class=\\\"dark\\\">\\n\";\n>>>         } else {\n>>>             print \"<tr class=\\\"light\\\">\\n\";\n>>>         }\n>>>         $alternate ^= 1;\n>>\n>> Hmmmm... I see that we do not check if $head is defined here before using\n>> it.  This can happen legitimately if we are on yet to be born orphan branch\n>> (so $head, which should be named $head_at, is undefined) but there exist\n>> other branches (so $headlist is not empty).\n>>\n>> But I don't think it is what happened in your case, is it?\n\ntldr; It did happen.\n \n> For my git projects on gerrit, our main branch name is \"base\".\n> We don't have any code on \"master\" branch.\n> May be the $HEAD is looking for master branch(or checked out branch in git\n> project).--> In our case, \"master\" is an empty branch.\n> Also, In the git projects, the HEAD file is pointing to \"ref:\n> refs/heads/master\".\n> So, I think that's the reason for errors.\n> \n> How can I make $HEAD to point to a branch other than \"master\"?.\n>   a) I can do this by pointing HEAD file in git projects to other branch\n[...]\n>   b) Is there any way, other than doing above step (a) ?.\n>      I mean I don't want to have a code on \"master\" branch and also I\n>      don't want to point HEAD file in git projects to some other branch.\n>      Do I need to make any modifications to \"gitweb.cgi\" for this?\n\nNow that I know the source of this error, I can write test case\nfor it, and fix it.  I'll try to do it soon.\n\nSo finally what you would need for (b) is just upgrade gitweb.\n-- \nJakub Narebski\nPoland\n"},{"id":"183763","messageId":"201202032233.05324.jnareb@gmail.com","threadId":"29456","inReplyTo":"CA+EqV8y3dhR8+PJbMxMNEsGjDOx6dxtPYjn8kDvAZxCAO7iS5w@mail.gmail.com","subject":"[PATCH] gitweb: Deal with HEAD pointing to unborn branch in \"heads\" view","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2012-02-03T21:33:05Z","receivedAt":"2012-02-03T21:33:05Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"On Mon, 30 Jan 2012, rajesh boyapati wrote:\n> \n> Thank you for your Suggestions in finding the error in my case.\n> Do you have a blog, so that, I can know your updates about gitweb.\n\nNo, I don't have a blog, though I might use Git page on Google+ to\nannounce larger changes.  \n\nI am posting this to you to announce partial fix for your problem\nin the form of patch to gitweb, which would hopefully made it to\nnext git version.\n\n> 2012/1/30 Jakub Narebski <jnareb@gmail.com>\n>> On Mon, 30 Jan 2012, rajesh boyapati wrote:\n>>> 2012/1/28 Jakub Narebski <jnareb@gmail.com>\n>>>> On Fri, 27 Jan 2012, rajesh boyapati wrote:\n\n>>>>>     my $alternate = 1;\n>>>>>     for (my $i = $from; $i <= $to; $i++) {\n>>>>>         my $entry = $headlist->[$i];\n>>>>>         my %ref = %$entry;\n>>>>>         my $curr = $ref{'id'} eq $head;\n>>>>>         if ($alternate) {\n>>>>>             print \"<tr class=\\\"dark\\\">\\n\";\n>>>>>         } else {\n>>>>>             print \"<tr class=\\\"light\\\">\\n\";\n>>>>>         }\n>>>>>         $alternate ^= 1;\n>>>>\n>>>> Hmmmm... I see that we do not check if $head is defined here before using\n>>>> it.  This can happen legitimately if we are on yet to be born orphan branch\n>>>> (so $head, which should be named $head_at, is undefined) but there exist\n>>>> other branches (so $headlist is not empty).\n\nThis was simple to fix.\n\n>>>>>>> [2012-01-25 18:50:35,658] ERROR\n>>>>>>> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: [Wed Jan 25\n>>>>>>> 18:50:35 2012] gitweb.cgi: Use of uninitialized value $commit_id\n>>>>>>> in open at /usr/lib/cgi-bin/gitweb.cgi line 2817.\n\n>>>>> sub parse_commits {\n>>>>>     my ($commit_id, $maxcount, $skip, $filename, @args) = @_;\n>>>>>     my @cos;\n>>>>>\n>>>>>     $maxcount ||= 1;\n>>>>>     $skip ||= 0;\n>>>>>\n>>>>>     local $/ = \"\\0\";\n>>>>>\n>>>>>     open my $fd, \"-|\", git_cmd(), \"rev-list\",\n>>>>>         \"--header\",\n>>>>>         @args,\n>>>>>         (\"--max-count=\" . $maxcount),\n>>>>>         (\"--skip=\" . $skip),\n>>>>>         @extra_options,\n>>>>>         $commit_id,\n>>>>>         \"--\",\n>>>>>         ($filename ? ($filename) : ())\n>>>>>         or die_error(500, \"Open git-rev-list failed\");\n\nBut I was not able to fix this, at least not currently.  I wrote a failing\ntest case for \"commit\" and similar views on unborn HEAD... but they fail\n_without_ error message like the one quoted.\n\nI'd have to go slower route of examining gitweb code in how it deals with\n\"invalid\" HEAD (i.e. HEAD not pointing to commit, being on unborn branch).\n\n>>> For my git projects on gerrit, our main branch name is \"base\".\n>>> We don't have any code on \"master\" branch.\n>>> May be the $HEAD is looking for master branch(or checked out branch in git\n>>> project).--> In our case, \"master\" is an empty branch.\n>>> Also, In the git projects, the HEAD file is pointing to \"ref:\n>>> refs/heads/master\".\n>>> So, I think that's the reason for errors.\n>>>\n>>> How can I make $HEAD to point to a branch other than \"master\"?.\n>>>   a) I can do this by pointing HEAD file in git projects to other branch\n>> [...]\n>>>   b) Is there any way, other than doing above step (a) ?.\n>>>      I mean I don't want to have a code on \"master\" branch and also I\n>>>      don't want to point HEAD file in git projects to some other branch.\n>>>      Do I need to make any modifications to \"gitweb.cgi\" for this?\n>>\n>> Now that I know the source of this error, I can write test case\n>> for it, and fix it.  I'll try to do it soon.\n>>\n>> So finally what you would need for (b) is just upgrade gitweb.\n\nAnd here is the patch:\n-- >8 ------------ >8 ---\nFrom: Jakub Narebski <jnareb@gmail.com>\nSubject: [PATCH] gitweb: Deal with HEAD pointing to unborn branch in \"heads\"\n view\n\nGitweb has problems if HEAD points to an unborn branch, with no\ncommits on it yet, but there are other branches present (so it is not\nnewly initialized repository).\n\nThis can happen if non-bare repository (with default 'master' branch)\nis updated not via committing but by other means like push to it, or\nGerrit.  It can happen also just after running \"git checkout --orphan\n<new branch>\" but before creating any new commit on this branch.\n\nThis commit adds test and fixes the issue of being on unborn branch\n(of HEAD not pointing to a commit) in \"heads\" view, and also in\n\"summary\" view -- which includes \"heads\" excerpt as subview.\n\nWhile at it rename local variable $head to $head_at, as it points to\ncurrent commit rather than current branch name (HEAD contents).\n\nReported-by: rajesh boyapati <boyapatisrajesh@gmail.com>\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\n gitweb/gitweb.perl                     |    4 ++--\n t/t9500-gitweb-standalone-no-errors.sh |    9 +++++++++\n 2 files changed, 11 insertions(+), 2 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 9cf7e71..1f0ec12 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -5570,7 +5570,7 @@ sub git_tags_body {\n \n sub git_heads_body {\n \t# uses global variable $project\n-\tmy ($headlist, $head, $from, $to, $extra) = @_;\n+\tmy ($headlist, $head_at, $from, $to, $extra) = @_;\n \t$from = 0 unless defined $from;\n \t$to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);\n \n@@ -5579,7 +5579,7 @@ sub git_heads_body {\n \tfor (my $i = $from; $i <= $to; $i++) {\n \t\tmy $entry = $headlist->[$i];\n \t\tmy %ref = %$entry;\n-\t\tmy $curr = $ref{'id'} eq $head;\n+\t\tmy $curr = defined $head_at && $ref{'id'} eq $head_at;\n \t\tif ($alternate) {\n \t\t\tprint \"<tr class=\\\"dark\\\">\\n\";\n \t\t} else {\ndiff --git a/t/t9500-gitweb-standalone-no-errors.sh b/t/t9500-gitweb-standalone-no-errors.sh\nindex 0f771c6..81246a6 100755\n--- a/t/t9500-gitweb-standalone-no-errors.sh\n+++ b/t/t9500-gitweb-standalone-no-errors.sh\n@@ -739,4 +739,13 @@ test_expect_success \\\n \t'echo \"\\$projects_list_group_categories = 1;\" >>gitweb_config.perl &&\n \t gitweb_run'\n \n+# ----------------------------------------------------------------------\n+# unborn branches\n+\n+test_expect_success \\\n+\t'unborn HEAD: \"summary\" page (with \"heads\" subview)' \\\n+\t'git checkout orphan_branch || git checkout --orphan orphan_branch &&\n+\t test_when_finished \"git checkout master\" &&\n+\t gitweb_run \"p=.git;a=summary\"'\n+\n test_done\n-- \n1.7.9\n"},{"id":"184138","messageId":"201202071753.12436.jnareb@gmail.com","threadId":"29456","inReplyTo":"CA+EqV8w6k2VrEtMydhGKZHbQdXHxCE3WA_0rtS-AY4cmQvii=A@mail.gmail.com","subject":"Re: [PATCH] gitweb: Deal with HEAD pointing to unborn branch in \"heads\" view","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2012-02-07T16:53:11Z","receivedAt":"2012-02-07T16:53:11Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"On Mon, 6 Feb 2012, rajesh boyapati wrote:\n> \n> Thanks for your work.\n\nI'm sorry I was able to find a fix only for the part of issue.\n\n>>>>>>>>> [2012-01-25 18:50:35,658] ERROR\n>>>>>>>>> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: [Wed Jan 25\n>>>>>>>>> 18:50:35 2012] gitweb.cgi: Use of uninitialized value $commit_id\n>>>>>>>>> in open at /usr/lib/cgi-bin/gitweb.cgi line 2817.\n>>>>>>>\n>>>>>>> sub parse_commits {\n>>>>>>>     my ($commit_id, $maxcount, $skip, $filename, @args) = @_;\n>>>>>>>     my @cos;\n>>>>>>>\n>>>>>>>     $maxcount ||= 1;\n>>>>>>>     $skip ||= 0;\n>>>>>>>\n>>>>>>>     local $/ = \"\\0\";\n>>>>>>>\n>>>>>>>     open my $fd, \"-|\", git_cmd(), \"rev-list\",\n>>>>>>>         \"--header\",\n>>>>>>>         @args,\n>>>>>>>         (\"--max-count=\" . $maxcount),\n>>>>>>>         (\"--skip=\" . $skip),\n>>>>>>>         @extra_options,\n>>>>>>>         $commit_id,\n>>>>>>>         \"--\",\n>>>>>>>         ($filename ? ($filename) : ())\n>>>>>>>         or die_error(500, \"Open git-rev-list failed\");\n>>\n>> But I was not able to fix this, at least not currently.  I wrote a failing\n>> test case for \"commit\" and similar views on unborn HEAD... but they fail\n>> _without_ error message like the one quoted.\n>>\n>> I'd have to go slower route of examining gitweb code in how it deals with\n>> \"invalid\" HEAD (i.e. HEAD not pointing to commit, being on unborn branch).\n\n[...]\n>> And here is the patch:\n>> -->8 ------------>8 ---\n>> From: Jakub Narebski <jnareb@gmail.com>\n>> Subject: [PATCH] gitweb: Deal with HEAD pointing to unborn branch in\n>>   \"heads\"  view\n[...]\n>> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\n>> index 9cf7e71..1f0ec12 100755\n>> --- a/gitweb/gitweb.perl\n>> +++ b/gitweb/gitweb.perl\n>> @@ -5570,7 +5570,7 @@ sub git_tags_body {\n>>\n>>  sub git_heads_body {\n>>        # uses global variable $project\n>> -       my ($headlist, $head, $from, $to, $extra) = @_;\n>> +       my ($headlist, $head_at, $from, $to, $extra) = @_;\n>>        $from = 0 unless defined $from;\n>>        $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);\n>>\n> \n> I didn't see a file called \"gitweb.perl\" in /usr/share/gitweb/\n\nThe file \"gitweb.perl\", or rather \"gitweb/gitweb.perl\" is the name\nof the script in git.git repository.  From it \"make gitweb\" would\ngenerate \"gitweb.cgi\" file...\n\n> I applied this patch to file \"index.cgi\" in /usr/share/gitweb/index.cgi at\n> line 4711.\n[...]\n> \n> I applied this patch to file \"index.cgi\" in /usr/share/gitweb/index.cgi at\n> line 4720.\n\n\n...and I guess Gerrit build process generates \"index.cgi\" from that.\n\n> Had I applied the patch to the correct file \"index.cgi\", which is a link to\n> file \"gitweb.cgi\" in /usr/lib/cgi-bin/gitweb.cgi ?\n\nAh, right.\n\n> Then, I restarted gerrit server to take changes.\n> Now the error log of gerrit shows:\n\n> [2012-02-06 11:21:46,726] ERROR\n> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: bad revision\n> 'HEAD'\n> [2012-02-06 11:21:49,167] ERROR\n> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: [Mon Feb  6 11:21:49\n> 2012] gitweb.cgi: Use of uninitialized value $commit_id in open at\n> /usr/lib/cgi-bin/gitweb.cgi line 2817.\n> [2012-02-06 11:21:49,169] ERROR\n> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: bad revision ''\n[the same errors repeated few times]\n\n> <<<<<<<<<<<<<<<<\n> Previously, there is a error showing at line 4720. Now, with this patch,\n> that error has gone.\n\nAs I said I was able to find a fix only for part of the issue.  \nUnfortunately I was not able to reproduce this error in this form.\nNote that the error location doesn't help much, because it is more\ninteresting for find which callers of parse_commits() pass undefined\n$commit_id.\n\nI can try to harden parse_commits() against bogus parameters; maybe\nthis would help.\n \n> I tried to upgrade gitweb with the command \"sudo apt-get install gitweb\",\n> but, it didn't find any upgrade.\n> Am I doing in a right way?\n\nThere is no new version of gitweb yet; it haven't even been accepted\nby Junio Hamano, maintainer of git of which gitweb is part, into git\nrepository (I might have to resend this patch for better visibility).\n\n> Is there any place like \"Github\" (where we can place git projects) for\n> gitweb ?\n\nGitweb is for quite some time developed within git repository.  From\nit the 'gitweb' package is created.\n\nClones of canonical, official git repository can be found in a few places:\n\n        git://git.kernel.org/pub/scm/git/git.git\n        git://repo.or.cz/alt-git.git\n        https://code.google.com/p/git-core/\n        https://github.com/git/git\n\nMy own clone of git, with my work, can be found at:\n\n       git://repo.or.cz/git/jnareb-git.git\n       https://github.com/jnareb/git\n\n>> diff --git a/t/t9500-gitweb-standalone-no-errors.sh\n>> b/t/t9500-gitweb-standalone-no-errors.sh\n>> index 0f771c6..81246a6 100755\n>> --- a/t/t9500-gitweb-standalone-no-errors.sh\n>> +++ b/t/t9500-gitweb-standalone-no-errors.sh\n>> @@ -739,4 +739,13 @@ test_expect_success \\\n>>        'echo \"\\$projects_list_group_categories = 1;\">>gitweb_config.perl\n>> &&\n>>         gitweb_run'\n>>\n>> +# ----------------------------------------------------------------------\n>> +# unborn branches\n>> +\n>> +test_expect_success \\\n>> +       'unborn HEAD: \"summary\" page (with \"heads\" subview)' \\\n>> +       'git checkout orphan_branch || git checkout --orphan orphan_branch\n>> &&\n>> +        test_when_finished \"git checkout master\" &&\n>> +        gitweb_run \"p=.git;a=summary\"'\n>> +\n>>  test_done\n>>\n> \n> I didn't find a file where to apply this patch.\n> Is this file to test your patch for you?\n\nYes, this is to test that my patch fixes the issue correctly, and to\nensure that further changes don't re-break it.  It is not usually\ninstalled with git or gitweb, so don't worry about it.\n\n-- \nJakub Narebski\nPoland\n"},{"id":"184186","messageId":"201202081604.17187.jnareb@gmail.com","threadId":"29456","inReplyTo":"201202071753.12436.jnareb@gmail.com","subject":"[PATCH] gitweb: Harden parse_commit and parse_commits","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2012-02-08T15:04:16Z","receivedAt":"2012-02-08T15:04:16Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"On Tue, 7 Feb 2012, Jakub Narebski wrote:\n> On Mon, 6 Feb 2012, rajesh boyapati wrote:\n[...]\n> > Then, I restarted gerrit server to take changes.\n> > Now the error log of gerrit shows:\n> \n> > [2012-02-06 11:21:46,726] ERROR\n> > com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: bad revision\n> > 'HEAD'\n> > [2012-02-06 11:21:49,167] ERROR\n> > com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: [Mon Feb  6 11:21:49\n> > 2012] gitweb.cgi: Use of uninitialized value $commit_id in open at\n> > /usr/lib/cgi-bin/gitweb.cgi line 2817.\n> > [2012-02-06 11:21:49,169] ERROR\n> > com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: bad revision ''\n> [the same errors repeated few times]\n> \n> > <<<<<<<<<<<<<<<<\n> > Previously, there is a error showing at line 4720. Now, with this patch,\n> > that error has gone.\n> \n> As I said I was able to find a fix only for part of the issue.  \n> Unfortunately I was not able to reproduce this error in this form.\n> Note that the error location doesn't help much, because it is more\n> interesting for find which callers of parse_commits() pass undefined\n> $commit_id.\n> \n> I can try to harden parse_commits() against bogus parameters; maybe\n> this would help.\n\nDoes the following patch help, and does it fix the issue?\n\n(Nb. you can try to simply change filename, and apply it with fuzz\nagainst index.cgi file).\n-- >8 -- ----- ----- ----- ----- ----- -- >8 --\nFrom: Jakub Narebski <jnareb@gmail.com>\nSubject: [PATCH] gitweb: Harden parse_commit and parse_commits\n\nGitweb has problems and gives errors when repository it shows is on\nunborn branch (HEAD doesn't point to a valid commit), but there exist\nother branches.\n\nOne of errors that shows in gitweb logs is undefined $commit_id in\nparse_commits() subroutine.  Therefore we harden both parse_commit()\nand parse_commits() against undefined $commit_id, and against no\noutput from git-rev-list because HEAD doesn't point to a commit.\n\nReported-by: rajesh boyapati <boyapatisrajesh@gmail.com>\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\n gitweb/gitweb.perl |    7 ++++++-\n 1 files changed, 6 insertions(+), 1 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex f9535eb..1181aeb 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -3334,6 +3334,8 @@ sub parse_commit {\n \tmy ($commit_id) = @_;\n \tmy %co;\n \n+\treturn unless defined $commit_id;\n+\n \tlocal $/ = \"\\0\";\n \n \topen my $fd, \"-|\", git_cmd(), \"rev-list\",\n@@ -3343,7 +3345,9 @@ sub parse_commit {\n \t\t$commit_id,\n \t\t\"--\",\n \t\tor die_error(500, \"Open git-rev-list failed\");\n-\t%co = parse_commit_text(<$fd>, 1);\n+\tmy $commit_text = <$fd>;\n+\t%co = parse_commit_text($commit_text, 1)\n+\t\tif defined $commit_text;\n \tclose $fd;\n \n \treturn %co;\n@@ -3353,6 +3357,7 @@ sub parse_commits {\n \tmy ($commit_id, $maxcount, $skip, $filename, @args) = @_;\n \tmy @cos;\n \n+\treturn unless defined $commit_id;\n \t$maxcount ||= 1;\n \t$skip ||= 0;\n \n-- \n1.7.9\n"},{"id":"184262","messageId":"201202092114.40832.jnareb@gmail.com","threadId":"29456","inReplyTo":"CA+EqV8xiLYo8XE--c1QfuXdhentUFpHqfPYXHt72eCpEA_hCNQ@mail.gmail.com","subject":"Re: [PATCH] gitweb: Harden parse_commit and parse_commits","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2012-02-09T20:14:40Z","receivedAt":"2012-02-09T20:14:40Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Please do not remove git@vger.kernel.org (git mailing list) from Cc,\ni.e. please use \"Reply to all\" instead of just \"Reply to author\".\n\nOn Wed, 8 Feb 2012, rajesh boyapati wrote:\n> 2012/2/8 Jakub Narebski <jnareb@gmail.com>\n \n[...]\n> > Does the following patch help, and does it fix the issue?\n> >\n> > (Nb. you can try to simply change filename, and apply it with fuzz\n> > against index.cgi file).\n> > -- >8 -- ----- ----- ----- ----- ----- -- >8 --\n> > From: Jakub Narebski <jnareb@gmail.com>\n> > Subject: [PATCH] gitweb: Harden parse_commit and parse_commits\n[...]\n> When I applied the above patch and also the patch from your previous\n> e-mail, I am getting this error\n> >>>>>>>>>>>>>\n> [2012-02-08 14:09:58,396] ERROR\n> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: bad revision\n> 'HEAD'\n> [2012-02-08 14:10:06,732] ERROR\n> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: bad revision\n> 'HEAD'\n> [2012-02-08 14:10:11,404] ERROR\n> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: bad revision\n> 'HEAD'\n> [2012-02-08 14:10:15,270] ERROR\n> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: Not a valid\n> object name HEAD\n> <<<<<<<<<<<<<<\n> With these patches, the previous errors at line numbers are gone.\n\nThanks for information.\n\n\nThis final issue will be a bit harder to fix.  This error message\n\n  fatal: bad revision 'HEAD'\n\ncomes from git (I think from \"git rev-list\" command), and not from gitweb.\nIt is printed on STDERR of git command.  What has to be done to fix it is\nto capture stderr of a process, or silence it.\n\nUnfortunately it is not that easy.  We use list form of open, which avoids\nusing a shell interpreter to run command, and is safer wrt. shell escaping.\n\nThe only place where gitweb cares about redirecting standard error from git\ncommand is git_object().  It is a bit hacky, and might be not entirely safe.\nTo fix this issue we would have to do the same in parse_commit*() as in\ngit_object(), or provide some kind of wrapper like IPC::Run provides\nfor redirecting stderr of called command.\n\nNote that this issue was not considered very important, because this message\ndoesn't goes into web server logs when running gitweb via mod_cgi with\nApache... and probably also with other web servers.  Gerrit (or rather\nwhatever it uses for serving CGI scripts) might be exception here.\n\n-- \nJakub Narebski\nPoland\n"},{"id":"184453","messageId":"201202111402.31684.jnareb@gmail.com","threadId":"29456","inReplyTo":"201202092114.40832.jnareb@gmail.com","subject":"[PATCH] gitweb: Silence stderr in parse_commit*() subroutines","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2012-02-11T13:02:30Z","receivedAt":"2012-02-11T13:02:30Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"On Thu, 9 Feb 2012, Jakub Narebski wrote:\n> On Wed, 8 Feb 2012, rajesh boyapati wrote:\n> > 2012/2/8 Jakub Narebski <jnareb@gmail.com>\n>  \n> [...]\n> > > Does the following patch help, and does it fix the issue?\n> > >\n> > > (Nb. you can try to simply change filename, and apply it with fuzz\n> > > against index.cgi file).\n> > > -- >8 -- ----- ----- ----- ----- ----- -- >8 --\n> > > From: Jakub Narebski <jnareb@gmail.com>\n> > > Subject: [PATCH] gitweb: Harden parse_commit and parse_commits\n> [...]\n> > When I applied the above patch and also the patch from your previous\n> > e-mail, I am getting this error\n> > >>>>>>>>>>>>>\n> > [2012-02-08 14:09:58,396] ERROR\n> > com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: bad revision\n> > 'HEAD'\n> > [2012-02-08 14:10:06,732] ERROR\n> > com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: bad revision\n> > 'HEAD'\n> > [2012-02-08 14:10:11,404] ERROR\n> > com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: bad revision\n> > 'HEAD'\n> > [2012-02-08 14:10:15,270] ERROR\n> > com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: Not a valid\n> > object name HEAD\n> > <<<<<<<<<<<<<<\n> > With these patches, the previous errors at line numbers are gone.\n> \n> Thanks for information.\n> \n> \n> This final issue will be a bit harder to fix.  This error message\n> \n>   fatal: bad revision 'HEAD'\n> \n> comes from git (I think from \"git rev-list\" command), and not from gitweb.\n> It is printed on STDERR of git command.  What has to be done to fix it is\n> to capture stderr of a process, or silence it.\n> \n> Unfortunately it is not that easy.  We use list form of open, which avoids\n> using a shell interpreter to run command, and is safer wrt. shell escaping.\n> \n> The only place where gitweb cares about redirecting standard error from git\n> command is git_object().  It is a bit hacky, and might be not entirely safe.\n> To fix this issue we would have to do the same in parse_commit*() as in\n> git_object(), or provide some kind of wrapper like IPC::Run provides\n> for redirecting stderr of called command.\n> \n> Note that this issue was not considered very important, because this message\n> doesn't goes into web server logs when running gitweb via mod_cgi with\n> Apache... and probably also with other web servers.  Gerrit (or rather\n> whatever it uses for serving CGI scripts) might be exception here.\n\nAnyway, here is the patch that should fix those \"CGI: fatal: Not a valid\nobject name HEAD\" errors for you.\n\nI'll resend the all the patches as single patch series for inclusion in\ngit, but I am not sure if this latest patch will be accepted because of\ndrawbacks of its implementation.\n\n-- >8 ---- ----- ----- ----- >8 --\nFrom: Jakub Narebski <jnareb@gmail.com>\nSubject: [PATCH] gitweb: Silence stderr in parse_commit*() subroutines\n\ngit-rev-list command in parse_commit() and parse_commits() can fail\nbecause $commit_id doesn't point to a valid commit; for example if we\nare on unborn branch HEAD doesn't point to a valid commit.\n\nIn this case git-rev-list prints\n\n  fatal: bad revision 'HEAD'\n\non its standard error.  This commit silences this warning, at the cost\nof using shell to redirect it to /dev/null, and relying on\nquote_command() to protect against code injection.\n\nNote however that such error message from git (from extrenal command)\nusually but not always does not appear in web server logs.\n\nReported-by: rajesh boyapati <boyapatisrajesh@gmail.com>\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\n gitweb/gitweb.perl |   10 ++++++----\n 1 files changed, 6 insertions(+), 4 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 1181aeb..081ac45 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -3338,12 +3338,13 @@ sub parse_commit {\n \n \tlocal $/ = \"\\0\";\n \n-\topen my $fd, \"-|\", git_cmd(), \"rev-list\",\n+\topen my $fd, \"-|\", quote_command(\n+\t\tgit_cmd(), \"rev-list\",\n \t\t\"--parents\",\n \t\t\"--header\",\n \t\t\"--max-count=1\",\n \t\t$commit_id,\n-\t\t\"--\",\n+\t\t\"--\") . ' 2>/dev/null',\n \t\tor die_error(500, \"Open git-rev-list failed\");\n \tmy $commit_text = <$fd>;\n \t%co = parse_commit_text($commit_text, 1)\n@@ -3363,7 +3364,8 @@ sub parse_commits {\n \n \tlocal $/ = \"\\0\";\n \n-\topen my $fd, \"-|\", git_cmd(), \"rev-list\",\n+\topen my $fd, \"-|\", quote_command(\n+\t\tgit_cmd(), \"rev-list\",\n \t\t\"--header\",\n \t\t@args,\n \t\t(\"--max-count=\" . $maxcount),\n@@ -3371,7 +3373,7 @@ sub parse_commits {\n \t\t@extra_options,\n \t\t$commit_id,\n \t\t\"--\",\n-\t\t($filename ? ($filename) : ())\n+\t\t($filename ? ($filename) : ())) . ' 2>/dev/null'\n \t\tor die_error(500, \"Open git-rev-list failed\");\n \twhile (my $line = <$fd>) {\n \t\tmy %co = parse_commit_text($line);\n-- \n1.7.9\n"},{"id":"184577","messageId":"201202131915.01753.jnareb@gmail.com","threadId":"29456","inReplyTo":"CA+EqV8xTsavQFWsoijrt+0UcfxSZO2voL=CawrRPvDeB=qHQfg@mail.gmail.com","subject":"Re: [PATCH] gitweb: Silence stderr in parse_commit*() subroutines","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2012-02-13T18:15:01Z","receivedAt":"2012-02-13T18:15:01Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"On Mon, 13 Feb 2012, rajesh boyapati wrote:\n> 2012/2/11 Jakub Narebski <jnareb@gmail.com>\n>> On Thu, 9 Feb 2012, Jakub Narebski wrote:\n>>> On Wed, 8 Feb 2012, rajesh boyapati wrote:\n>>>> 2012/2/8 Jakub Narebski <jnareb@gmail.com>\n\n[...]\n>>>> When I applied the above patch and also the patch from your previous\n>>>> e-mail, I am getting this error\n>>>>>>>>>>>>>>>>>\n>>>> [2012-02-08 14:09:58,396] ERROR\n>>>> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: bad revision\n>>>> 'HEAD'\n>>>> [2012-02-08 14:10:06,732] ERROR\n>>>> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: bad revision\n>>>> 'HEAD'\n>>>> [2012-02-08 14:10:11,404] ERROR\n>>>> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: bad revision\n>>>> 'HEAD'\n>>>> [2012-02-08 14:10:15,270] ERROR\n>>>> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: Not a valid\n>>>> object name HEAD\n>>>> <<<<<<<<<<<<<<\n>>>> With these patches, the previous errors at line numbers are gone.\n[...]\n>>> This final issue will be a bit harder to fix.  This error message\n>>>\n>>>   fatal: bad revision 'HEAD'\n>>>\n>>> comes from git (I think from \"git rev-list\" command), and not from gitweb.\n>>> It is printed on STDERR of git command.  What has to be done to fix it is\n>>> to capture stderr of a process, or silence it.\n[...]\n>> Anyway, here is the patch that should fix those \"CGI: fatal: Not a valid\n>> object name HEAD\" errors for you.\n>>\n>> I'll resend the all the patches as single patch series for inclusion in\n>> git, but I am not sure if this latest patch will be accepted because of\n>> drawbacks of its implementation.\n>>\n>> -->8 ---- ----- ----- ----->8 --\n>> From: Jakub Narebski <jnareb@gmail.com>\n>> Subject: [PATCH] gitweb: Silence stderr in parse_commit*() subroutines\n[...]\n>> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\n>> index 1181aeb..081ac45 100755\n>> --- a/gitweb/gitweb.perl\n>> +++ b/gitweb/gitweb.perl\n>> @@ -3338,12 +3338,13 @@ sub parse_commit {\n>>\n>>        local $/ = \"\\0\";\n>>\n>> -       open my $fd, \"-|\", git_cmd(), \"rev-list\",\n>> +       open my $fd, \"-|\", quote_command(\n>> +               git_cmd(), \"rev-list\",\n>>                \"--parents\",\n>>                \"--header\",\n>>                \"--max-count=1\",\n>>                $commit_id,\n>> -               \"--\",\n>> +               \"--\") . ' 2>/dev/null',\n>>                or die_error(500, \"Open git-rev-list failed\");\n>>        my $commit_text = <$fd>;\n>>        %co = parse_commit_text($commit_text, 1)\n>> @@ -3363,7 +3364,8 @@ sub parse_commits {\n>>\n>>        local $/ = \"\\0\";\n>>\n>> -       open my $fd, \"-|\", git_cmd(), \"rev-list\",\n>> +       open my $fd, \"-|\", quote_command(\n>> +               git_cmd(), \"rev-list\",\n>>                \"--header\",\n>>                @args,\n>>                (\"--max-count=\" . $maxcount),\n>> @@ -3371,7 +3373,7 @@ sub parse_commits {\n>>                @extra_options,\n>>                $commit_id,\n>>                \"--\",\n>> -               ($filename ? ($filename) : ())\n>> +               ($filename ? ($filename) : ())) . ' 2>/dev/null'\n>>                or die_error(500, \"Open git-rev-list failed\");\n>>        while (my $line = <$fd>) {\n>>                my %co = parse_commit_text($line);\n>>\n> \n> I am getting this error with this patch\n>>>>>>>>>>>>>>>>>>>\n> [2012-02-13 11:20:19,268] ERROR\n> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: usage: git rev-list\n> [OPTION] <commit-id>... [ -- paths... ]\n> [2012-02-13 11:20:19,268] ERROR\n> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI:   limiting output:\n> [2012-02-13 11:20:19,268] ERROR\n> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI:     --max-count=nr\n[...]\n> [2012-02-13 11:20:27,913] ERROR\n> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: bad flag '--2'\n> used after filename\n> [2012-02-13 11:20:32,579] ERROR\n> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: bad flag '--2'\n> used after filename\n> <<<<<<<<<<<<<<<<<<<\n\nStrange, I cannot reproduce this with non-Gerrit gitweb.  It looks\nlike it somehow lost in between \"... -- 2>/dev/null\" at the end of\ngit-rev-list command, and fails at \"--2\" which is bad flag.\n\nAre you sure you applied the patch correctly?  Does 'object' view\n(take any 'commit' or 'blob' or 'tree' view, and replace action part\nby 'object') works correctly in Gerrit's gitweb?\n\n-- \nJakub Narebski\nPoland\n"},{"id":"184581","messageId":"7vmx8mfu8k.fsf@alter.siamese.dyndns.org","threadId":"29456","inReplyTo":"201202111402.31684.jnareb@gmail.com","subject":"Re: [PATCH] gitweb: Silence stderr in parse_commit*() subroutines","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-02-13T18:44:59Z","receivedAt":"2012-02-13T18:44:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jakub Narebski <jnareb@gmail.com> writes:\n\n> Anyway, here is the patch that should fix those \"CGI: fatal: Not a valid\n> object name HEAD\" errors for you.\n\nI have to wonder if it is simpler and less error prone to check HEAD\nbefore doing anything else immediately after which repository is being\nconsulted, and give the same \"no history at all yet in this project\" page\nfor most if not all operations, instead of patching things up at this deep\nin the callchain.\n"},{"id":"184585","messageId":"201202132004.41991.jnareb@gmail.com","threadId":"29456","inReplyTo":"CA+EqV8xin_ubOoGouhHz2qnzoHrpMMQsjUTXnrtmsxRTLPZtZQ@mail.gmail.com","subject":"Re: [PATCH] gitweb: Silence stderr in parse_commit*() subroutines","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2012-02-13T19:04:41Z","receivedAt":"2012-02-13T19:04:41Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"On Mon, 13 Feb 2012, rajesh boyapati wrote:\n> 2012/2/13 Jakub Narebski <jnareb@gmail.com>\n>> On Mon, 13 Feb 2012, rajesh boyapati wrote:\n\n>>> I am getting this error with this patch\n>>>>>>>>>>>>>>>>>>>>>\n>>> [2012-02-13 11:20:19,268] ERROR\n>>> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: usage: git rev-list\n>>> [OPTION] <commit-id>... [ -- paths... ]\n>>> [2012-02-13 11:20:19,268] ERROR\n>>> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI:   limiting output:\n>>> [2012-02-13 11:20:19,268] ERROR\n>>> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI:     --max-count=nr\n>> [...]\n>>> [2012-02-13 11:20:27,913] ERROR\n>>> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: bad flag '--2'\n>>> used after filename\n>>> [2012-02-13 11:20:32,579] ERROR\n>>> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: bad flag '--2'\n>>> used after filename\n>>> <<<<<<<<<<<<<<<<<<<\n>>\n>> Strange, I cannot reproduce this with non-Gerrit gitweb.  It looks\n>> like it somehow lost in between \"... -- 2>/dev/null\" at the end of\n>> git-rev-list command, and fails at \"--2\" which is bad flag.\n>>\n> This is the patch I applied\n>>>>>>>>>>>>>\n> sub parse_commit {\n>     my ($commit_id) = @_;\n>     my %co;\n> \n>         return unless defined $commit_id;\n> \n>     local $/ = \"\\0\";\n> \n>     *open my $fd, \"-|\", quote_command(\n>              git_cmd(), \"rev-list\",*\n>         \"--parents\",\n>         \"--header\",\n>         \"--max-count=1\",\n>         $commit_id,\n>        * \"--\") . '2>/dev/null',*\n                   ^^^^^^^^^^^^^\n\nIt should be ' 2>/dev/null', with space before redirection, and not\n'2>/dev/null'.  This space is here necessary.\n\n> With this Patch, Gerrit's gitweb is not showing anything.\n> I mean, I can access gitweb from gerrit, but if I click on Tabs(like log,\n> commit, etc...which worked with previous patches), I cannot see any thing.\n> \n> Even with previous patches also there is no improvement in Gerrit's gitweb,\n> only some of the errors are gone in error_log.\n> The improvement I am talking about is \"If I click other tabs(log, shortlog,\n> commit, tree,etc) after clicking \"summary\", Gerrit's gitweb is not showing\n> anything\".\n\nMany views in gitweb do default to HEAD.  If HEAD does not point to a valid\ncommit, they would fail, in better or worse way.\n\nExcept for the first one those patches are more of band-aid and workaround\nthan fixing underlying issue that gitweb assumes that HEAD is valid in \nnon-empty repository.  But fixing this will require more work.\n\n-- \nJakub Narebski\nPoland\n"},{"id":"184587","messageId":"201202132012.04721.jnareb@gmail.com","threadId":"29456","inReplyTo":"7vmx8mfu8k.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] gitweb: Silence stderr in parse_commit*() subroutines","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2012-02-13T19:12:04Z","receivedAt":"2012-02-13T19:12:04Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Junio C Hamano wrote:\n> Jakub Narebski <jnareb@gmail.com> writes:\n> \n> > Anyway, here is the patch that should fix those \"CGI: fatal: Not a valid\n> > object name HEAD\" errors for you.\n> \n> I have to wonder if it is simpler and less error prone to check HEAD\n> before doing anything else immediately after which repository is being\n> consulted, and give the same \"no history at all yet in this project\" page\n> for most if not all operations, instead of patching things up at this deep\n> in the callchain.\n\nActually the problem is that there is history (there are other branches),\nbut HEAD points to unborn (unused) 'master' branch.\n\nBut you are right that we should fix underlying issue with invalid\nassumption which gitweb uses, that HEAD points to a valid commit if\nrepository is non-empty.\n\nThough I think leaving safety of 2nd patch could be a good idea anyway.\nAnd 1st patch fixes a real issue, and does not only provide band-aid.\n\n\nP.S. I will resend those three patches as patch series for easier review,\nso they are not tangled in this deep thread.  They should be in 'gitweb/web'\nbranch in my public forks of git repository on repo.or.cz and github.\n\n-- \nJakub Narebski\nPoland\n"},{"id":"184754","messageId":"201202151104.55348.jnareb@gmail.com","threadId":"29456","inReplyTo":"CA+EqV8w5jCHa2NY+NLaht901Qk=kQvALG3EA6BkePiGow3YFeQ@mail.gmail.com","subject":"Re: [PATCH] gitweb: Silence stderr in parse_commit*() subroutines","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2012-02-15T10:04:54Z","receivedAt":"2012-02-15T10:04:54Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"On Mon, 13 Feb 2012, rajesh boyapati wrote:\n> 2012/2/13 Jakub Narebski <jnareb@gmail.com>\n>> On Mon, 13 Feb 2012, rajesh boyapati wrote:\n\n\n>>> This is the patch I applied\n>>>>>>>>>>>>>>>\n>>> sub parse_commit {\n>>>     my ($commit_id) = @_;\n>>>     my %co;\n>>>\n>>>         return unless defined $commit_id;\n>>>\n>>>     local $/ = \"\\0\";\n>>>\n>>>     *open my $fd, \"-|\", quote_command(\n>>>              git_cmd(), \"rev-list\",*\n>>>         \"--parents\",\n>>>         \"--header\",\n>>>         \"--max-count=1\",\n>>>         $commit_id,\n>>>        * \"--\") . '2>/dev/null',*\n>>                   ^^^^^^^^^^^^^\n>>\n>> It should be ' 2>/dev/null', with space before redirection, and not\n>> '2>/dev/null'.  This space is here necessary.\n> \n> \n> Sorry for the typo error. I changed that and I am now seeing this error in\n> Gerrit's error_log\n> <<<<<<<<<<<<<\n> [2012-02-13 13:45:35,201] ERROR\n> com.google.gerrit.httpd.gitweb.GitWebServlet : CGI: fatal: Not a valid\n> object name HEAD\n> >>>>>>>>>>>>>\n\nWTF, redirecting stderr (file descriptor number 2) to /dev/null should have\nsilenced git-rev-list in case of errors.\n\nCompare\n\n  $ git rev-list foo --\n  fatal: bad revision 'foo'\n\nwith\n\n  $ git rev-list foo -- 2>/dev/null\n\nwhich gives no output.\n\nI wonder what shell does gitweb use if run from com.google.gerrit.httpd\nas servlet...\n\n[...]\n>> Many views in gitweb do default to HEAD.  If HEAD does not point to a valid\n>> commit, they would fail, in better or worse way.\n>>\n>> Except for the first one those patches are more of band-aid and workaround\n>> than fixing underlying issue that gitweb assumes that HEAD is valid in\n>> non-empty repository.  But fixing this will require more work.\n>>\n> Yes, I agree with you.\n>\n> If the HEAD's in a git project are pointed to master branch, those are fine\n> with Gerrits gitweb. Everything is working fine. (See the images in attached\n> file \"Master.zip\")\n> \n> For the HEAD's in the git projects that are pointed to a branch other than\n> master (I mean if master branch is empty), I have the problem when I click\n> on tabs (log, shortlog, commit, commitdiff, tree) after clicking \"summary\"\n> tab.  (See the images in attched file \"Unborn-branch.zip\").\n\nThat is because those views defaults to HEAD, which doesn't point to\na valid commit because 'master' branch it does point to doesn't have any\ncommits on it.  They should probably be disabled (grayed-out, and made\nordinary text and not hyperlink) if HEAD is invalid.\n\nBut this would require more work than those patches.\n>\n> If I click other tabs before clicking \"summary\" tab, they are working fine.\n\nThat is because if you select some branch, then all those views use\ncurrently selected branch (passed via URL, e.g. 'h' or 'hb' parameter\nin case of query-params URL).\n\n-- \nJakub Narebski\nPoland\n"}]}