Skip to content

Commit 4a868fd

Browse files
Michael J Grubergitster
authored andcommitted
pretty: parse the gpg status lines rather than the output
Currently, parse_signature_lines() parses the gpg output for strings which depend on LANG so it fails to recognize good commit signatures (and thus does not fill in %G? and the like) in most locales. Make it parse the status lines from gpg instead, which are the proper machine interface. This fixes the problem described above. There is a change in behavior for "%GS" which we intentionally do not work around: "%GS" used to put quotes around the signer's uid (or rather: it inherited from the gpg user output). We output the uid without quotes now, just like author and committer names. Signed-off-by: Michael J Gruber <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9cc4ac8 commit 4a868fd

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

pretty.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ struct format_commit_context {
692692
unsigned commit_signature_parsed:1;
693693
struct {
694694
char *gpg_output;
695+
char *gpg_status;
695696
char good_bad;
696697
char *signer;
697698
} signature;
@@ -881,13 +882,13 @@ static struct {
881882
char result;
882883
const char *check;
883884
} signature_check[] = {
884-
{ 'G', ": Good signature from " },
885-
{ 'B', ": BAD signature from " },
885+
{ 'G', "\n[GNUPG:] GOODSIG " },
886+
{ 'B', "\n[GNUPG:] BADSIG " },
886887
};
887888

888889
static void parse_signature_lines(struct format_commit_context *ctx)
889890
{
890-
const char *buf = ctx->signature.gpg_output;
891+
const char *buf = ctx->signature.gpg_status;
891892
int i;
892893

893894
for (i = 0; i < ARRAY_SIZE(signature_check); i++) {
@@ -896,7 +897,7 @@ static void parse_signature_lines(struct format_commit_context *ctx)
896897
if (!found)
897898
continue;
898899
ctx->signature.good_bad = signature_check[i].result;
899-
found += strlen(signature_check[i].check);
900+
found += strlen(signature_check[i].check)+17;
900901
next = strchrnul(found, '\n');
901902
ctx->signature.signer = xmemdupz(found, next - found);
902903
break;
@@ -908,6 +909,7 @@ static void parse_commit_signature(struct format_commit_context *ctx)
908909
struct strbuf payload = STRBUF_INIT;
909910
struct strbuf signature = STRBUF_INIT;
910911
struct strbuf gpg_output = STRBUF_INIT;
912+
struct strbuf gpg_status = STRBUF_INIT;
911913
int status;
912914

913915
ctx->commit_signature_parsed = 1;
@@ -917,13 +919,15 @@ static void parse_commit_signature(struct format_commit_context *ctx)
917919
goto out;
918920
status = verify_signed_buffer(payload.buf, payload.len,
919921
signature.buf, signature.len,
920-
&gpg_output, NULL);
922+
&gpg_output, &gpg_status);
921923
if (status && !gpg_output.len)
922924
goto out;
923925
ctx->signature.gpg_output = strbuf_detach(&gpg_output, NULL);
926+
ctx->signature.gpg_status = strbuf_detach(&gpg_status, NULL);
924927
parse_signature_lines(ctx);
925928

926929
out:
930+
strbuf_release(&gpg_status);
927931
strbuf_release(&gpg_output);
928932
strbuf_release(&payload);
929933
strbuf_release(&signature);

0 commit comments

Comments
 (0)