All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] gitweb: gpg signature status indication for commits
@ 2014-03-28  9:48 Victor Kartashov
  2014-03-28 17:47 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Victor Kartashov @ 2014-03-28  9:48 UTC (permalink / raw)
  To: sunshine; +Cc: git, Victor Kartashov

show gpg signature (if any) for commit message in gitweb
in case of valid signature highlight it with green
in case of invalid signature highlight it with red

Signed-off-by: Victor Kartashov <victor.kartashov@gmail.com>
---
here's new patch
fixed remarks by Eric Sunshine
"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.

 gitweb/gitweb.perl       | 36 +++++++++++++++++++++++++++++-------
 gitweb/static/gitweb.css | 11 +++++++++++
 2 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 79057b7..ccde90f 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] =~ "\0"); # Remove '\0'
 
 	if (! @commit_lines) {
 		return;
@@ -3469,6 +3470,9 @@ sub parse_commit_text {
 				$co{'committer_name'} = $co{'committer'};
 			}
 		}
+		elsif ($line =~ /^gpg: /) {
+			push @signature, $line;
+		}
 	}
 	if (!defined $co{'tree'}) {
 		return;
@@ -3508,6 +3512,10 @@ sub parse_commit_text {
 	foreach my $line (@commit_lines) {
 		$line =~ s/^    //;
 	}
+	push(@commit_lines, "") if scalar @signature;
+	foreach my $sig (@signature) {
+		push(@commit_lines, $sig);
+	}
 	$co{'comment'} = \@commit_lines;
 
 	my $age = time - $co{'committer_epoch'};
@@ -3530,13 +3538,13 @@ 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 +4579,21 @@ 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/^gpg:(.)+BAD(.)+/) {
+			if (! $opts{'-remove_signoff'}) {
+				print "<span class=\"bad_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..e99e223 100644
--- a/gitweb/static/gitweb.css
+++ b/gitweb/static/gitweb.css
@@ -136,6 +136,17 @@ span.signoff {
 	color: #888888;
 }
 
+span.good_sign {
+	font-weight: bold;
+	background-color: #aaffaa;
+}
+
+span.bad_sign {
+	font-weight: bold;
+	background-color: #880000;
+	color: #ffffff
+}
+
 div.log_link {
 	padding: 0px 8px;
 	font-size: 70%;
-- 
1.8.3.rc0.10.g8974033

^ permalink raw reply related	[flat|nested] 5+ messages in thread
* [PATCH] gitweb: gpg signature status indication for commits
@ 2014-03-27 14:56 Victor Kartashov
  2014-03-27 20:12 ` Eric Sunshine
  0 siblings, 1 reply; 5+ messages in thread
From: Victor Kartashov @ 2014-03-27 14:56 UTC (permalink / raw)
  To: git

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(-)

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-03-28 19:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-28  9:48 [PATCH] gitweb: gpg signature status indication for commits Victor Kartashov
2014-03-28 17:47 ` Junio C Hamano
     [not found]   ` <CAGfpA8RWnX9DZtDiZ3Zf=8s+ga+DEmTbGDN0b7B0JM5_U4tAPw@mail.gmail.com>
2014-03-28 19:14     ` Victor Kartashov
  -- strict thread matches above, loose matches on Subject: below --
2014-03-27 14:56 Victor Kartashov
2014-03-27 20:12 ` Eric Sunshine

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.