git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/5] pretty: parse the gpg status lines rather than the output

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Feb 14, 2013, 16:04 UTC
Message-ID
<0e78892fa82498b67ef6cf9316f2dcc73d42c892.1360857415.git.git@drmicha.warpmail.net>
In-Reply-To
<CAJ9Ak2pLqUesOWKNtjwG7P_BW7-EqJP4Kaj0FF_+72Wn=oGoew@mail.gmail.com>

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>
---
 pretty.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/pretty.c b/pretty.c
index 2a1e174..973b912 100644
--- a/pretty.c
+++ b/pretty.c
@@ -759,6 +759,7 @@ struct format_commit_context {
 	unsigned commit_signature_parsed:1;
 	struct {
 		char *gpg_output;
+		char *gpg_status;
 		char good_bad;
 		char *signer;
 	} signature;
@@ -948,13 +949,13 @@ static struct {
 	char result;
 	const char *check;
 } signature_check[] = {
-	{ 'G', ": Good signature from " },
-	{ 'B', ": BAD signature from " },
+	{ 'G', "\n[GNUPG:] GOODSIG " },
+	{ 'B', "\n[GNUPG:] BADSIG " },
 };
 
 static void parse_signature_lines(struct format_commit_context *ctx)
 {
-	const char *buf = ctx->signature.gpg_output;
+	const char *buf = ctx->signature.gpg_status;
 	int i;
 
 	for (i = 0; i < ARRAY_SIZE(signature_check); i++) {
@@ -963,7 +964,7 @@ static void parse_signature_lines(struct format_commit_context *ctx)
 		if (!found)
 			continue;
 		ctx->signature.good_bad = signature_check[i].result;
-		found += strlen(signature_check[i].check);
+		found += strlen(signature_check[i].check)+17;
 		next = strchrnul(found, '\n');
 		ctx->signature.signer = xmemdupz(found, next - found);
 		break;
@@ -975,6 +976,7 @@ static void parse_commit_signature(struct format_commit_context *ctx)
 	struct strbuf payload = STRBUF_INIT;
 	struct strbuf signature = STRBUF_INIT;
 	struct strbuf gpg_output = STRBUF_INIT;
+	struct strbuf gpg_status = STRBUF_INIT;
 	int status;
 
 	ctx->commit_signature_parsed = 1;
@@ -984,13 +986,15 @@ static void parse_commit_signature(struct format_commit_context *ctx)
 		goto out;
 	status = verify_signed_buffer(payload.buf, payload.len,
 				      signature.buf, signature.len,
-				      &gpg_output, NULL);
+				      &gpg_output, &gpg_status);
 	if (status && !gpg_output.len)
 		goto out;
 	ctx->signature.gpg_output = strbuf_detach(&gpg_output, NULL);
+	ctx->signature.gpg_status = strbuf_detach(&gpg_status, NULL);
 	parse_signature_lines(ctx);
 
  out:
+	strbuf_release(&gpg_status);
 	strbuf_release(&gpg_output);
 	strbuf_release(&payload);
 	strbuf_release(&signature);
-- 
1.8.1.3.797.ge0260c7
Previous: Michael J GruberNext: Michael J Gruber
Message 10 of 14 in “[BUG] Veryfing signatures in git log fails when language is not english”
  1. XANiFeb 14, 2013
  2. Michael J GruberFeb 14, 2013
  3. Mariusz GronczewskiFeb 14, 2013
  4. 0/5 gpg_interface: use the statusMichael J Gruber, Feb 14, 2013
  5. 1/5 gpg-interface: check good signature in a reliable wayMichael J Gruber, Feb 14, 2013
  6. Junio C HamanoFeb 14, 2013
  7. Michael J GruberFeb 15, 2013
  8. 2/5 log-tree: rely upon the check in the gpg_interfaceMichael J Gruber, Feb 14, 2013
  9. 3/5 gpg_interface: allow to request status returnMichael J Gruber, Feb 14, 2013
  10. 4/5 pretty: parse the gpg status lines rather than the outputMichael J Gruber, Feb 14, 2013
  11. 5/5 pretty: make %GK output the signing key for signed commitsMichael J Gruber, Feb 14, 2013
  12. Junio C HamanoFeb 14, 2013
  13. Mariusz GronczewskiFeb 15, 2013
  14. Junio C HamanoFeb 15, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.