Skip to content

Commit 0174eea

Browse files
Michael J Grubergitster
authored andcommitted
pretty: make %GK output the signing key for signed commits
In order to employ signed keys in an automated way it is absolutely necessary to check which keys the signatures come from. Signed-off-by: Michael J Gruber <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4a868fd commit 0174eea

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Documentation/pretty-formats.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ The placeholders are:
133133
- '%GG': raw verification message from GPG for a signed commit
134134
- '%G?': show either "G" for Good or "B" for Bad for a signed commit
135135
- '%GS': show the name of the signer for a signed commit
136+
- '%GK': show the key used to sign a signed commit
136137
- '%gD': reflog selector, e.g., `refs/stash@{1}`
137138
- '%gd': shortened reflog selector, e.g., `stash@{1}`
138139
- '%gn': reflog identity name

pretty.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ struct format_commit_context {
695695
char *gpg_status;
696696
char good_bad;
697697
char *signer;
698+
char *key;
698699
} signature;
699700
char *message;
700701
size_t width, indent1, indent2;
@@ -897,7 +898,9 @@ static void parse_signature_lines(struct format_commit_context *ctx)
897898
if (!found)
898899
continue;
899900
ctx->signature.good_bad = signature_check[i].result;
900-
found += strlen(signature_check[i].check)+17;
901+
found += strlen(signature_check[i].check);
902+
ctx->signature.key = xmemdupz(found, 16);
903+
found += 17;
901904
next = strchrnul(found, '\n');
902905
ctx->signature.signer = xmemdupz(found, next - found);
903906
break;
@@ -1130,6 +1133,10 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
11301133
if (c->signature.signer)
11311134
strbuf_addstr(sb, c->signature.signer);
11321135
break;
1136+
case 'K':
1137+
if (c->signature.key)
1138+
strbuf_addstr(sb, c->signature.key);
1139+
break;
11331140
}
11341141
return 2;
11351142
}

0 commit comments

Comments
 (0)