Now displays if commits were signed using icons. gpg
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>
Mon, 10 Oct 2016 21:28:36 +0000 (23:28 +0200)
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>
Mon, 10 Oct 2016 21:28:36 +0000 (23:28 +0200)
gitweb.cgi
static/gitweb.css

index b8de05c..7724a1f 100755 (executable)
@@ -3436,7 +3436,7 @@ sub parse_commit_text {
        my ($commit_text, $withparents) = @_;
        my @commit_lines = split '\n', $commit_text;
        my %co;
-
+       
        pop @commit_lines; # Remove '\0'
 
        if (! @commit_lines) {
@@ -3445,8 +3445,11 @@ sub parse_commit_text {
 
        my $header = shift @commit_lines;
        if ($header !~ m/^[0-9a-fA-F]{40}/) {
-               return;
+         return;
        }
+       # if ($commit_text =~ m/(-----BEGIN PGP SIGNATURE-----.*-----END PGP SIGNATURE-----)/m ) {
+       #   $co{'sig'} = $1;
+       # }
        ($co{'id'}, my @parents) = split ' ', $header;
        while (my $line = shift @commit_lines) {
                last if $line eq "\n";
@@ -3528,6 +3531,37 @@ sub parse_commit_text {
                $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
        }
        return %co;
+      }
+
+sub build_commit_sig_table {
+#  my @commits = `git log --pretty="format:%H %G?"`;
+  open my $fd, "-|", git_cmd(), "log", '--pretty=%H %G?' or return;
+  my @commits = <$fd>;
+  close $fd;
+  my %ch;
+  my $commit;
+  my $signed;
+  open TMP, ">/tmp/commit";
+  foreach (@commits) {
+    print TMP $_;
+    ($commit,$signed) = split(" ",$_);
+    if ((defined $commit) and (defined $signed)) {
+      $ch{$commit} = $signed;
+    }
+  }
+  return %ch;
+}
+
+
+sub verify_commit {
+  my %co = @_;
+  my %table = build_commit_sig_table();
+  if (defined $table{$co{'id'}}) {
+    if ($table{$co{'id'}} eq 'U' or $table{$co{'id'}} eq 'G') {
+      return '<span class="octicon octicon-verified" title="GPG signed commit"></span> ';
+    }
+  }
+  return '<span class="octicon octicon-unverified" title="Unsigned commit"></span> ';
 }
 
 sub parse_commit {
@@ -5862,8 +5896,9 @@ sub git_log_body {
                next if !%co;
                my $commit = $co{'id'};
                my $ref = format_ref_marker($refs, $commit);
+               my $verified = verify_commit(%co);
                git_print_header_div('commit',
-                              "<span class=\"age\">$co{'age_string'}</span>" .
+                              "<span class=\"age\">$co{'age_string'}</span>" .$verified.
                               esc_html($co{'title'}),
                               $commit, undef, $ref);
                print "<div class=\"title_text\">\n" .
@@ -5901,6 +5936,7 @@ sub git_shortlog_body {
        for (my $i = $from; $i <= $to; $i++) {
                my %co = %{$commitlist->[$i]};
                my $commit = $co{'id'};
+               my $verified = verify_commit(%co);
                my $ref = format_ref_marker($refs, $commit);
                if ($alternate) {
                        print "<tr class=\"dark\">\n";
@@ -5911,7 +5947,7 @@ sub git_shortlog_body {
                # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
                print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
                      format_author_html('td', \%co, 10) . "<td>";
-               print format_subject_html($co{'title'}, $co{'title_short'},
+               print $verified." ".format_subject_html($co{'title'}, $co{'title_short'},
                                          href(action=>"commit", hash=>$commit), $ref);
                print "</td>\n" .
                      "<td class=\"link\">" .
@@ -7211,6 +7247,7 @@ sub git_tree {
        git_header_html();
        my $basedir = '';
        my %co;
+       my $verified;
        if ( defined $hash_base ) {
                my @views_nav = ();
                if (defined $file_name) {
@@ -7236,9 +7273,10 @@ sub git_tree {
                  %co = parse_commit($hash);
                }
                if (%co) {
+                 $verified = verify_commit(%co);
                  git_heads_nav(\@headslist, $co{id}, undef, undef, undef, 'tree'); # Print list of branches
                }
-               git_print_header_div('commit', esc_html($co{'title'}) , $hash_base, undef, $ref);
+               git_print_header_div('commit', $verified.esc_html($co{'title'}) , $hash_base, undef, $ref);
        } else {
                undef $hash_base;
                print "<div class=\"page_nav\">\n";
@@ -7578,11 +7616,11 @@ sub git_commit {
        git_print_page_nav('commit', '',
                           $hash, $co{'tree'}, $hash,
                           $formats_nav);
-
+       my $verified = verify_commit(%co);
        if (defined $co{'parent'}) {
-               git_print_header_div('commitdiff', esc_html($co{'title'}) , $hash, undef, $ref);
+               git_print_header_div('commitdiff', $verified." ".esc_html($co{'title'}) , $hash, undef, $ref);
        } else {
-               git_print_header_div('tree', esc_html($co{'title'}) , $co{'tree'}, $hash, $ref);
+               git_print_header_div('tree', $verified." ".esc_html($co{'title'}) , $co{'tree'}, $hash, $ref);
        }
        print "<div class=\"title_text\">\n" .
              "<table class=\"object_header\">\n";
@@ -7761,8 +7799,9 @@ sub git_blobdiff {
                $formats_nav .= diff_style_nav($diff_style);
                git_header_html(undef, $expires);
                if (defined $hash_base && (my %co = parse_commit($hash_base))) {
-                       git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
-                       git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
+                 my $verified = verify_commit(%co);
+                 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
+                 git_print_header_div('commit', $verified." ".esc_html($co{'title'}), $hash_base);
                } else {
                        print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
                        print "<div class=\"title\">".esc_html("$hash vs $hash_parent")."</div>\n";
@@ -7992,7 +8031,8 @@ sub git_commitdiff {
 
                git_header_html(undef, $expires);
                git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
-               git_print_header_div('commit', esc_html($co{'title'}), $hash, undef, $ref);
+               my $verified = verify_commit(%co);
+               git_print_header_div('commit', $verified." ".esc_html($co{'title'}), $hash, undef, $ref);
                print "<div class=\"title_text\">\n" .
                      "<table class=\"object_header\">\n";
                git_print_authorship_rows(\%co);
index 2c82a72..8b78b38 100644 (file)
@@ -769,6 +769,10 @@ div.heads a:hover {
     background: #0c0;
 }
 
+.octicon-verified {
+    color: #0a0;
+}
+
 /* Style definition generated by highlight 2.4.5, http://www.andre-simon.de/ */
 
 /* Highlighting theme definition: */
@@ -786,3 +790,4 @@ div.heads a:hover {
 .kwb    { color:#830000; }
 .kwc    { color:#000000; font-weight:bold; }
 .kwd    { color:#010181; }
+