Skip to content

Commit ff4771b

Browse files
committed
Merge pull request #26 from dscho/msys2
Fixes required to build Git for Windows with MSys2
2 parents daea199 + 119830d commit ff4771b

18 files changed

+104
-26
lines changed

compat/mingw.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,16 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
10711071
free(quoted);
10721072
}
10731073

1074+
if (getenv("GIT_STRACE_COMMANDS")) {
1075+
char **path = get_path_split();
1076+
cmd = path_lookup("strace.exe", path, 1);
1077+
if (!cmd)
1078+
return error("strace not found!");
1079+
if (xutftowcs_path(wcmd, cmd) < 0)
1080+
return -1;
1081+
strbuf_insert(&args, 0, "strace ", 7);
1082+
}
1083+
10741084
wargs = xmalloc((2 * args.len + 1) * sizeof(wchar_t));
10751085
xutftowcs(wargs, args.buf, 2 * args.len + 1);
10761086
strbuf_release(&args);
@@ -2216,8 +2226,26 @@ void mingw_startup()
22162226
__argv[0] = wcstoutfdup_startup(buffer, _wpgmptr, maxlen);
22172227
for (i = 1; i < argc; i++)
22182228
__argv[i] = wcstoutfdup_startup(buffer, wargv[i], maxlen);
2219-
for (i = 0; wenv[i]; i++)
2229+
for (i = 0; wenv[i]; i++) {
22202230
environ[i] = wcstoutfdup_startup(buffer, wenv[i], maxlen);
2231+
if (starts_with(environ[i], "MSYS2_TZ=")) {
2232+
char *to_free = environ[i];
2233+
environ[i] = xstrdup(to_free + 6);
2234+
free(to_free);
2235+
}
2236+
if (starts_with(environ[i], "TMP=")) {
2237+
/*
2238+
* Convert all dir separators to forward slashes,
2239+
* to help shell commands called from the Git
2240+
* executable (by not mistaking the dir separators
2241+
* for escape characters.
2242+
*/
2243+
char *p;
2244+
for (p = environ[i]; *p; p++)
2245+
if (*p == '\\')
2246+
*p = '/';
2247+
}
2248+
}
22212249
environ[i] = NULL;
22222250
free(buffer);
22232251

compat/mingw.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1+
#include <stdint.h>
2+
#include <wchar.h>
13
#include <winsock2.h>
24
#include <ws2tcpip.h>
3-
45
/*
56
* things that are not available in header files
67
*/
78

8-
typedef int pid_t;
99
typedef int uid_t;
1010
typedef int socklen_t;
11-
#define hstrerror strerror
1211

1312
#define S_IFLNK 0120000 /* Symbolic link */
1413
#define S_ISLNK(x) (((x) & S_IFMT) == S_IFLNK)
1514
#define S_ISSOCK(x) 0
1615

16+
#ifndef S_IRWXG
1717
#define S_IRGRP 0
1818
#define S_IWGRP 0
1919
#define S_IXGRP 0
2020
#define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
21+
#endif
22+
#ifndef S_IRWXO
2123
#define S_IROTH 0
2224
#define S_IWOTH 0
2325
#define S_IXOTH 0
2426
#define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
27+
#endif
2528

2629
#define S_ISUID 0004000
2730
#define S_ISGID 0002000
@@ -159,8 +162,10 @@ int pipe(int filedes[2]);
159162
unsigned int sleep (unsigned int seconds);
160163
int mkstemp(char *template);
161164
int gettimeofday(struct timeval *tv, void *tz);
165+
#ifndef __MINGW64_VERSION_MAJOR
162166
struct tm *gmtime_r(const time_t *timep, struct tm *result);
163167
struct tm *localtime_r(const time_t *timep, struct tm *result);
168+
#endif
164169
int getpagesize(void); /* defined in MinGW's libgcc.a */
165170
struct passwd *getpwuid(uid_t uid);
166171
int setitimer(int type, struct itimerval *in, struct itimerval *out);
@@ -208,6 +213,10 @@ char *mingw_mktemp(char *template);
208213
char *mingw_getcwd(char *pointer, int len);
209214
#define getcwd mingw_getcwd
210215

216+
#ifdef NO_UNSETENV
217+
#error "NO_UNSETENV is incompatible with the MinGW startup code!"
218+
#endif
219+
211220
char *mingw_getenv(const char *name);
212221
#define getenv mingw_getenv
213222
int mingw_putenv(const char *namevalue);
@@ -296,8 +305,10 @@ static inline time_t filetime_to_time_t(const FILETIME *ft)
296305
/*
297306
* Use mingw specific stat()/lstat()/fstat() implementations on Windows.
298307
*/
308+
#ifndef __MINGW64_VERSION_MAJOR
299309
#define off_t off64_t
300310
#define lseek _lseeki64
311+
#endif
301312

302313
/* use struct stat with 64 bit st_size */
303314
#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: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,12 +503,11 @@ ifneq (,$(findstring MINGW,$(uname_S)))
503503
NO_POSIX_GOODIES = UnfortunatelyYes
504504
DEFAULT_HELP_FORMAT = html
505505
NO_D_INO_IN_DIRENT = YesPlease
506-
COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -D_USE_32BIT_TIME_T -DNOGDI -Icompat -Icompat/win32
506+
COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/win32
507507
COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
508508
COMPAT_OBJS += compat/mingw.o compat/winansi.o \
509509
compat/win32/pthread.o compat/win32/syslog.o \
510510
compat/win32/dirent.o compat/win32/fscache.o
511-
BASIC_LDFLAGS += -Wl,--large-address-aware
512511
EXTLIBS += -lws2_32
513512
GITLIBS += git.res
514513
PTHREAD_LIBS =
@@ -529,6 +528,33 @@ ifneq (,$(wildcard ../THIS_IS_MSYSGIT))
529528
else
530529
NO_CURL = YesPlease
531530
endif
531+
ifeq (MINGW32,$(MSYSTEM))
532+
prefix = /mingw32/
533+
NO_PYTHON =
534+
endif
535+
ifeq (MINGW64,$(MSYSTEM))
536+
prefix = /mingw64/
537+
NO_PYTHON =
538+
else
539+
COMPAT_CFLAGS += -D_USE_32BIT_TIME_T
540+
BASIC_LDFLAGS += -Wl,--large-address-aware
541+
endif
542+
ifeq (MSYS,$(MSYSTEM))
543+
prefix = /usr/
544+
endif
545+
ifneq (,$(MSYSTEM))
546+
CC = gcc
547+
htmldir = share/doc/git/$(firstword $(subst -, ,$(GIT_VERSION)))/html
548+
INSTALL = /bin/install
549+
NO_R_TO_GCC_LINKER = YesPlease
550+
INTERNAL_QSORT = YesPlease
551+
HAVE_LIBCHARSET_H = YesPlease
552+
NO_GETTEXT =
553+
NO_PYTHON =
554+
USE_LIBPCRE= YesPlease
555+
NO_CURL =
556+
USE_NED_ALLOCATOR =
557+
endif
532558
endif
533559
ifeq ($(uname_S),QNX)
534560
COMPAT_CFLAGS += -DSA_RESTART=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/t5000-tar-tree.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,9 @@ test_expect_success 'archive --list shows only enabled remote filters' '
240240
test_expect_success 'invoke tar filter by format' '
241241
git archive --format=tar.foo HEAD >config.tar.foo &&
242242
tr ab ba <config.tar.foo >config.tar &&
243-
d2u_force config.tar &&
244243
test_cmp_bin b.tar config.tar &&
245244
git archive --format=bar HEAD >config.bar &&
246245
tr ab ba <config.bar >config.tar &&
247-
d2u_force config.tar &&
248246
test_cmp_bin b.tar config.tar
249247
'
250248

@@ -269,7 +267,6 @@ test_expect_success 'only enabled filters are available remotely' '
269267
test_must_fail git archive --remote=. --format=tar.foo HEAD \
270268
>remote.tar.foo &&
271269
git archive --remote=. --format=bar >remote.bar HEAD &&
272-
d2u_force config.bar &&
273270
test_cmp_bin remote.bar config.bar
274271
'
275272

t/t5516-fetch-push.sh

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

1616
. ./test-lib.sh
1717

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

2028
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
@@ -65,7 +65,7 @@ repo_with_newline='repo
6565
with
6666
newline'
6767

68-
if mkdir "$repo_with_newline" 2>/dev/null
68+
if ! test_have_prereq MINGW && mkdir "$repo_with_newline" 2>/dev/null
6969
then
7070
test_set_prereq FUNNYNAMES
7171
else

t/test-lib-functions.sh

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -866,11 +866,3 @@ mingw_read_file_strip_cr_ () {
866866
eval "$1=\$$1\$line"
867867
done
868868
}
869-
870-
# Perform dos2unix line ending conversion for binary files
871-
d2u_force() {
872-
if test_have_prereq MINGW
873-
then
874-
dos2unix --force "$1"
875-
fi
876-
}

t/test-lib.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
# for git on windows so stdin will not be misdetected as attached to a
1919
# terminal
20+
test -z "$TEST_NO_REDIRECT" ||
2021
exec < /dev/null
2122

2223
# Keep the original TERM for say_color
@@ -524,7 +525,12 @@ maybe_setup_valgrind () {
524525
test_eval_ () {
525526
# This is a separate function because some tests use
526527
# "return" to end a test_expect_success block early.
527-
eval </dev/null >&3 2>&4 "$*"
528+
if test -z "$TEST_NO_REDIRECT"
529+
then
530+
eval </dev/null >&3 2>&4 "$*"
531+
else
532+
eval "$*"
533+
fi
528534
}
529535

530536
test_run_ () {
@@ -942,7 +948,7 @@ test_i18ngrep () {
942948
test_lazy_prereq PIPE '
943949
# test whether the filesystem supports FIFOs
944950
case $(uname -s) in
945-
CYGWIN*)
951+
CYGWIN*|MINGW*)
946952
false
947953
;;
948954
*)

0 commit comments

Comments
 (0)