Skip to content

Commit 42b1fc6

Browse files
author
nalla
committed
Merge pull request #26 from dscho/msys2
Fixes required to build Git for Windows with MSys2
2 parents f96acd3 + 66ee249 commit 42b1fc6

17 files changed

+145
-22
lines changed

compat/mingw.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,16 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
10661066
free(quoted);
10671067
}
10681068

1069+
if (getenv("GIT_STRACE_COMMANDS")) {
1070+
char **path = get_path_split();
1071+
cmd = path_lookup("strace.exe", path, 1);
1072+
if (!cmd)
1073+
return error("strace not found!");
1074+
if (xutftowcs_path(wcmd, cmd) < 0)
1075+
return -1;
1076+
strbuf_insert(&args, 0, "strace ", 7);
1077+
}
1078+
10691079
wargs = xmalloc((2 * args.len + 1) * sizeof(wchar_t));
10701080
xutftowcs(wargs, args.buf, 2 * args.len + 1);
10711081
strbuf_release(&args);
@@ -1639,7 +1649,12 @@ int mingw_rename(const char *pold, const char *pnew)
16391649
if (gle == ERROR_ACCESS_DENIED &&
16401650
(attrs = GetFileAttributesW(wpnew)) != INVALID_FILE_ATTRIBUTES) {
16411651
if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
1642-
errno = EISDIR;
1652+
DWORD attrsold = GetFileAttributesW(wpold);
1653+
if (attrsold == INVALID_FILE_ATTRIBUTES ||
1654+
!(attrsold & FILE_ATTRIBUTE_DIRECTORY))
1655+
errno = EISDIR;
1656+
else if (!_wrmdir(wpnew))
1657+
goto repeat;
16431658
return -1;
16441659
}
16451660
if ((attrs & FILE_ATTRIBUTE_READONLY) &&
@@ -2148,8 +2163,26 @@ void mingw_startup()
21482163
__argv[0] = wcstoutfdup_startup(buffer, _wpgmptr, maxlen);
21492164
for (i = 1; i < argc; i++)
21502165
__argv[i] = wcstoutfdup_startup(buffer, wargv[i], maxlen);
2151-
for (i = 0; wenv[i]; i++)
2166+
for (i = 0; wenv[i]; i++) {
21522167
environ[i] = wcstoutfdup_startup(buffer, wenv[i], maxlen);
2168+
if (!strncasecmp(environ[i], "MSYS2_TZ=", 9)) {
2169+
char *to_free = environ[i];
2170+
environ[i] = xstrdup(to_free + 6);
2171+
free(to_free);
2172+
}
2173+
if (!strncasecmp(environ[i], "TMP=", 4)) {
2174+
/*
2175+
* Convert all dir separators to forward slashes,
2176+
* to help shell commands called from the Git
2177+
* executable (by not mistaking the dir separators
2178+
* for escape characters).
2179+
*/
2180+
char *p;
2181+
for (p = environ[i]; *p; p++)
2182+
if (*p == '\\')
2183+
*p = '/';
2184+
}
2185+
}
21532186
environ[i] = NULL;
21542187
free(buffer);
21552188

compat/mingw.h

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
1+
#include <stdint.h>
2+
#include <wchar.h>
3+
#include <sys/types.h>
4+
#ifndef _POSIX
5+
typedef _sigset_t sigset_t;
6+
#endif
17
#include <winsock2.h>
28
#include <ws2tcpip.h>
3-
49
/*
510
* things that are not available in header files
611
*/
712

8-
typedef int pid_t;
913
typedef int uid_t;
1014
typedef int socklen_t;
11-
#define hstrerror strerror
1215

1316
#define S_IFLNK 0120000 /* Symbolic link */
1417
#define S_ISLNK(x) (((x) & S_IFMT) == S_IFLNK)
1518
#define S_ISSOCK(x) 0
1619

20+
#ifndef S_IRWXG
1721
#define S_IRGRP 0
1822
#define S_IWGRP 0
1923
#define S_IXGRP 0
2024
#define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
25+
#endif
26+
#ifndef S_IRWXO
2127
#define S_IROTH 0
2228
#define S_IWOTH 0
2329
#define S_IXOTH 0
2430
#define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
31+
#endif
2532

2633
#define S_ISUID 0004000
2734
#define S_ISGID 0002000
@@ -92,8 +99,10 @@ static inline int symlink(const char *oldpath, const char *newpath)
9299
{ errno = ENOSYS; return -1; }
93100
static inline int fchmod(int fildes, mode_t mode)
94101
{ errno = ENOSYS; return -1; }
102+
#ifndef __MINGW64_VERSION_MAJOR
95103
static inline pid_t fork(void)
96104
{ errno = ENOSYS; return -1; }
105+
#endif
97106
static inline unsigned int alarm(unsigned int seconds)
98107
{ return 0; }
99108
static inline int fsync(int fd)
@@ -164,8 +173,10 @@ int pipe(int filedes[2]);
164173
unsigned int sleep (unsigned int seconds);
165174
int mkstemp(char *template);
166175
int gettimeofday(struct timeval *tv, void *tz);
176+
#ifndef __MINGW64_VERSION_MAJOR
167177
struct tm *gmtime_r(const time_t *timep, struct tm *result);
168178
struct tm *localtime_r(const time_t *timep, struct tm *result);
179+
#endif
169180
int getpagesize(void); /* defined in MinGW's libgcc.a */
170181
struct passwd *getpwuid(uid_t uid);
171182
int setitimer(int type, struct itimerval *in, struct itimerval *out);
@@ -213,6 +224,10 @@ char *mingw_mktemp(char *template);
213224
char *mingw_getcwd(char *pointer, int len);
214225
#define getcwd mingw_getcwd
215226

227+
#ifdef NO_UNSETENV
228+
#error "NO_UNSETENV is incompatible with the MinGW startup code!"
229+
#endif
230+
216231
char *mingw_getenv(const char *name);
217232
#define getenv mingw_getenv
218233
int mingw_putenv(const char *namevalue);
@@ -285,8 +300,10 @@ static inline int getrlimit(int resource, struct rlimit *rlp)
285300
/*
286301
* Use mingw specific stat()/lstat()/fstat() implementations on Windows.
287302
*/
303+
#ifndef __MINGW64_VERSION_MAJOR
288304
#define off_t off64_t
289305
#define lseek _lseeki64
306+
#endif
290307

291308
/* use struct stat with 64 bit st_size */
292309
#ifdef stat
@@ -359,8 +376,12 @@ static inline char *mingw_find_last_dir_sep(const char *path)
359376
int mingw_offset_1st_component(const char *path);
360377
#define offset_1st_component mingw_offset_1st_component
361378
#define PATH_SEP ';'
379+
#ifndef __MINGW64_VERSION_MAJOR
362380
#define PRIuMAX "I64u"
363381
#define PRId64 "I64d"
382+
#else
383+
#include <inttypes.h>
384+
#endif
364385

365386
void mingw_open_html(const char *path);
366387
#define open_html mingw_open_html

compat/win32/pthread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ extern pthread_t pthread_self(void);
7777

7878
static inline int pthread_exit(void *ret)
7979
{
80-
ExitThread((DWORD)ret);
80+
ExitThread((DWORD)(size_t)ret);
8181
}
8282

8383
typedef DWORD pthread_key_t;

compat/winansi.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ static HANDLE hthread, hread, hwrite;
2323
static HANDLE hconsole1, hconsole2;
2424

2525
#ifdef __MINGW32__
26+
#if !defined(__MINGW64_VERSION_MAJOR) || __MINGW64_VERSION_MAJOR < 5
2627
typedef struct _CONSOLE_FONT_INFOEX {
2728
ULONG cbSize;
2829
DWORD nFont;
@@ -32,6 +33,7 @@ typedef struct _CONSOLE_FONT_INFOEX {
3233
WCHAR FaceName[LF_FACESIZE];
3334
} CONSOLE_FONT_INFOEX, *PCONSOLE_FONT_INFOEX;
3435
#endif
36+
#endif
3537

3638
typedef BOOL (WINAPI *PGETCURRENTCONSOLEFONTEX)(HANDLE, BOOL,
3739
PCONSOLE_FONT_INFOEX);

config.mak.uname

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,6 @@ ifneq (,$(findstring MINGW,$(uname_S)))
495495
NO_MKDTEMP = YesPlease
496496
NO_MKSTEMPS = YesPlease
497497
NO_SVN_TESTS = YesPlease
498-
NO_PERL_MAKEMAKER = YesPlease
499498
RUNTIME_PREFIX = YesPlease
500499
NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
501500
NO_NSEC = YesPlease
@@ -512,13 +511,12 @@ ifneq (,$(findstring MINGW,$(uname_S)))
512511
NO_POSIX_GOODIES = UnfortunatelyYes
513512
DEFAULT_HELP_FORMAT = html
514513
NO_D_INO_IN_DIRENT = YesPlease
515-
COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -D_USE_32BIT_TIME_T -DNOGDI -Icompat -Icompat/win32
514+
COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/win32
516515
COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
517516
COMPAT_OBJS += compat/mingw.o compat/winansi.o \
518517
compat/win32/pthread.o compat/win32/syslog.o \
519518
compat/win32/dirent.o
520519
BASIC_CFLAGS += -DPROTECT_NTFS_DEFAULT=1
521-
BASIC_LDFLAGS += -Wl,--large-address-aware
522520
EXTLIBS += -lws2_32
523521
GITLIBS += git.res
524522
PTHREAD_LIBS =
@@ -527,7 +525,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
527525
X = .exe
528526
SPARSE_FLAGS = -Wno-one-bit-signed-bitfield
529527
ifneq (,$(wildcard ../THIS_IS_MSYSGIT))
530-
htmldir = doc/git/html/
528+
htmldir = share/doc/git/$(firstword $(subst -, ,$(GIT_VERSION)))/html
531529
prefix =
532530
INSTALL = /bin/install
533531
EXTLIBS += /mingw/lib/libz.a
@@ -536,7 +534,33 @@ ifneq (,$(wildcard ../THIS_IS_MSYSGIT))
536534
HAVE_LIBCHARSET_H = YesPlease
537535
NO_GETTEXT = YesPlease
538536
else
539-
NO_CURL = YesPlease
537+
ifeq ($(shell expr "$(uname_R)" : '2\.'),2)
538+
# MSys2
539+
prefix = /usr/
540+
ifeq (MINGW32,$(MSYSTEM))
541+
prefix = /mingw32/
542+
endif
543+
ifeq (MINGW64,$(MSYSTEM))
544+
prefix = /mingw64/
545+
else
546+
COMPAT_CFLAGS += -D_USE_32BIT_TIME_T
547+
BASIC_LDFLAGS += -Wl,--large-address-aware
548+
endif
549+
CC = gcc
550+
htmldir = share/doc/git/$(firstword $(subst -, ,$(GIT_VERSION)))/html
551+
INSTALL = /bin/install
552+
NO_R_TO_GCC_LINKER = YesPlease
553+
INTERNAL_QSORT = YesPlease
554+
HAVE_LIBCHARSET_H = YesPlease
555+
NO_GETTEXT =
556+
USE_GETTEXT_SCHEME = fallthrough
557+
USE_LIBPCRE= YesPlease
558+
NO_CURL =
559+
USE_NED_ALLOCATOR =
560+
NO_PYTHON =
561+
else
562+
NO_CURL = YesPlease
563+
endif
540564
endif
541565
endif
542566
ifeq ($(uname_S),QNX)

http.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "credential.h"
99
#include "version.h"
1010
#include "pkt-line.h"
11+
#include "exec_cmd.h"
1112

1213
int active_requests;
1314
int http_is_verbose;
@@ -147,24 +148,36 @@ static void process_curl_messages(void)
147148
}
148149
#endif
149150

151+
static int git_config_path(const char **result,
152+
const char *var, const char *value)
153+
{
154+
if (git_config_string(result, var, value))
155+
return 1;
156+
#ifdef __MINGW32__
157+
if (**result == '/')
158+
*result = system_path((*result) + 1);
159+
#endif
160+
return 0;
161+
}
162+
150163
static int http_options(const char *var, const char *value, void *cb)
151164
{
152165
if (!strcmp("http.sslverify", var)) {
153166
curl_ssl_verify = git_config_bool(var, value);
154167
return 0;
155168
}
156169
if (!strcmp("http.sslcert", var))
157-
return git_config_string(&ssl_cert, var, value);
170+
return git_config_path(&ssl_cert, var, value);
158171
#if LIBCURL_VERSION_NUM >= 0x070903
159172
if (!strcmp("http.sslkey", var))
160-
return git_config_string(&ssl_key, var, value);
173+
return git_config_path(&ssl_key, var, value);
161174
#endif
162175
#if LIBCURL_VERSION_NUM >= 0x070908
163176
if (!strcmp("http.sslcapath", var))
164-
return git_config_string(&ssl_capath, var, value);
177+
return git_config_path(&ssl_capath, var, value);
165178
#endif
166179
if (!strcmp("http.sslcainfo", var))
167-
return git_config_string(&ssl_cainfo, var, value);
180+
return git_config_path(&ssl_cainfo, var, value);
168181
if (!strcmp("http.sslcertpasswordprotected", var)) {
169182
ssl_cert_password_required = git_config_bool(var, value);
170183
return 0;

perl/Git.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ sub repository {
188188
};
189189

190190
if ($dir) {
191-
$dir =~ m#^/# or $dir = $opts{Directory} . '/' . $dir;
191+
_verify_require();
192+
File::Spec->file_name_is_absolute($dir) or $dir = $opts{Directory} . '/' . $dir;
192193
$opts{Repository} = abs_path($dir);
193194

194195
# If --git-dir went ok, this shouldn't die either.

t/t3300-funny-names.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ tree, index, and tree objects.
1313

1414
HT=' '
1515

16+
test_have_prereq MINGW ||
1617
echo 2>/dev/null > "Name with an${HT}HT"
1718
if ! test -f "Name with an${HT}HT"
1819
then

t/t3600-rm.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ test_expect_success \
1414
git add -- foo bar baz 'space embedded' -q &&
1515
git commit -m 'add normal files'"
1616

17-
if touch -- 'tab embedded' 'newline
17+
18+
if ! test_have_prereq MINGW && touch -- 'tab embedded' 'newline
1819
embedded' 2>/dev/null
1920
then
2021
test_set_prereq FUNNYNAMES

t/t3703-add-magic-pathspec.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ cat >expected <<EOF
3838
add 'sub/foo'
3939
EOF
4040

41-
if mkdir ":" 2>/dev/null
41+
if ! test_have_prereq MINGW && mkdir ":" 2>/dev/null
4242
then
4343
test_set_prereq COLON_DIR
4444
fi

t/t3902-quoted.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ GN='純'
1212
HT=' '
1313
DQ='"'
1414

15+
test_have_prereq MINGW ||
1516
echo foo 2>/dev/null > "Name and an${HT}HT"
1617
if ! test -f "Name and an${HT}HT"
1718
then

t/t4016-diff-quote.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ P1='pathname with HT'
1313
P2='pathname with SP'
1414
P3='pathname
1515
with LF'
16+
test_have_prereq !MINGW &&
1617
echo 2>/dev/null >"$P1" && test -f "$P1" && rm -f "$P1" || {
1718
skip_all='Your filesystem does not allow tabs in filenames'
1819
test_done

t/t4135-apply-weird-filenames.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ test_expect_success 'setup' '
1919
2020
test_when_finished "rm -f \"tab embedded.txt\"" &&
2121
test_when_finished "rm -f '\''\"quoteembedded\".txt'\''" &&
22-
if touch -- "tab embedded.txt" '\''"quoteembedded".txt'\''
22+
if ! test_have_prereq MINGW &&
23+
touch -- "tab embedded.txt" '\''"quoteembedded".txt'\''
2324
then
2425
test_set_prereq FUNNYNAMES
2526
fi

t/t5516-fetch-push.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ This test checks the following functionality:
1616

1717
. ./test-lib.sh
1818

19+
if test_have_prereq MINGW
20+
then
21+
# Avoid posix-to-windows path mangling
22+
pwd () {
23+
builtin pwd
24+
}
25+
fi
26+
1927
D=`pwd`
2028

2129
mk_empty () {

t/t9700/test.pl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ BEGIN
3333
is($r->config_int("test.nonexistent"), undef, "config_int: nonexistent");
3434
ok($r->config_bool("test.booltrue"), "config_bool: true");
3535
ok(!$r->config_bool("test.boolfalse"), "config_bool: false");
36-
is($r->config_path("test.path"), $r->config("test.pathexpanded"),
36+
our $test_path = $r->config_path("test.path");
37+
$test_path =~ s/\\/\//g if ($^O eq 'msys');
38+
is($test_path, $r->config("test.pathexpanded"),
3739
"config_path: ~/foo expansion");
3840
is_deeply([$r->config_path("test.pathmulti")], ["foo", "bar"],
3941
"config_path: multiple values");

t/t9903-bash-prompt.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ repo_with_newline='repo
6767
with
6868
newline'
6969

70-
if mkdir "$repo_with_newline" 2>/dev/null
70+
if ! test_have_prereq MINGW && mkdir "$repo_with_newline" 2>/dev/null
7171
then
7272
test_set_prereq FUNNYNAMES
7373
else

0 commit comments

Comments
 (0)