Skip to content

Commit ff5dad8

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 c6db784 commit ff5dad8

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

compat/mingw.c

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

1793+
char *mingw_query_user_email(void)
1794+
{
1795+
return get_extended_user_info(NameUserPrincipal);
1796+
}
1797+
17931798
struct passwd *getpwuid(int uid)
17941799
{
17951800
static unsigned initialized;

compat/mingw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,8 @@ static inline void convert_slashes(char *path)
414414
int mingw_offset_1st_component(const char *path);
415415
#define offset_1st_component mingw_offset_1st_component
416416
#define PATH_SEP ';'
417+
extern char *mingw_query_user_email(void);
418+
#define query_user_email mingw_query_user_email
417419
#if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800)
418420
#define PRIuMAX "I64u"
419421
#define PRId64 "I64d"

git-compat-util.h

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

373+
#ifndef query_user_email
374+
#define query_user_email() NULL
375+
#endif
376+
373377
#if defined(__HP_cc) && (__HP_cc >= 61000)
374378
#define NORETURN __attribute__((noreturn))
375379
#define NORETURN_PTR

ident.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ const char *ident_default_email(void)
169169
strbuf_addstr(&git_default_email, email);
170170
committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
171171
author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
172-
} else
172+
} else if ((email = query_user_email()) && email[0])
173+
strbuf_addstr(&git_default_email, email);
174+
else
173175
copy_email(xgetpwuid_self(&default_email_is_bogus),
174176
&git_default_email, &default_email_is_bogus);
175177
strbuf_trim(&git_default_email);

0 commit comments

Comments
 (0)