From 1fed2d9580c403c4780fe2ee3fb7468e83e990d5 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 13 Oct 2015 10:36:52 +0000 Subject: [PATCH] mingw: use domain information for default email When a user is registered in a Windows domain, it is really easy to obtain the email address. So let's do that. Suggested by Lutz Roeder. Signed-off-by: Johannes Schindelin --- compat/mingw.c | 5 +++++ compat/mingw.h | 2 ++ git-compat-util.h | 4 ++++ ident.c | 4 +++- 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/compat/mingw.c b/compat/mingw.c index 5004f96f47..c74660c092 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1953,6 +1953,11 @@ static char *get_extended_user_info(enum EXTENDED_NAME_FORMAT type) return NULL; } +char *mingw_query_user_email(void) +{ + return get_extended_user_info(NameUserPrincipal); +} + struct passwd *getpwuid(int uid) { static unsigned initialized; diff --git a/compat/mingw.h b/compat/mingw.h index 78fb308882..2359451235 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -434,6 +434,8 @@ int mingw_offset_1st_component(const char *path); #define PATH_SEP ';' extern const char *program_data_config(void); #define git_program_data_config program_data_config +extern char *mingw_query_user_email(void); +#define query_user_email mingw_query_user_email #if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800) #define PRIuMAX "I64u" #define PRId64 "I64d" diff --git a/git-compat-util.h b/git-compat-util.h index 216cf33736..8a8bc1103b 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -376,6 +376,10 @@ static inline char *git_find_last_dir_sep(const char *path) #define git_program_data_config() NULL #endif +#ifndef query_user_email +#define query_user_email() NULL +#endif + #if defined(__HP_cc) && (__HP_cc >= 61000) #define NORETURN __attribute__((noreturn)) #define NORETURN_PTR diff --git a/ident.c b/ident.c index d17b5bd341..2f3252113d 100644 --- a/ident.c +++ b/ident.c @@ -169,7 +169,9 @@ const char *ident_default_email(void) strbuf_addstr(&git_default_email, email); committer_ident_explicitly_given |= IDENT_MAIL_GIVEN; author_ident_explicitly_given |= IDENT_MAIL_GIVEN; - } else + } else if ((email = query_user_email()) && email[0]) + strbuf_addstr(&git_default_email, email); + else copy_email(xgetpwuid_self(&default_email_is_bogus), &git_default_email, &default_email_is_bogus); strbuf_trim(&git_default_email);