From: Jonathan Nieder <jrnieder@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Johannes Sixt <j.sixt@viscovery.net>,
git@vger.kernel.org, Matt Kraai <kraai@ftbfs.org>,
Gerrit Pape <pape@smarden.org>,
Ian Jackson <ijackson@chiark.greenend.org.uk>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH/RFC jn/ident-from-etc-mailname] ident: do not retrieve default ident when unnecessary
Date: Thu, 6 Oct 2011 12:17:19 -0500 [thread overview]
Message-ID: <20111006171719.GB6946@elie> (raw)
In-Reply-To: <7vty7pga7y.fsf@alter.siamese.dyndns.org>
Avoid a getpwuid() call (which contacts the network if the password
database is not local), read of /etc/mailname, gethostname() call, and
reverse DNS lookup if the user has already chosen a name and email
through configuration, the environment, or the command line.
This should slightly speed up commands like "git commit". More
importantly, it improves error reporting when computation of the
default ident string does not go smoothly. For example, after
detecting a problem (e.g., "warning: cannot open /etc/mailname:
Permission denied") in retrieving the default committer identity:
touch /etc/mailname; # as root
chmod -r /etc/mailname; # as root
git commit -m 'test commit'
you can squelch the warning while waiting for your sysadmin to fix the
permissions problem.
echo '[user] email = me@example.com' >>~/.gitconfig
Inspired-by: Johannes Sixt <j6t@kdgb.org>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Junio C Hamano wrote:
> --- a/ident.c
> +++ b/ident.c
> @@ -239,6 +239,10 @@ const char *fmt_ident(const char *name, const char *email,
> int warn_on_no_name = (flag & IDENT_WARN_ON_NO_NAME);
> int name_addr_only = (flag & IDENT_NO_DATE);
>
> + if (name && !git_default_name[0])
> + strcpy(git_default_name, name);
> + if (email && !git_default_email[0])
> + strcpy(git_default_email, email);
That poisons the "git_default_foo" variables for the next fmt_ident
call. But something similar should work.
ident.c | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/ident.c b/ident.c
index edb43144..f619619b 100644
--- a/ident.c
+++ b/ident.c
@@ -117,19 +117,21 @@ static void copy_email(const struct passwd *pw)
sizeof(git_default_email) - len);
}
-static void setup_ident(void)
+static void setup_ident(const char **name, const char **emailp)
{
struct passwd *pw = NULL;
/* Get the name ("gecos") */
- if (!git_default_name[0]) {
+ if (!*name && !git_default_name[0]) {
pw = getpwuid(getuid());
if (!pw)
die("You don't exist. Go away!");
copy_gecos(pw, git_default_name, sizeof(git_default_name));
}
+ if (!*name)
+ *name = git_default_name;
- if (!git_default_email[0]) {
+ if (!*emailp && !git_default_email[0]) {
const char *email = getenv("EMAIL");
if (email && email[0]) {
@@ -144,6 +146,8 @@ static void setup_ident(void)
copy_email(pw);
}
}
+ if (!*emailp)
+ *emailp = git_default_email;
/* And set the default date */
if (!git_default_date[0])
@@ -239,11 +243,7 @@ const char *fmt_ident(const char *name, const char *email,
int warn_on_no_name = (flag & IDENT_WARN_ON_NO_NAME);
int name_addr_only = (flag & IDENT_NO_DATE);
- setup_ident();
- if (!name)
- name = git_default_name;
- if (!email)
- email = git_default_email;
+ setup_ident(&name, &email);
if (!*name) {
struct passwd *pw;
--
1.7.7.rc1
next prev parent reply other threads:[~2011-10-06 17:17 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-03 4:57 [PATCH/RFC] ident: check /etc/mailname if email is unknown Jonathan Nieder
2011-10-03 5:30 ` Junio C Hamano
2011-10-03 6:16 ` [PATCH v2] " Jonathan Nieder
2011-10-03 7:09 ` Johannes Sixt
2011-10-03 7:44 ` Jonathan Nieder
2011-10-03 19:13 ` Junio C Hamano
2011-10-06 17:17 ` Jonathan Nieder [this message]
2011-10-06 18:19 ` [PATCH/RFC jn/ident-from-etc-mailname] ident: do not retrieve default ident when unnecessary Junio C Hamano
2011-10-06 18:48 ` Jonathan Nieder
2011-10-03 11:32 ` [PATCH v2] ident: check /etc/mailname if email is unknown Ian Jackson
2011-10-03 19:15 ` Junio C Hamano
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=20111006171719.GB6946@elie \
--to=jrnieder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=ijackson@chiark.greenend.org.uk \
--cc=j.sixt@viscovery.net \
--cc=kraai@ftbfs.org \
--cc=pape@smarden.org \
--cc=torvalds@linux-foundation.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).