Skip to content

Commit 4de9394

Browse files
mgornygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3daaaab commit 4de9394

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

Documentation/pretty-formats.txt

+2
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ endif::git-rev-list[]
154154
- '%GS': show the name of the signer for a signed commit
155155
- '%GK': show the key used to sign a signed commit
156156
- '%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
157159
- '%gD': reflog selector, e.g., `refs/stash@{1}` or
158160
`refs/stash@{2 minutes ago`}; the format follows the rules described
159161
for the `-g` option. The portion before the `@` is the refname as

gpg-interface.c

+15-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ void signature_check_clear(struct signature_check *sigc)
7474
FREE_AND_NULL(sigc->signer);
7575
FREE_AND_NULL(sigc->key);
7676
FREE_AND_NULL(sigc->fingerprint);
77+
FREE_AND_NULL(sigc->primary_key_fingerprint);
7778
}
7879

7980
/* An exclusive status -- only one of them can appear in output */
@@ -108,7 +109,7 @@ static void parse_gpg_output(struct signature_check *sigc)
108109
{
109110
const char *buf = sigc->gpg_status;
110111
const char *line, *next;
111-
int i;
112+
int i, j;
112113
int seen_exclusive_status = 0;
113114

114115
/* Iterate over all lines */
@@ -147,6 +148,18 @@ static void parse_gpg_output(struct signature_check *sigc)
147148
next = strchrnul(line, ' ');
148149
free(sigc->fingerprint);
149150
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);
150163
}
151164

152165
break;
@@ -165,6 +178,7 @@ static void parse_gpg_output(struct signature_check *sigc)
165178
*/
166179
sigc->result = 'E';
167180
/* Clear partial data to avoid confusion */
181+
FREE_AND_NULL(sigc->primary_key_fingerprint);
168182
FREE_AND_NULL(sigc->fingerprint);
169183
FREE_AND_NULL(sigc->signer);
170184
FREE_AND_NULL(sigc->key);

gpg-interface.h

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct signature_check {
2424
char *signer;
2525
char *key;
2626
char *fingerprint;
27+
char *primary_key_fingerprint;
2728
};
2829

2930
void signature_check_clear(struct signature_check *sigc);

pretty.c

+4
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,10 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
12601260
if (c->signature_check.fingerprint)
12611261
strbuf_addstr(sb, c->signature_check.fingerprint);
12621262
break;
1263+
case 'P':
1264+
if (c->signature_check.primary_key_fingerprint)
1265+
strbuf_addstr(sb, c->signature_check.primary_key_fingerprint);
1266+
break;
12631267
default:
12641268
return 0;
12651269
}

0 commit comments

Comments
 (0)