git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Grant Olson <kgo@grant-olson.net>
To: git@vger.kernel.org
Subject: PATCH:  Less fragile lookup of gpg key
Date: Sat, 01 May 2010 11:16:59 -0400	[thread overview]
Message-ID: <4BDC45EB.8090305@grant-olson.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 2070 bytes --]

When signing a tag, git will attempt to lookup your gpg key if you don't
provide the key id.  Right now, it's a little fragile.  My gpg key uid
is "Grant T. Olson (Personal Email) <kgo@grant-olson.net>".  My git user
info is "Grant T. Olson <kgo@grant-olson.net>".  Things don't match
because git doesn't have the comment.

However, if I lookup just by email, things work perfectly.

I think doing this would make life much easier for new users, and in the
case that someone has an OpenPGP key without email (e.g. Ubuntu Master
Signing Key) we can safely assume they're an expert and will either add
the key id to their configuration or use -u instead of -s.

Here's a patch that will try to lookup the user by email only if no
signing key is provided.  If there is no email, it will still fall back
to the default generated by git.

From d0fcf1340495045813758f910e8f4d745e28546b Mon Sep 17 00:00:00 2001
From: Grant Olson <kgo@grant-olson.net>
Date: Sat, 1 May 2010 11:02:18 -0400
Subject: [PATCH] Lookup gpg key by email

---
 builtin/tag.c |    2 +-
 ident.c       |    9 +++++++++
 2 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/builtin/tag.c b/builtin/tag.c
index d311491..4eb3cc5 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -165,7 +165,7 @@ static int do_sign(struct strbuf *buffer)
 	int i, j;

 	if (!*signingkey) {
-		if (strlcpy(signingkey, git_committer_info(IDENT_ERROR_ON_NO_NAME),
+		if (strlcpy(signingkey, git_committer_email(),
 				sizeof(signingkey)) > sizeof(signingkey) - 1)
 			return error("committer info too long.");
 		bracket = strchr(signingkey, '>');
diff --git a/ident.c b/ident.c
index 9e24388..0e8b78a 100644
--- a/ident.c
+++ b/ident.c
@@ -260,6 +260,15 @@ const char *git_committer_info(int flag)
 			 flag);
 }

+const char *git_committer_email(void)
+{
+	const char *email = getenv("GIT_COMMITTER_EMAIL");
+	if(!email)
+		email = git_default_email;
+
+	return email;
+}
+
 int user_ident_sufficiently_given(void)
 {
 #ifndef WINDOWS
-- 
1.7.0.4



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 554 bytes --]

             reply	other threads:[~2010-05-01 15:17 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-01 15:16 Grant Olson [this message]
2010-05-01 16:26 ` PATCH: Less fragile lookup of gpg key A Large Angry SCM
2010-05-01 17:18   ` Junio C Hamano
2010-05-01 17:25     ` Grant Olson
2010-05-01 19:54       ` Junio C Hamano
2010-05-02 23:39         ` Grant Olson
2010-05-03  0:59         ` Greg A. Woods
2010-05-03  2:09           ` Grant Olson
2010-05-03 11:16           ` Theodore Tso
2010-05-03 22:19             ` Greg A. Woods
2010-05-04  2:19               ` tytso
2010-05-04  2:23                 ` Grant Olson
2010-05-04  6:07                 ` Andreas Ericsson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4BDC45EB.8090305@grant-olson.net \
    --to=kgo@grant-olson.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).