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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Oct 15, 2018 at 02:47 UTC
501afcb8b021611758bf07d0e18fa8ff7fbbed73
4 files changed
+14
compat/mingw.c
+5
@@ -1796,6 +1796,11 @@ static char *get_extended_user_info(enum EXTENDED_NAME_FORMAT type)
1796
return NULL;
1797
}
1798
1799
+char *mingw_query_user_email(void)
1800
+{
1801
+ return get_extended_user_info(NameUserPrincipal);
1802
+}
1803
+
1804
struct passwd *getpwuid(int uid)
1805
{
1806
static unsigned initialized;
compat/mingw.h
+2
@@ -424,6 +424,8 @@ static inline void convert_slashes(char *path)
424
int mingw_offset_1st_component(const char *path);
425
#define offset_1st_component mingw_offset_1st_component
426
#define PATH_SEP ';'
427
+extern char *mingw_query_user_email(void);
428
+#define query_user_email mingw_query_user_email
429
#if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800)
430
#define PRIuMAX "I64u"
431
#define PRId64 "I64d"
git-compat-util.h
+4
@@ -382,6 +382,10 @@ static inline char *git_find_last_dir_sep(const char *path)
382
#define find_last_dir_sep git_find_last_dir_sep
383
#endif
384
385
+#ifndef query_user_email
386
+#define query_user_email() NULL
387
+#endif
388
+
389
#if defined(__HP_cc) && (__HP_cc >= 61000)
390
#define NORETURN __attribute__((noreturn))
391
#define NORETURN_PTR
ident.c
+3
@@ -168,6 +168,9 @@ const char *ident_default_email(void)
168
strbuf_addstr(&git_default_email, email);
169
committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
170
author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
171
+ } else if ((email = query_user_email()) && email[0]) {
172
+ strbuf_addstr(&git_default_email, email);
173
+ free((char *)email);
174
} else
175
copy_email(xgetpwuid_self(&default_email_is_bogus),
176
&git_default_email, &default_email_is_bogus);