Skip to content

Commit a852a69

Browse files
committed
Merge pull request #26 from dscho/msys2
Fixes required to build Git for Windows with MSys2
2 parents 124dadd + 3016015 commit a852a69

17 files changed

+139
-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: 18 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
@@ -164,8 +171,10 @@ int pipe(int filedes[2]);
164171
unsigned int sleep (unsigned int seconds);
165172
int mkstemp(char *template);
166173
int gettimeofday(struct timeval *tv, void *tz);
174+
#ifndef __MINGW64_VERSION_MAJOR
167175
struct tm *gmtime_r(const time_t *timep, struct tm *result);
168176
struct tm *localtime_r(const time_t *timep, struct tm *result);
177+
#endif
169178
int getpagesize(void); /* defined in MinGW's libgcc.a */
170179
struct passwd *getpwuid(uid_t uid);
171180
int setitimer(int type, struct itimerval *in, struct itimerval *out);
@@ -213,6 +222,10 @@ char *mingw_mktemp(char *template);
213222
char *mingw_getcwd(char *pointer, int len);
214223
#define getcwd mingw_getcwd
215224

225+
#ifdef NO_UNSETENV
226+
#error "NO_UNSETENV is incompatible with the MinGW startup code!"
227+
#endif
228+
216229
char *mingw_getenv(const char *name);
217230
#define getenv mingw_getenv
218231
int mingw_putenv(const char *namevalue);
@@ -285,8 +298,10 @@ static inline int getrlimit(int resource, struct rlimit *rlp)
285298
/*
286299
* Use mingw specific stat()/lstat()/fstat() implementations on Windows.
287300
*/
301+
#ifndef __MINGW64_VERSION_MAJOR
288302
#define off_t off64_t
289303
#define lseek _lseeki64
304+
#endif
290305

291306
/* use struct stat with 64 bit st_size */
292307
#ifdef stat

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;
@@ -180,24 +181,36 @@ static void process_curl_messages(void)
180181
}
181182
#endif
182183

184+
static int git_config_path(const char **result,
185+
const char *var, const char *value)
186+
{
187+
if (git_config_string(result, var, value))
188+
return 1;
189+
#ifdef __MINGW32__
190+
if (**result == '/')
191+
*result = system_path((*result) + 1);
192+
#endif
193+
return 0;
194+
}
195+
183196
static int http_options(const char *var, const char *value, void *cb)
184197
{
185198
if (!strcmp("http.sslverify", var)) {
186199
curl_ssl_verify = git_config_bool(var, value);
187200
return 0;
188201
}
189202
if (!strcmp("http.sslcert", var))
190-
return git_config_string(&ssl_cert, var, value);
203+
return git_config_path(&ssl_cert, var, value);
191204
#if LIBCURL_VERSION_NUM >= 0x070903
192205
if (!strcmp("http.sslkey", var))
193-
return git_config_string(&ssl_key, var, value);
206+
return git_config_path(&ssl_key, var, value);
194207
#endif
195208
#if LIBCURL_VERSION_NUM >= 0x070908
196209
if (!strcmp("http.sslcapath", var))
197-
return git_config_string(&ssl_capath, var, value);
210+
return git_config_path(&ssl_capath, var, value);
198211
#endif
199212
if (!strcmp("http.sslcainfo", var))
200-
return git_config_string(&ssl_cainfo, var, value);
213+
return git_config_path(&ssl_cainfo, var, value);
201214
if (!strcmp("http.sslcertpasswordprotected", var)) {
202215
ssl_cert_password_required = git_config_bool(var, value);
203216
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

t/test-lib.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,20 @@ test_eval_ () {
506506
#
507507
# The test itself is run with stderr put back to &4 (so either to
508508
# /dev/null, or to the original stderr if --verbose was used).
509+
if test -n "$TEST_NO_REDIRECT"
510+
then
511+
test_eval_inner_ "$@"
512+
test_eval_ret_=$?
513+
if test "$trace" = t
514+
then
515+
set +x
516+
if test "$test_eval_ret_" != 0
517+
then
518+
say_color error >&4 "error: last command exited with \$?=$test_eval_ret_"
519+
fi
520+
fi
521+
return $test_eval_ret_
522+
fi
509523
{
510524
test_eval_inner_ "$@" </dev/null >&3 2>&4
511525
test_eval_ret_=$?
@@ -980,7 +994,7 @@ test_i18ngrep () {
980994
test_lazy_prereq PIPE '
981995
# test whether the filesystem supports FIFOs
982996
case $(uname -s) in
983-
CYGWIN*)
997+
CYGWIN*|MINGW*)
984998
false
985999
;;
9861000
*)

0 commit comments

Comments
 (0)