Merge branch 'js/mingw-default-ident'
The logic to select the default user name and e-mail on Windows has been improved. * js/mingw-default-ident: mingw: use domain information for default email getpwuid(mingw): provide a better default for the user name getpwuid(mingw): initialize the structure only once
This commit is contained in:
commit
16ce0b92bd
@ -5,6 +5,7 @@
|
|||||||
#include "../strbuf.h"
|
#include "../strbuf.h"
|
||||||
#include "../run-command.h"
|
#include "../run-command.h"
|
||||||
#include "../cache.h"
|
#include "../cache.h"
|
||||||
|
#include "win32/lazyload.h"
|
||||||
|
|
||||||
#define HCAST(type, handle) ((type)(intptr_t)handle)
|
#define HCAST(type, handle) ((type)(intptr_t)handle)
|
||||||
|
|
||||||
@ -1798,18 +1799,63 @@ int mingw_getpagesize(void)
|
|||||||
return si.dwAllocationGranularity;
|
return si.dwAllocationGranularity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* See https://msdn.microsoft.com/en-us/library/windows/desktop/ms724435.aspx */
|
||||||
|
enum EXTENDED_NAME_FORMAT {
|
||||||
|
NameDisplay = 3,
|
||||||
|
NameUserPrincipal = 8
|
||||||
|
};
|
||||||
|
|
||||||
|
static char *get_extended_user_info(enum EXTENDED_NAME_FORMAT type)
|
||||||
|
{
|
||||||
|
DECLARE_PROC_ADDR(secur32.dll, BOOL, GetUserNameExW,
|
||||||
|
enum EXTENDED_NAME_FORMAT, LPCWSTR, PULONG);
|
||||||
|
static wchar_t wbuffer[1024];
|
||||||
|
DWORD len;
|
||||||
|
|
||||||
|
if (!INIT_PROC_ADDR(GetUserNameExW))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
len = ARRAY_SIZE(wbuffer);
|
||||||
|
if (GetUserNameExW(type, wbuffer, &len)) {
|
||||||
|
char *converted = xmalloc((len *= 3));
|
||||||
|
if (xwcstoutf(converted, wbuffer, len) >= 0)
|
||||||
|
return converted;
|
||||||
|
free(converted);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *mingw_query_user_email(void)
|
||||||
|
{
|
||||||
|
return get_extended_user_info(NameUserPrincipal);
|
||||||
|
}
|
||||||
|
|
||||||
struct passwd *getpwuid(int uid)
|
struct passwd *getpwuid(int uid)
|
||||||
{
|
{
|
||||||
|
static unsigned initialized;
|
||||||
static char user_name[100];
|
static char user_name[100];
|
||||||
static struct passwd p;
|
static struct passwd *p;
|
||||||
|
DWORD len;
|
||||||
|
|
||||||
DWORD len = sizeof(user_name);
|
if (initialized)
|
||||||
if (!GetUserName(user_name, &len))
|
return p;
|
||||||
|
|
||||||
|
len = sizeof(user_name);
|
||||||
|
if (!GetUserName(user_name, &len)) {
|
||||||
|
initialized = 1;
|
||||||
return NULL;
|
return NULL;
|
||||||
p.pw_name = user_name;
|
}
|
||||||
p.pw_gecos = "unknown";
|
|
||||||
p.pw_dir = NULL;
|
p = xmalloc(sizeof(*p));
|
||||||
return &p;
|
p->pw_name = user_name;
|
||||||
|
p->pw_gecos = get_extended_user_info(NameDisplay);
|
||||||
|
if (!p->pw_gecos)
|
||||||
|
p->pw_gecos = "unknown";
|
||||||
|
p->pw_dir = NULL;
|
||||||
|
|
||||||
|
initialized = 1;
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HANDLE timer_event;
|
static HANDLE timer_event;
|
||||||
|
@ -424,6 +424,8 @@ static inline void convert_slashes(char *path)
|
|||||||
int mingw_offset_1st_component(const char *path);
|
int mingw_offset_1st_component(const char *path);
|
||||||
#define offset_1st_component mingw_offset_1st_component
|
#define offset_1st_component mingw_offset_1st_component
|
||||||
#define PATH_SEP ';'
|
#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)
|
#if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800)
|
||||||
#define PRIuMAX "I64u"
|
#define PRIuMAX "I64u"
|
||||||
#define PRId64 "I64d"
|
#define PRId64 "I64d"
|
||||||
|
@ -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
|
#define find_last_dir_sep git_find_last_dir_sep
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef query_user_email
|
||||||
|
#define query_user_email() NULL
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__HP_cc) && (__HP_cc >= 61000)
|
#if defined(__HP_cc) && (__HP_cc >= 61000)
|
||||||
#define NORETURN __attribute__((noreturn))
|
#define NORETURN __attribute__((noreturn))
|
||||||
#define NORETURN_PTR
|
#define NORETURN_PTR
|
||||||
|
3
ident.c
3
ident.c
@ -168,6 +168,9 @@ const char *ident_default_email(void)
|
|||||||
strbuf_addstr(&git_default_email, email);
|
strbuf_addstr(&git_default_email, email);
|
||||||
committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
|
committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
|
||||||
author_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
|
} else
|
||||||
copy_email(xgetpwuid_self(&default_email_is_bogus),
|
copy_email(xgetpwuid_self(&default_email_is_bogus),
|
||||||
&git_default_email, &default_email_is_bogus);
|
&git_default_email, &default_email_is_bogus);
|
||||||
|
Loading…
Reference in New Issue
Block a user