{"thread":{"id":"36304","subject":"[PATCH] gitweb: gpg signature status indication for commits","startedAt":"2014-03-27T14:56:20Z","lastAt":"2014-03-27T20:12:48Z","messageCount":2,"participants":["Victor Kartashov","Eric Sunshine"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"237906","messageId":"1395932180-19454-1-git-send-email-victor.kartashov@gmail.com","threadId":"36304","inReplyTo":null,"subject":"[PATCH] gitweb: gpg signature status indication for commits","fromName":"Victor Kartashov","fromEmail":"victor.kartashov@gmail.com","sentAt":"2014-03-27T14:56:20Z","receivedAt":"2014-03-27T14:56:20Z","isPatch":true,"sender":{"key":"victor.kartashov@gmail.com","avatar":null},"body":"shows gpg signature (if any) for commit message in gitweb\nin case of successfully verifying the signature highlights it with green\n\nSigned-off-by: Victor Kartashov <victor.kartashov@gmail.com>\n---\n gitweb/gitweb.perl       | 33 ++++++++++++++++++++++++++-------\n gitweb/static/gitweb.css |  5 +++++\n 2 files changed, 31 insertions(+), 7 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 79057b7..0b41392 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] eq \"\\0\"); # Remove '\\0'\n \n \tif (! @commit_lines) {\n \t\treturn;\n@@ -3469,6 +3470,10 @@ 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{\n+\t\t\tpush @signature, $line;\n+\t\t}\n \t}\n \tif (!defined $co{'tree'}) {\n \t\treturn;\n@@ -3508,6 +3513,11 @@ sub parse_commit_text {\n \tforeach my $line (@commit_lines) {\n \t\t$line =~ s/^    //;\n \t}\n+\tpush(@commit_lines, \"\") if(scalar(@signature) > 0);\n+\tforeach my $sig (@signature)\n+\t{\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 +3540,15 @@ 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+\n+\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 +4583,14 @@ 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/^\\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..0b7479c 100644\n--- a/gitweb/static/gitweb.css\n+++ b/gitweb/static/gitweb.css\n@@ -136,6 +136,11 @@ span.signoff {\n \tcolor: #888888;\n }\n \n+span.good_sign {\n+\tfont-weight: bold;\n+\tbackground-color: #aaffaa;\n+}\n+\n div.log_link {\n \tpadding: 0px 8px;\n \tfont-size: 70%;\n-- \n1.8.3.2\n"},{"id":"237943","messageId":"CAPig+cR0_7c8Km3JP_282ENGSa+4nOA=-xi2=V3DoQhTz7kNwA@mail.gmail.com","threadId":"36304","inReplyTo":"1395932180-19454-1-git-send-email-victor.kartashov@gmail.com","subject":"Re: [PATCH] gitweb: gpg signature status indication for commits","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2014-03-27T20:12:48Z","receivedAt":"2014-03-27T20:12:48Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Thu, Mar 27, 2014 at 10:56 AM, Victor Kartashov\n<victor.kartashov@gmail.com> wrote:\n> shows gpg signature (if any) for commit message in gitweb\n> in case of successfully verifying the signature highlights it with green\n\nWrite in imperative mood: \"Show gpg ... highlight it...\"\n\nAs a corollary, would it be meaningful to highlight a bad signature with red?\n\n> Signed-off-by: Victor Kartashov <victor.kartashov@gmail.com>\n> ---\n>  gitweb/gitweb.perl       | 33 ++++++++++++++++++++++++++-------\n>  gitweb/static/gitweb.css |  5 +++++\n>  2 files changed, 31 insertions(+), 7 deletions(-)\n>\n> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\n> index 79057b7..0b41392 100755\n> --- a/gitweb/gitweb.perl\n> +++ b/gitweb/gitweb.perl\n> @@ -3430,8 +3430,9 @@ sub parse_commit_text {\n>         my ($commit_text, $withparents) = @_;\n>         my @commit_lines = split '\\n', $commit_text;\n>         my %co;\n> +       my @signature = ();\n>\n> -       pop @commit_lines; # Remove '\\0'\n> +       pop @commit_lines if ($commit_lines[-1] eq \"\\0\"); # Remove '\\0'\n\nWhat is this change about? Is it related to your gpg change or something else?\n\n>         if (! @commit_lines) {\n>                 return;\n> @@ -3469,6 +3470,10 @@ sub parse_commit_text {\n>                                 $co{'committer_name'} = $co{'committer'};\n>                         }\n>                 }\n> +               elsif ($line =~ /^gpg: /)\n\nInconsistent 'elsif' placement. (Cuddle it with the close-brace.)\n\n> +               {\n\nInconsistent open-brace placement.\n\n> +                       push @signature, $line;\n> +               }\n>         }\n>         if (!defined $co{'tree'}) {\n>                 return;\n> @@ -3508,6 +3513,11 @@ sub parse_commit_text {\n>         foreach my $line (@commit_lines) {\n>                 $line =~ s/^    //;\n>         }\n> +       push(@commit_lines, \"\") if(scalar(@signature) > 0);\n\nMissing space after 'if'.\n\nIn this Perl file, it would be more consistent to drop the '> 0' and\nsay merely 'if scalar @signature'.\n\n> +       foreach my $sig (@signature)\n> +       {\n\nBrace placement.\n\n> +               push(@commit_lines, $sig);\n> +       }\n>         $co{'comment'} = \\@commit_lines;\n>\n>         my $age = time - $co{'committer_epoch'};\n> @@ -3530,13 +3540,15 @@ sub parse_commit {\n>\n>         local $/ = \"\\0\";\n>\n> -       open my $fd, \"-|\", git_cmd(), \"rev-list\",\n> -               \"--parents\",\n> -               \"--header\",\n> -               \"--max-count=1\",\n> +\n> +\n\nUnnecessary two extra blank lines.\n\n> +       open my $fd, \"-|\", git_cmd(), \"show\",\n> +               \"--quiet\",\n> +               \"--date=raw\",\n> +               \"--pretty=format:%H %P%ntree %T%nparent %P%nauthor %an <%ae> %ad%ncommitter %cn <%ce> %cd%n%GG%n%s%n%n%b\",\n>                 $commit_id,\n>                 \"--\",\n> -               or die_error(500, \"Open git-rev-list failed\");\n> +               or die_error(500, \"Open git-show failed\");\n>         %co = parse_commit_text(<$fd>, 1);\n>         close $fd;\n>\n> @@ -4571,7 +4583,14 @@ 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> +                               print \"<span class=\\\"good_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..0b7479c 100644\n> --- a/gitweb/static/gitweb.css\n> +++ b/gitweb/static/gitweb.css\n> @@ -136,6 +136,11 @@ span.signoff {\n>         color: #888888;\n>  }\n>\n> +span.good_sign {\n> +       font-weight: bold;\n> +       background-color: #aaffaa;\n> +}\n> +\n>  div.log_link {\n>         padding: 0px 8px;\n>         font-size: 70%;\n> --\n> 1.8.3.2\n"}]}