Skip to content

Commit 2cd3bea

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 b57b444 commit 2cd3bea

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
@@ -1853,6 +1853,11 @@ static char *get_extended_user_info(enum EXTENDED_NAME_FORMAT type)
18531853
return NULL;
18541854
}
18551855

1856+
char *mingw_query_user_email(void)
1857+
{
1858+
return get_extended_user_info(NameUserPrincipal);
1859+
}
1860+
18561861
struct passwd *getpwuid(int uid)
18571862
{
18581863
static unsigned initialized;

compat/mingw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ int mingw_offset_1st_component(const char *path);
428428
#define PATH_SEP ';'
429429
extern const char *program_data_config(void);
430430
#define git_program_data_config program_data_config
431+
extern char *mingw_query_user_email(void);
432+
#define query_user_email mingw_query_user_email
431433
#if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800)
432434
#define PRIuMAX "I64u"
433435
#define PRId64 "I64d"

git-compat-util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ static inline char *git_find_last_dir_sep(const char *path)
379379
#define git_program_data_config() NULL
380380
#endif
381381

382+
#ifndef query_user_email
383+
#define query_user_email() NULL
384+
#endif
385+
382386
#if defined(__HP_cc) && (__HP_cc >= 61000)
383387
#define NORETURN __attribute__((noreturn))
384388
#define NORETURN_PTR

ident.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ const char *ident_default_email(void)
171171
strbuf_addstr(&git_default_email, email);
172172
committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
173173
author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
174-
} else
174+
} else if ((email = query_user_email()) && email[0])
175+
strbuf_addstr(&git_default_email, email);
176+
else
175177
copy_email(xgetpwuid_self(&default_email_is_bogus),
176178
&git_default_email, &default_email_is_bogus);
177179
strbuf_trim(&git_default_email);

0 commit comments

Comments
 (0)