Skip to content

Commit 41966a7

Browse files
committed
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 <[email protected]>
1 parent dec010d commit 41966a7

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

compat/mingw.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,6 +1826,11 @@ static char *get_extended_user_info(enum EXTENDED_NAME_FORMAT type)
18261826
return NULL;
18271827
}
18281828

1829+
char *mingw_query_user_email(void)
1830+
{
1831+
return get_extended_user_info(NameUserPrincipal);
1832+
}
1833+
18291834
struct passwd *getpwuid(int uid)
18301835
{
18311836
static unsigned initialized;

compat/mingw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ static inline void convert_slashes(char *path)
424424
int mingw_offset_1st_component(const char *path);
425425
#define offset_1st_component mingw_offset_1st_component
426426
#define PATH_SEP ';'
427+
extern char *mingw_query_user_email(void);
428+
#define query_user_email mingw_query_user_email
427429
#if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800)
428430
#define PRIuMAX "I64u"
429431
#define PRId64 "I64d"

git-compat-util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,10 @@ static inline char *git_find_last_dir_sep(const char *path)
382382
#define find_last_dir_sep git_find_last_dir_sep
383383
#endif
384384

385+
#ifndef query_user_email
386+
#define query_user_email() NULL
387+
#endif
388+
385389
#if defined(__HP_cc) && (__HP_cc >= 61000)
386390
#define NORETURN __attribute__((noreturn))
387391
#define NORETURN_PTR

ident.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ const char *ident_default_email(void)
168168
strbuf_addstr(&git_default_email, email);
169169
committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
170170
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);
171174
} else
172175
copy_email(xgetpwuid_self(&default_email_is_bogus),
173176
&git_default_email, &default_email_is_bogus);

0 commit comments

Comments
 (0)