mingw: use domain information for default email
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Mon, 15 Oct 2018 09:47:08 +0000 (02:47 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 16 Oct 2018 03:59:57 +0000 (12:59 +0900)
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>
compat/mingw.c
compat/mingw.h
git-compat-util.h
ident.c
index 90554712932f19a09b162ed14b7089944e63a8ea..45c8046c7cc34ff53ed506af303a1874ca35d67b 100644 (file)
@@ -1796,6 +1796,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;
index 571019d0bddceaf3245e15dbcc4ebfb70a501d17..f31dcff2be1d60ce4f5ae46089d59255f1bc4dff 100644 (file)
@@ -424,6 +424,8 @@ static inline void convert_slashes(char *path)
 int mingw_offset_1st_component(const char *path);
 #define offset_1st_component mingw_offset_1st_component
 #define PATH_SEP ';'
+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"
index 5f2e90932f9990419d75d803d9552acf2f14adef..71779cb0aeb6f34de974cc1f7b81d13ce137b941 100644 (file)
@@ -382,6 +382,10 @@ static inline char *git_find_last_dir_sep(const char *path)
 #define find_last_dir_sep git_find_last_dir_sep
 #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 327abe557f5a66546665664511d3e71b7f0929e7..33bcf40644cdf23434a7cb622b6be71bb7cd867c 100644 (file)
--- a/ident.c
+++ b/ident.c
@@ -168,6 +168,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 if ((email = query_user_email()) && email[0]) {
+                       strbuf_addstr(&git_default_email, email);
+                       free((char *)email);
                } else
                        copy_email(xgetpwuid_self(&default_email_is_bogus),
                                   &git_default_email, &default_email_is_bogus);