Package: git
Version: 1:1.7.2.3-2.2
Tags: patch

If the hostname in /etc/mailname does not contain a '.', the
user.email configuration is unset, and /etc/nsswitch.conf contains

        hosts:  files dns

rather than

        hosts:  files

then scripts making a lot of commits (e.g., rebase, am, the test
suite) take a long time for me.  By using strace I tracked it down
to communication with the DNS cache, in the following code block:

        if (!strchr(git_default_email+len, '.')) {
                struct hostent *he = gethostbyname(git_default_email + len);
 [...]

IIUC then the intent of that code is to change a non-fqdn from
gethostname to an fqdn.  I would prefer to skip it when the hostname
comes from /etc/mailname.

In other words, how about the following, for squashing in with the
patch "bug#448655: check /etc/mailname if author email is unknown"?

-- 8< --
Subject: ident: do not resolve hostname from /etc/mailname

The mailname in /etc/mailname is meant to be used as is, not
transformed into an fqdn by a host lookup and reverse lookup.

Noticed because when the DNS cache is faraway such lookups can be very
slow.

While at it, clarify by removing some code.  s[strlen(s)] == '\n' is
by definition always false, and fgets takes care of removing the
terminating newline on its own already.

Signed-off-by: Jonathan Nieder <[email protected]>
---
 ident.c |   17 +++++++----------
 1 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/ident.c b/ident.c
index 82770ed..da1fb6e 100644
--- a/ident.c
+++ b/ident.c
@@ -61,20 +61,17 @@ static void copy_email(const struct passwd *pw)
        mailname = fopen("/etc/mailname", "r");
        if (mailname && fgets(git_default_email + len,
                              sizeof(git_default_email) - len, mailname)) {
-               int l = strlen(git_default_email + len);
-               if (git_default_email[len+l] == '\n')
-                       git_default_email[len+l] = 0;
+               fclose(mailname);
+               return; /* success. */
        }
-       else {
-               if (errno != ENOENT)
-                       warning("unable to read /etc/mailname: %s\n",
-                                strerror(errno));
-               gethostname(git_default_email + len,
-                           sizeof(git_default_email) - len);
-       }
+
+       if (errno != ENOENT)
+               warning("unable to read /etc/mailname: %s\n",
+                        strerror(errno));
        if (mailname)
                fclose(mailname);
 
+       gethostname(git_default_email + len, sizeof(git_default_email) - len);
        if (!strchr(git_default_email+len, '.')) {
                struct hostent *he = gethostbyname(git_default_email + len);
                char *domainname;
-- 
1.7.4.rc3




-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to