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 <git@drmicha.warpmail.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael J Gruber committed
Feb 14, 2013 at 17:04 UTC
4a868fd655a72c2663d9519363162db467baccb2
1 file changed
+9
-5
pretty.c
+9
-5
@@ -692,6 +692,7 @@ struct format_commit_context {
692
unsigned commit_signature_parsed:1;
693
struct {
694
char *gpg_output;
695
+ char *gpg_status;
696
char good_bad;
697
char *signer;
698
} signature;
@@ -881,13 +882,13 @@ static struct {
882
char result;
883
const char *check;
884
} signature_check[] = {
884
- { 'G', ": Good signature from " },
885
- { 'B', ": BAD signature from " },
885
+ { 'G', "\n[GNUPG:] GOODSIG " },
886
+ { 'B', "\n[GNUPG:] BADSIG " },
887
};
888
889
static void parse_signature_lines(struct format_commit_context *ctx)
890
{
890
- const char *buf = ctx->signature.gpg_output;
891
+ const char *buf = ctx->signature.gpg_status;
892
int i;
893
894
for (i = 0; i < ARRAY_SIZE(signature_check); i++) {
@@ -896,7 +897,7 @@ static void parse_signature_lines(struct format_commit_context *ctx)
897
if (!found)
898
continue;
899
ctx->signature.good_bad = signature_check[i].result;
899
- found += strlen(signature_check[i].check);
900
+ found += strlen(signature_check[i].check)+17;
901
next = strchrnul(found, '\n');
902
ctx->signature.signer = xmemdupz(found, next - found);
903
break;
@@ -908,6 +909,7 @@ static void parse_commit_signature(struct format_commit_context *ctx)
909
struct strbuf payload = STRBUF_INIT;
910
struct strbuf signature = STRBUF_INIT;
911
struct strbuf gpg_output = STRBUF_INIT;
912
+ struct strbuf gpg_status = STRBUF_INIT;
913
int status;
914
915
ctx->commit_signature_parsed = 1;
@@ -917,13 +919,15 @@ static void parse_commit_signature(struct format_commit_context *ctx)
919
goto out;
920
status = verify_signed_buffer(payload.buf, payload.len,
921
signature.buf, signature.len,
920
- &gpg_output, NULL);
922
+ &gpg_output, &gpg_status);
923
if (status && !gpg_output.len)
924
goto out;
925
ctx->signature.gpg_output = strbuf_detach(&gpg_output, NULL);
926
+ ctx->signature.gpg_status = strbuf_detach(&gpg_status, NULL);
927
parse_signature_lines(ctx);
928
929
out:
930
+ strbuf_release(&gpg_status);
931
strbuf_release(&gpg_output);
932
strbuf_release(&payload);
933
strbuf_release(&signature);