On Tue, Oct 30, 2007 at 08:00:19PM +0000, Ian Jackson wrote:
> See policy 11.6 and search for /etc/mailname.  Observe in the
> transcript below that git chose the email address
> [EMAIL PROTECTED]' rather than
> [EMAIL PROTECTED]' as it should have done.

Yes, here's a patch.  Regards, Gerrit.


>From 94b1bb543fbfcb62deb8736c5478f349c47763d2 Mon Sep 17 00:00:00 2001
From: Gerrit Pape <[EMAIL PROTECTED]>
Date: Fri, 2 Nov 2007 20:11:19 +0000
Subject: [PATCH] bug#448655: check /etc/mailname if author email is unknown

Before falling back to gethostname(), check /etc/mailname on Debian if
GIT_AUTHOR_EMAIL is not set in the environment or through config files;
only fallback if /etc/mailname cannot be opened or read.
---
 ident.c |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/ident.c b/ident.c
index 9b2a852..2a58fd9 100644
--- a/ident.c
+++ b/ident.c
@@ -45,6 +45,8 @@ static void copy_gecos(const struct passwd *w, char *name, 
size_t sz)
 
 static void copy_email(const struct passwd *pw)
 {
+       FILE *mailname;
+
        /*
         * Make up a fake email address
         * (name + '@' + hostname [+ '.' + domainname])
@@ -54,7 +56,23 @@ static void copy_email(const struct passwd *pw)
                die("Your sysadmin must hate you!");
        memcpy(git_default_email, pw->pw_name, len);
        git_default_email[len++] = '@';
-       gethostname(git_default_email + len, sizeof(git_default_email) - len);
+
+       /* On Debian check /etc/mailname before using gethostname */
+       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;
+       }
+       else {
+               warning("unable to read /etc/mailname: %s\n", strerror(errno));
+               gethostname(git_default_email + len,
+                           sizeof(git_default_email) - len);
+       }
+       if (mailname)
+               fclose(mailname);
+
        if (!strchr(git_default_email+len, '.')) {
                struct hostent *he = gethostbyname(git_default_email + len);
                char *domainname;
-- 
1.5.3.5




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

Reply via email to