From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Taylor Braun-Jones <taylor@braun-jones.org>,
Duy Nguyen <pclouds@gmail.com>,
Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH 2/3] ident: keep a flag for bogus default_email
Date: Thu, 10 Dec 2015 17:54:16 -0500 [thread overview]
Message-ID: <20151210225416.GA1648@sigill.intra.peff.net> (raw)
In-Reply-To: <20151210213535.GB8374@sigill.intra.peff.net>
On Thu, Dec 10, 2015 at 04:35:35PM -0500, Jeff King wrote:
> @@ -82,7 +83,7 @@ static int add_mailname_host(struct strbuf *buf)
> return 0;
> }
>
> -static void add_domainname(struct strbuf *out)
> +static void add_domainname(struct strbuf *out, int *is_bogus)
> {
> char buf[1024];
> struct hostent *he;
> @@ -90,17 +91,21 @@ static void add_domainname(struct strbuf *out)
> if (gethostname(buf, sizeof(buf))) {
> warning("cannot get host name: %s", strerror(errno));
> strbuf_addstr(out, "(none)");
> + *is_bogus = 1;
> return;
> }
> if (strchr(buf, '.'))
> strbuf_addstr(out, buf);
> else if ((he = gethostbyname(buf)) && strchr(he->h_name, '.'))
> strbuf_addstr(out, he->h_name);
> - else
> + else {
> strbuf_addf(out, "%s.(none)", buf);
> + *is_bogus = 1;
> + }
This hunk has some minor conflicts with ep/ident-with-getaddrinfo, which
graduated to master in the tips you just pushed out.
Here's a rebased version on top of the current master (the other patches
can remain the same).
-- >8 --
Subject: [PATCH] ident: keep a flag for bogus default_email
If we have to deduce the user's email address and can't come
up with something plausible for the hostname, we simply
write "(none)" or ".(none)" in the hostname.
Later, our strict-check is forced to use strstr to look for
this magic string. This is probably not a problem in
practice, but it's rather ugly. Let's keep an extra flag
that tells us the email is bogus, and check that instead.
We could get away with simply setting the global in
add_domainname(); it only gets called to write into
git_default_email. However, let's make the code a little
more obvious to future readers by actually passing a pointer
to our "bogus" flag down the call-chain.
Signed-off-by: Jeff King <peff@peff.net>
---
ident.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/ident.c b/ident.c
index 140dd63..fde3244 100644
--- a/ident.c
+++ b/ident.c
@@ -10,6 +10,7 @@
static struct strbuf git_default_name = STRBUF_INIT;
static struct strbuf git_default_email = STRBUF_INIT;
static struct strbuf git_default_date = STRBUF_INIT;
+static int default_email_is_bogus;
#define IDENT_NAME_GIVEN 01
#define IDENT_MAIL_GIVEN 02
@@ -108,22 +109,26 @@ static int canonical_name(const char *host, struct strbuf *out)
return status;
}
-static void add_domainname(struct strbuf *out)
+static void add_domainname(struct strbuf *out, int *is_bogus)
{
char buf[1024];
if (gethostname(buf, sizeof(buf))) {
warning("cannot get host name: %s", strerror(errno));
strbuf_addstr(out, "(none)");
+ *is_bogus = 1;
return;
}
if (strchr(buf, '.'))
strbuf_addstr(out, buf);
- else if (canonical_name(buf, out) < 0)
+ else if (canonical_name(buf, out) < 0) {
strbuf_addf(out, "%s.(none)", buf);
+ *is_bogus = 1;
+ }
}
-static void copy_email(const struct passwd *pw, struct strbuf *email)
+static void copy_email(const struct passwd *pw, struct strbuf *email,
+ int *is_bogus)
{
/*
* Make up a fake email address
@@ -134,7 +139,7 @@ static void copy_email(const struct passwd *pw, struct strbuf *email)
if (!add_mailname_host(email))
return; /* read from "/etc/mailname" (Debian) */
- add_domainname(email);
+ add_domainname(email, is_bogus);
}
const char *ident_default_name(void)
@@ -156,7 +161,8 @@ const char *ident_default_email(void)
committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
} else
- copy_email(xgetpwuid_self(), &git_default_email);
+ copy_email(xgetpwuid_self(), &git_default_email,
+ &default_email_is_bogus);
strbuf_trim(&git_default_email);
}
return git_default_email.buf;
@@ -348,8 +354,7 @@ const char *fmt_ident(const char *name, const char *email,
name = pw->pw_name;
}
- if (strict && email == git_default_email.buf &&
- strstr(email, "(none)")) {
+ if (strict && email == git_default_email.buf && default_email_is_bogus) {
fputs(env_hint, stderr);
die("unable to auto-detect email address (got '%s')", email);
}
--
2.6.3.636.g1460207
next prev parent reply other threads:[~2015-12-10 22:54 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-02 20:10 git-clone fails when current user is not in /etc/passwd Taylor Braun-Jones
2015-12-09 15:23 ` Taylor Braun-Jones
2015-12-09 16:08 ` Duy Nguyen
2015-12-09 18:24 ` Duy Nguyen
2015-12-09 22:35 ` Taylor Braun-Jones
2015-12-10 18:33 ` Taylor Braun-Jones
2015-12-10 18:34 ` Jeff King
2015-12-10 19:57 ` Junio C Hamano
2015-12-10 20:40 ` Jeff King
2015-12-10 21:32 ` [PATCH 0/3] " Jeff King
2015-12-10 21:33 ` [PATCH 1/3] ident: make xgetpwuid_self() a static local helper Jeff King
2015-12-10 23:39 ` Junio C Hamano
2015-12-10 21:35 ` [PATCH 2/3] ident: keep a flag for bogus default_email Jeff King
2015-12-10 22:54 ` Jeff King [this message]
2015-12-10 21:41 ` [PATCH 3/3] ident: loosen getpwuid error in non-strict mode Jeff King
2015-12-14 15:07 ` Jeff King
2015-12-10 23:44 ` [PATCH 0/3] git-clone fails when current user is not in /etc/passwd Junio C Hamano
2015-12-11 2:20 ` Taylor Braun-Jones
2015-12-10 18:43 ` Junio C Hamano
2015-12-10 18:52 ` Taylor Braun-Jones
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=20151210225416.GA1648@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pclouds@gmail.com \
--cc=taylor@braun-jones.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).