gpg-interface.c: obtain primary key fingerprint as well

Obtain the primary key fingerprint off VALIDSIG status message, and expose it via %GP format. Signed-off-by: Michał Górny <mgorny@gentoo.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michał Górny committed Oct 22, 2018 at 18:38 UTC 4de9394dcb769394f490a0285015a1d26beb54d1
4 files changed +22 -1
Documentation/pretty-formats.txt
+2
@@ -154,6 +154,8 @@ endif::git-rev-list[]
154 - '%GS': show the name of the signer for a signed commit
155 - '%GK': show the key used to sign a signed commit
156 - '%GF': show the fingerprint of the key used to sign a signed commit
157 +- '%GP': show the fingerprint of the primary key whose subkey was used
158 + to sign a signed commit
159 - '%gD': reflog selector, e.g., `refs/stash@{1}` or
160 `refs/stash@{2 minutes ago`}; the format follows the rules described
161 for the `-g` option. The portion before the `@` is the refname as
gpg-interface.c
+15 -1
@@ -74,6 +74,7 @@ void signature_check_clear(struct signature_check *sigc)
74 FREE_AND_NULL(sigc->signer);
75 FREE_AND_NULL(sigc->key);
76 FREE_AND_NULL(sigc->fingerprint);
77 + FREE_AND_NULL(sigc->primary_key_fingerprint);
78 }
79
80 /* An exclusive status -- only one of them can appear in output */
@@ -108,7 +109,7 @@ static void parse_gpg_output(struct signature_check *sigc)
109 {
110 const char *buf = sigc->gpg_status;
111 const char *line, *next;
111 - int i;
112 + int i, j;
113 int seen_exclusive_status = 0;
114
115 /* Iterate over all lines */
@@ -147,6 +148,18 @@ static void parse_gpg_output(struct signature_check *sigc)
148 next = strchrnul(line, ' ');
149 free(sigc->fingerprint);
150 sigc->fingerprint = xmemdupz(line, next - line);
151 +
152 + /* Skip interim fields */
153 + for (j = 9; j > 0; j--) {
154 + if (!*next)
155 + break;
156 + line = next + 1;
157 + next = strchrnul(line, ' ');
158 + }
159 +
160 + next = strchrnul(line, '\n');
161 + free(sigc->primary_key_fingerprint);
162 + sigc->primary_key_fingerprint = xmemdupz(line, next - line);
163 }
164
165 break;
@@ -165,6 +178,7 @@ found_duplicate_status:
178 */
179 sigc->result = 'E';
180 /* Clear partial data to avoid confusion */
181 + FREE_AND_NULL(sigc->primary_key_fingerprint);
182 FREE_AND_NULL(sigc->fingerprint);
183 FREE_AND_NULL(sigc->signer);
184 FREE_AND_NULL(sigc->key);
gpg-interface.h
+1
@@ -24,6 +24,7 @@ struct signature_check {
24 char *signer;
25 char *key;
26 char *fingerprint;
27 + char *primary_key_fingerprint;
28 };
29
30 void signature_check_clear(struct signature_check *sigc);
pretty.c
+4
@@ -1260,6 +1260,10 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
1260 if (c->signature_check.fingerprint)
1261 strbuf_addstr(sb, c->signature_check.fingerprint);
1262 break;
1263 + case 'P':
1264 + if (c->signature_check.primary_key_fingerprint)
1265 + strbuf_addstr(sb, c->signature_check.primary_key_fingerprint);
1266 + break;
1267 default:
1268 return 0;
1269 }