@matheusbsbs / matheus-bagliano / commits / 46f74f007b
Fork 0

Prefer EMAIL to username@hostname.

The environment variable $EMAIL gives a better default of user's preferred e-mail address than the hardcoded "username@hostname", as it is understood by many existing programs. We still honor GIT_*_EMAIL environment variables and user.email configuration variable give them higher precedence, so that the user can override $EMAIL or "username@hostname", as they are likely to be more specific to the context of working on a particular project. Signed-off-by: Matt Kraai <kraai@ftbfs.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Matt Kraai committed Jul 5, 2007 at 17:29 UTC 46f74f007b86452c4b4135f5145f94eefc994ea2
1 file changed +12 -7
ident.c
+12 -7
@@ -83,11 +83,18 @@ static void setup_ident(void)
83 }
84
85 if (!git_default_email[0]) {
86 - if (!pw)
87 - pw = getpwuid(getuid());
88 - if (!pw)
89 - die("You don't exist. Go away!");
90 - copy_email(pw);
86 + const char *email = getenv("EMAIL");
87 +
88 + if (email && email[0])
89 + strlcpy(git_default_email, email,
90 + sizeof(git_default_email));
91 + else {
92 + if (!pw)
93 + pw = getpwuid(getuid());
94 + if (!pw)
95 + die("You don't exist. Go away!");
96 + copy_email(pw);
97 + }
98 }
99
100 /* And set the default date */
@@ -197,8 +204,6 @@ const char *fmt_ident(const char *name, const char *email,
204 name = git_default_name;
205 if (!email)
206 email = git_default_email;
200 - if (!email)
201 - email = getenv("EMAIL");
207
208 if (!*name) {
209 struct passwd *pw;