threads / patch / 36304

patchgitweb: gpg signature status indication for commits

Subject: [PATCH] gitweb: gpg signature status indication for commits

## tl;dr

2 messages between Mar 27, 2014 and Mar 27, 2014. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Victor Kartashov· Mar 27, 2014, 14:56 UTC · lore

shows gpg signature (if any) for commit message in gitweb in case of successfully verifying the signature highlights it with green

Signed-off-by: Victor Kartashov <victor.kartashov@gmail.com>
---
 gitweb/gitweb.perl       | 33 ++++++++++++++++++++++++++-------
 gitweb/static/gitweb.css |  5 +++++
 2 files changed, 31 insertions(+), 7 deletions(-)
Show changes to 2 files +31 −7

gitweb/gitweb.perl, gitweb/static/gitweb.css

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 79057b7..0b41392 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3430,8 +3430,9 @@ sub parse_commit_text {
 	my ($commit_text, $withparents) = @_;
 	my @commit_lines = split '\n', $commit_text;
 	my %co;
+	my @signature = ();
 
-	pop @commit_lines; # Remove '\0'
+	pop @commit_lines if ($commit_lines[-1] eq "\0"); # Remove '\0'
 
 	if (! @commit_lines) {
 		return;
@@ -3469,6 +3470,10 @@ sub parse_commit_text {
 				$co{'committer_name'} = $co{'committer'};
 			}
 		}
+		elsif ($line =~ /^gpg: /)
+		{
+			push @signature, $line;
+		}
 	}
 	if (!defined $co{'tree'}) {
 		return;
@@ -3508,6 +3513,11 @@ sub parse_commit_text {
 	foreach my $line (@commit_lines) {
 		$line =~ s/^    //;
 	}
+	push(@commit_lines, "") if(scalar(@signature) > 0);
+	foreach my $sig (@signature)
+	{
+		push(@commit_lines, $sig);
+	}
 	$co{'comment'} = \@commit_lines;
 
 	my $age = time - $co{'committer_epoch'};
@@ -3530,13 +3540,15 @@ sub parse_commit {
 
 	local $/ = "\0";
 
-	open my $fd, "-|", git_cmd(), "rev-list",
-		"--parents",
-		"--header",
-		"--max-count=1",
+
+
+	open my $fd, "-|", git_cmd(), "show",
+		"--quiet",
+		"--date=raw",
+		"--pretty=format:%H %P%ntree %T%nparent %P%nauthor %an <%ae> %ad%ncommitter %cn <%ce> %cd%n%GG%n%s%n%n%b",
 		$commit_id,
 		"--",
-		or die_error(500, "Open git-rev-list failed");
+		or die_error(500, "Open git-show failed");
 	%co = parse_commit_text(<$fd>, 1);
 	close $fd;
 
@@ -4571,7 +4583,14 @@ sub git_print_log {
 	# print log
 	my $skip_blank_line = 0;
 	foreach my $line (@$log) {
-		if ($line =~ m/^\s*([A-Z][-A-Za-z]*-[Bb]y|C[Cc]): /) {
+		if ($line =~ m/^gpg:(.)+Good(.)+/) {
+			if (! $opts{'-remove_signoff'}) {
+				print "<span class=\"good_sign\">" . esc_html($line) . "</span><br/>\n";
+				$skip_blank_line = 1;
+			}
+			next;
+		}
+		elsif ($line =~ m/^\s*([A-Z][-A-Za-z]*-[Bb]y|C[Cc]): /) {
 			if (! $opts{'-remove_signoff'}) {
 				print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
 				$skip_blank_line = 1;
diff --git a/gitweb/static/gitweb.css b/gitweb/static/gitweb.css
index 3212601..0b7479c 100644
--- a/gitweb/static/gitweb.css
+++ b/gitweb/static/gitweb.css
@@ -136,6 +136,11 @@ span.signoff {
 	color: #888888;
 }
 
+span.good_sign {
+	font-weight: bold;
+	background-color: #aaffaa;
+}
+
 div.log_link {
 	padding: 0px 8px;
 	font-size: 70%;
-- 
1.8.3.2
Eric Sunshine· Mar 27, 2014, 20:12 UTC · re: Victor Kartashov · lore

Re: [PATCH] gitweb: gpg signature status indication for commits

On Thu, Mar 27, 2014 at 10:56 AM, Victor Kartashov <victor.kartashov@gmail.com> wrote:

> shows gpg signature (if any) for commit message in gitweb
> in case of successfully verifying the signature highlights it with green
Write in imperative mood: "Show gpg ... highlight it..."
As a corollary, would it be meaningful to highlight a bad signature with red?
Show 18 quoted lines
> Signed-off-by: Victor Kartashov <victor.kartashov@gmail.com>
> ---
>  gitweb/gitweb.perl       | 33 ++++++++++++++++++++++++++-------
>  gitweb/static/gitweb.css |  5 +++++
>  2 files changed, 31 insertions(+), 7 deletions(-)
>
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index 79057b7..0b41392 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -3430,8 +3430,9 @@ sub parse_commit_text {
>         my ($commit_text, $withparents) = @_;
>         my @commit_lines = split '\n', $commit_text;
>         my %co;
> +       my @signature = ();
>
> -       pop @commit_lines; # Remove '\0'
> +       pop @commit_lines if ($commit_lines[-1] eq "\0"); # Remove '\0'
What is this change about? Is it related to your gpg change or something else?
Show 7 quoted lines
>         if (! @commit_lines) {
>                 return;
> @@ -3469,6 +3470,10 @@ sub parse_commit_text {
>                                 $co{'committer_name'} = $co{'committer'};
>                         }
>                 }
> +               elsif ($line =~ /^gpg: /)
Inconsistent 'elsif' placement. (Cuddle it with the close-brace.)
> +               {
Inconsistent open-brace placement.
Show 10 quoted lines
> +                       push @signature, $line;
> +               }
>         }
>         if (!defined $co{'tree'}) {
>                 return;
> @@ -3508,6 +3513,11 @@ sub parse_commit_text {
>         foreach my $line (@commit_lines) {
>                 $line =~ s/^    //;
>         }
> +       push(@commit_lines, "") if(scalar(@signature) > 0);
Missing space after 'if'.

In this Perl file, it would be more consistent to drop the '> 0' and say merely 'if scalar @signature'.

> +       foreach my $sig (@signature)
> +       {
Brace placement.
Show 15 quoted lines
> +               push(@commit_lines, $sig);
> +       }
>         $co{'comment'} = \@commit_lines;
>
>         my $age = time - $co{'committer_epoch'};
> @@ -3530,13 +3540,15 @@ sub parse_commit {
>
>         local $/ = "\0";
>
> -       open my $fd, "-|", git_cmd(), "rev-list",
> -               "--parents",
> -               "--header",
> -               "--max-count=1",
> +
> +
Unnecessary two extra blank lines.
Show 45 quoted lines
> +       open my $fd, "-|", git_cmd(), "show",
> +               "--quiet",
> +               "--date=raw",
> +               "--pretty=format:%H %P%ntree %T%nparent %P%nauthor %an <%ae> %ad%ncommitter %cn <%ce> %cd%n%GG%n%s%n%n%b",
>                 $commit_id,
>                 "--",
> -               or die_error(500, "Open git-rev-list failed");
> +               or die_error(500, "Open git-show failed");
>         %co = parse_commit_text(<$fd>, 1);
>         close $fd;
>
> @@ -4571,7 +4583,14 @@ sub git_print_log {
>         # print log
>         my $skip_blank_line = 0;
>         foreach my $line (@$log) {
> -               if ($line =~ m/^\s*([A-Z][-A-Za-z]*-[Bb]y|C[Cc]): /) {
> +               if ($line =~ m/^gpg:(.)+Good(.)+/) {
> +                       if (! $opts{'-remove_signoff'}) {
> +                               print "<span class=\"good_sign\">" . esc_html($line) . "</span><br/>\n";
> +                               $skip_blank_line = 1;
> +                       }
> +                       next;
> +               }
> +               elsif ($line =~ m/^\s*([A-Z][-A-Za-z]*-[Bb]y|C[Cc]): /) {
>                         if (! $opts{'-remove_signoff'}) {
>                                 print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
>                                 $skip_blank_line = 1;
> diff --git a/gitweb/static/gitweb.css b/gitweb/static/gitweb.css
> index 3212601..0b7479c 100644
> --- a/gitweb/static/gitweb.css
> +++ b/gitweb/static/gitweb.css
> @@ -136,6 +136,11 @@ span.signoff {
>         color: #888888;
>  }
>
> +span.good_sign {
> +       font-weight: bold;
> +       background-color: #aaffaa;
> +}
> +
>  div.log_link {
>         padding: 0px 8px;
>         font-size: 70%;
> --
> 1.8.3.2

← back to recent threads