Skip to content

Commit 662009b

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 76b93cf commit 662009b

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
@@ -1942,6 +1942,11 @@ static char *get_extended_user_info(enum EXTENDED_NAME_FORMAT type)
19421942
return NULL;
19431943
}
19441944

1945+
char *mingw_query_user_email(void)
1946+
{
1947+
return get_extended_user_info(NameUserPrincipal);
1948+
}
1949+
19451950
struct passwd *getpwuid(int uid)
19461951
{
19471952
static unsigned initialized;

compat/mingw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ int mingw_offset_1st_component(const char *path);
430430
#define PATH_SEP ';'
431431
extern const char *program_data_config(void);
432432
#define git_program_data_config program_data_config
433+
extern char *mingw_query_user_email(void);
434+
#define query_user_email mingw_query_user_email
433435
#ifndef __MINGW64_VERSION_MAJOR
434436
#define PRIuMAX "I64u"
435437
#define PRId64 "I64d"

git-compat-util.h

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

376+
#ifndef query_user_email
377+
#define query_user_email() NULL
378+
#endif
379+
376380
#if defined(__HP_cc) && (__HP_cc >= 61000)
377381
#define NORETURN __attribute__((noreturn))
378382
#define NORETURN_PTR

ident.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ const char *ident_default_email(void)
120120
strbuf_addstr(&git_default_email, email);
121121
committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
122122
author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
123-
} else
123+
} else if ((email = query_user_email()) && email[0])
124+
strbuf_addstr(&git_default_email, email);
125+
else
124126
copy_email(xgetpwuid_self(), &git_default_email);
125127
strbuf_trim(&git_default_email);
126128
}

0 commit comments

Comments
 (0)