{"thread":{"id":"36311","subject":"Re: [PATCH] gitweb: gpg signature status indication for commits","startedAt":"2014-03-28T09:48:50Z","lastAt":"2014-03-28T19:14:51Z","messageCount":3,"participants":["Victor Kartashov","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"237992","messageId":"1396000130-10322-1-git-send-email-v.kartashov@npo-echelon.ru","threadId":"36311","inReplyTo":null,"subject":"Re: [PATCH] gitweb: gpg signature status indication for commits","fromName":"Victor Kartashov","fromEmail":"v.kartashov@npo-echelon.ru","sentAt":"2014-03-28T09:48:50Z","receivedAt":"2014-03-28T09:48:50Z","isPatch":true,"sender":{"key":"v.kartashov@npo-echelon.ru","avatar":null},"body":"show gpg signature (if any) for commit message in gitweb\nin case of valid signature highlight it with green\nin case of invalid signature highlight it with red\n\nSigned-off-by: Victor Kartashov <victor.kartashov@gmail.com>\n---\nhere's new patch\nfixed remarks by Eric Sunshine\n\"pop @commit_lines\" in parse_commit_text() leads to a loss of the last line in commit message ('sign-off' line, for example), so I search for '\\0' before removing it.\n\n gitweb/gitweb.perl       | 36 +++++++++++++++++++++++++++++-------\n gitweb/static/gitweb.css | 11 +++++++++++\n 2 files changed, 40 insertions(+), 7 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 79057b7..ccde90f 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -3430,8 +3430,9 @@ sub parse_commit_text {\n \tmy ($commit_text, $withparents) = @_;\n \tmy @commit_lines = split '\\n', $commit_text;\n \tmy %co;\n+\tmy @signature = ();\n \n-\tpop @commit_lines; # Remove '\\0'\n+\tpop @commit_lines if ($commit_lines[-1] =~ \"\\0\"); # Remove '\\0'\n \n \tif (! @commit_lines) {\n \t\treturn;\n@@ -3469,6 +3470,9 @@ sub parse_commit_text {\n \t\t\t\t$co{'committer_name'} = $co{'committer'};\n \t\t\t}\n \t\t}\n+\t\telsif ($line =~ /^gpg: /) {\n+\t\t\tpush @signature, $line;\n+\t\t}\n \t}\n \tif (!defined $co{'tree'}) {\n \t\treturn;\n@@ -3508,6 +3512,10 @@ sub parse_commit_text {\n \tforeach my $line (@commit_lines) {\n \t\t$line =~ s/^    //;\n \t}\n+\tpush(@commit_lines, \"\") if scalar @signature;\n+\tforeach my $sig (@signature) {\n+\t\tpush(@commit_lines, $sig);\n+\t}\n \t$co{'comment'} = \\@commit_lines;\n \n \tmy $age = time - $co{'committer_epoch'};\n@@ -3530,13 +3538,13 @@ sub parse_commit {\n \n \tlocal $/ = \"\\0\";\n \n-\topen my $fd, \"-|\", git_cmd(), \"rev-list\",\n-\t\t\"--parents\",\n-\t\t\"--header\",\n-\t\t\"--max-count=1\",\n+\topen my $fd, \"-|\", git_cmd(), \"show\",\n+\t\t\"--quiet\",\n+\t\t\"--date=raw\",\n+\t\t\"--pretty=format:%H %P%ntree %T%nparent %P%nauthor %an <%ae> %ad%ncommitter %cn <%ce> %cd%n%GG%n%s%n%n%b\",\n \t\t$commit_id,\n \t\t\"--\",\n-\t\tor die_error(500, \"Open git-rev-list failed\");\n+\t\tor die_error(500, \"Open git-show failed\");\n \t%co = parse_commit_text(<$fd>, 1);\n \tclose $fd;\n \n@@ -4571,7 +4579,21 @@ sub git_print_log {\n \t# print log\n \tmy $skip_blank_line = 0;\n \tforeach my $line (@$log) {\n-\t\tif ($line =~ m/^\\s*([A-Z][-A-Za-z]*-[Bb]y|C[Cc]): /) {\n+\t\tif ($line =~ m/^gpg:(.)+Good(.)+/) {\n+\t\t\tif (! $opts{'-remove_signoff'}) {\n+\t\t\t\tprint \"<span class=\\\"good_sign\\\">\" . esc_html($line) . \"</span><br/>\\n\";\n+\t\t\t\t$skip_blank_line = 1;\n+\t\t\t}\n+\t\t\tnext;\n+\t\t}\n+\t\telsif ($line =~ m/^gpg:(.)+BAD(.)+/) {\n+\t\t\tif (! $opts{'-remove_signoff'}) {\n+\t\t\t\tprint \"<span class=\\\"bad_sign\\\">\" . esc_html($line) . \"</span><br/>\\n\";\n+\t\t\t\t$skip_blank_line = 1;\n+\t\t\t}\n+\t\t\tnext;\n+\t\t}\n+\t\telsif ($line =~ m/^\\s*([A-Z][-A-Za-z]*-[Bb]y|C[Cc]): /) {\n \t\t\tif (! $opts{'-remove_signoff'}) {\n \t\t\t\tprint \"<span class=\\\"signoff\\\">\" . esc_html($line) . \"</span><br/>\\n\";\n \t\t\t\t$skip_blank_line = 1;\ndiff --git a/gitweb/static/gitweb.css b/gitweb/static/gitweb.css\nindex 3212601..e99e223 100644\n--- a/gitweb/static/gitweb.css\n+++ b/gitweb/static/gitweb.css\n@@ -136,6 +136,17 @@ span.signoff {\n \tcolor: #888888;\n }\n \n+span.good_sign {\n+\tfont-weight: bold;\n+\tbackground-color: #aaffaa;\n+}\n+\n+span.bad_sign {\n+\tfont-weight: bold;\n+\tbackground-color: #880000;\n+\tcolor: #ffffff\n+}\n+\n div.log_link {\n \tpadding: 0px 8px;\n \tfont-size: 70%;\n-- \n1.8.3.rc0.10.g8974033\n"},{"id":"238023","messageId":"xmqqfvm2b4h1.fsf@gitster.dls.corp.google.com","threadId":"36311","inReplyTo":"1396000130-10322-1-git-send-email-v.kartashov@npo-echelon.ru","subject":"Re: [PATCH] gitweb: gpg signature status indication for commits","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-03-28T17:47:06Z","receivedAt":"2014-03-28T17:47:06Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Victor Kartashov <v.kartashov@npo-echelon.ru> writes:\n\n> show gpg signature (if any) for commit message in gitweb\n> in case of valid signature highlight it with green\n> in case of invalid signature highlight it with red\n\nIf that is a single sentence, please write it as such:\n\n   Show gpg signature (if any) for commit message in gitweb in case of\n   valid signature highlight it with green in case of invalid signature\n   highlight it with red.\n\nBut that is almost unparsable ;-)\n\n   Teach gitweb to show GPG signature verification status when\n   showing a commit that is signed.  Highlight in green or red to\n   differentiate valid and invalid signatures.\n\nor something?\n\nIs it a good idea to do this unconditionally in all repositories?\n\n> Signed-off-by: Victor Kartashov <victor.kartashov@gmail.com>\n> ---\n>  gitweb/gitweb.perl       | 36 +++++++++++++++++++++++++++++-------\n>  gitweb/static/gitweb.css | 11 +++++++++++\n>  2 files changed, 40 insertions(+), 7 deletions(-)\n>\n> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\n> index 79057b7..ccde90f 100755\n> --- a/gitweb/gitweb.perl\n> +++ b/gitweb/gitweb.perl\n> @@ -3430,8 +3430,9 @@ sub parse_commit_text {\n>  \tmy ($commit_text, $withparents) = @_;\n>  \tmy @commit_lines = split '\\n', $commit_text;\n>  \tmy %co;\n> +\tmy @signature = ();\n>  \n> -\tpop @commit_lines; # Remove '\\0'\n> +\tpop @commit_lines if ($commit_lines[-1] =~ \"\\0\"); # Remove '\\0'\n\nThis comment, which only says what it intends to do without saying\nwhy it wants to do so, does not explain why this is a good change.\n\nDoes the code even know if $commit_lines[-1] is a non-empty string?\nIs it safe to assume if $commit_lines[-1] has a NUL anywhere, it is\nalways the last line that ends the record, which is not part of the\ncommit log message?\n\nI am assuming that this $commit_text is read from \"log -z\" (or\n\"rev-list -z\") output and split at NUL boundary, but if that is the\ncase, it might be cleaner to remove the trailing NUL from $commit_text\nbefore even attempting to split it into an array at LFs, but that is\nan unrelated tangent.\n\nA bigger question is why does the incoming data sometimes ends with\nNUL that must be stripped out, and sometimes does not?  I see that\nyou are updating the data producer in the later part of the patch;\nwouldn't it be saner if you have the data producer produce the input\nto this function in a way that is consistent with the current code,\ni.e. always terminate the output with a NUL?\n\n> @@ -3469,6 +3470,9 @@ sub parse_commit_text {\n>  \t\t\t\t$co{'committer_name'} = $co{'committer'};\n>  \t\t\t}\n>  \t\t}\n> +\t\telsif ($line =~ /^gpg: /) {\n\nI think Eric already pointed out the style issue on this line.\n\n> @@ -3508,6 +3512,10 @@ sub parse_commit_text {\n>  \tforeach my $line (@commit_lines) {\n>  \t\t$line =~ s/^    //;\n>  \t}\n> +\tpush(@commit_lines, \"\") if scalar @signature;\n> +\tforeach my $sig (@signature) {\n> +\t\tpush(@commit_lines, $sig);\n> +\t}\n\nHmm, is it different from doing:\n\n\tpush @commit_lines, @signature;\n\nin some way?\n\n> @@ -4571,7 +4579,21 @@ sub git_print_log {\n>  \t# print log\n>  \tmy $skip_blank_line = 0;\n>  \tforeach my $line (@$log) {\n> -\t\tif ($line =~ m/^\\s*([A-Z][-A-Za-z]*-[Bb]y|C[Cc]): /) {\n> +\t\tif ($line =~ m/^gpg:(.)+Good(.)+/) {\n> +\t\t\tif (! $opts{'-remove_signoff'}) {\n\nSorry, but I fail to see what the \"remove-signoff\" option has to do\nwith this new feature.  The interaction needs to be explained in the\nlog message.\n\n> +\t\t\t\tprint \"<span class=\\\"good_sign\\\">\" . esc_html($line) . \"</span><br/>\\n\";\n> +\t\t\t\t$skip_blank_line = 1;\n> +\t\t\t}\n> +\t\t\tnext;\n> +\t\t}\n> +\t\telsif ($line =~ m/^gpg:(.)+BAD(.)+/) {\n> +\t\t\tif (! $opts{'-remove_signoff'}) {\n> +\t\t\t\tprint \"<span class=\\\"bad_sign\\\">\" . esc_html($line) . \"</span><br/>\\n\";\n> +\t\t\t\t$skip_blank_line = 1;\n> +\t\t\t}\n> +\t\t\tnext;\n> +\t\t}\n> +\t\telsif ($line =~ m/^\\s*([A-Z][-A-Za-z]*-[Bb]y|C[Cc]): /) {\n>  \t\t\tif (! $opts{'-remove_signoff'}) {\n>  \t\t\t\tprint \"<span class=\\\"signoff\\\">\" . esc_html($line) . \"</span><br/>\\n\";\n>  \t\t\t\t$skip_blank_line = 1;\n> diff --git a/gitweb/static/gitweb.css b/gitweb/static/gitweb.css\n> index 3212601..e99e223 100644\n> --- a/gitweb/static/gitweb.css\n> +++ b/gitweb/static/gitweb.css\n> @@ -136,6 +136,17 @@ span.signoff {\n>  \tcolor: #888888;\n>  }\n>  \n> +span.good_sign {\n> +\tfont-weight: bold;\n> +\tbackground-color: #aaffaa;\n> +}\n> +\n> +span.bad_sign {\n> +\tfont-weight: bold;\n> +\tbackground-color: #880000;\n> +\tcolor: #ffffff\n> +}\n> +\n>  div.log_link {\n>  \tpadding: 0px 8px;\n>  \tfont-size: 70%;\n"},{"id":"238037","messageId":"CAGfpA8RUaJKxEcqjpmBFeinefK=qu8sYuQHxRTg9ndFG_GJGEA@mail.gmail.com","threadId":"36311","inReplyTo":"CAGfpA8RWnX9DZtDiZ3Zf=8s+ga+DEmTbGDN0b7B0JM5_U4tAPw@mail.gmail.com","subject":"Re: [PATCH] gitweb: gpg signature status indication for commits","fromName":"Victor Kartashov","fromEmail":"victor.kartashov@gmail.com","sentAt":"2014-03-28T19:14:51Z","receivedAt":"2014-03-28T19:14:51Z","isPatch":true,"sender":{"key":"victor.kartashov@gmail.com","avatar":null},"body":" On 28 March 2014 21:47, Junio C Hamano <gitster@pobox.com> wrote:\n>\n>\n>    Teach gitweb to show GPG signature verification status when\n>    showing a commit that is signed.  Highlight in green or red to\n>    differentiate valid and invalid signatures.\n>\n> or something?\n\n\n Yes, kind of :)\n\n> Is it a good idea to do this unconditionally in all repositories?\n\n\n Actually, I don't know. It's a question to discuss. This patch\ndoesn't affect commits without signature. And if there is a signature,\nyou robably would like to validate it.\n There is an option \"remove_signoff\" that, as I thought, would have an\neffect on this. But I couldn't find where it's defined.\n\n>\n>\n> This comment, which only says what it intends to do without saying\n> why it wants to do so, does not explain why this is a good change.\n>\n> Does the code even know if $commit_lines[-1] is a non-empty string?\n> Is it safe to assume if $commit_lines[-1] has a NUL anywhere, it is\n> always the last line that ends the record, which is not part of the\n> commit log message?\n>\n> I am assuming that this $commit_text is read from \"log -z\" (or\n> \"rev-list -z\") output and split at NUL boundary, but if that is the\n> case, it might be cleaner to remove the trailing NUL from $commit_text\n> before even attempting to split it into an array at LFs, but that is\n> an unrelated tangent.\n>\n> A bigger question is why does the incoming data sometimes ends with\n> NUL that must be stripped out, and sometimes does not?  I see that\n> you are updating the data producer in the later part of the patch;\n> wouldn't it be saner if you have the data producer produce the input\n> to this function in a way that is consistent with the current code,\n> i.e. always terminate the output with a NUL?\n\n\n It seems to be a good idea. I'll try to do that.\n\n> > @@ -3469,6 +3470,9 @@ sub parse_commit_text {\n> >                               $co{'committer_name'} = $co{'committer'};\n> >                       }\n> >               }\n> > +             elsif ($line =~ /^gpg: /) {\n>\n> I think Eric already pointed out the style issue on this line.\n>\n> > @@ -3508,6 +3512,10 @@ sub parse_commit_text {\n> >       foreach my $line (@commit_lines) {\n> >               $line =~ s/^    //;\n> >       }\n> > +     push(@commit_lines, \"\") if scalar @signature;\n> > +     foreach my $sig (@signature) {\n> > +             push(@commit_lines, $sig);\n> > +     }\n>\n> Hmm, is it different from doing:\n>\n>         push @commit_lines, @signature;\n>\n> in some way?\n>\n> > @@ -4571,7 +4579,21 @@ sub git_print_log {\n> >       # print log\n> >       my $skip_blank_line = 0;\n> >       foreach my $line (@$log) {\n> > -             if ($line =~ m/^\\s*([A-Z][-A-Za-z]*-[Bb]y|C[Cc]): /) {\n> > +             if ($line =~ m/^gpg:(.)+Good(.)+/) {\n> > +                     if (! $opts{'-remove_signoff'}) {\n>\n> Sorry, but I fail to see what the \"remove-signoff\" option has to do\n> with this new feature.  The interaction needs to be explained in the\n> log message.\n\n\n I explained it above. From my point of view, one may want to remove\ngpg signature and \"sign-off\" inscription together.\n Maybe, we should discuss this question, and after that I'll prepare new patch.\n\n>\n>\n> > +                             print \"<span class=\\\"good_sign\\\">\" . esc_html($line) . \"</span><br/>\\n\";\n> > +                             $skip_blank_line = 1;\n> > +                     }\n> > +                     next;\n> > +             }\n> > +             elsif ($line =~ m/^gpg:(.)+BAD(.)+/) {\n> > +                     if (! $opts{'-remove_signoff'}) {\n> > +                             print \"<span class=\\\"bad_sign\\\">\" . esc_html($line) . \"</span><br/>\\n\";\n> > +                             $skip_blank_line = 1;\n> > +                     }\n> > +                     next;\n> > +             }\n> > +             elsif ($line =~ m/^\\s*([A-Z][-A-Za-z]*-[Bb]y|C[Cc]): /) {\n> >                       if (! $opts{'-remove_signoff'}) {\n> >                               print \"<span class=\\\"signoff\\\">\" . esc_html($line) . \"</span><br/>\\n\";\n> >                               $skip_blank_line = 1;\n> > diff --git a/gitweb/static/gitweb.css b/gitweb/static/gitweb.css\n> > index 3212601..e99e223 100644\n> > --- a/gitweb/static/gitweb.css\n> > +++ b/gitweb/static/gitweb.css\n> > @@ -136,6 +136,17 @@ span.signoff {\n> >       color: #888888;\n> >  }\n> >\n> > +span.good_sign {\n> > +     font-weight: bold;\n> > +     background-color: #aaffaa;\n> > +}\n> > +\n> > +span.bad_sign {\n> > +     font-weight: bold;\n> > +     background-color: #880000;\n> > +     color: #ffffff\n> > +}\n> > +\n> >  div.log_link {\n> >       padding: 0px 8px;\n> >       font-size: 70%;\n"}]}