Skip to content

Fixes required to build Git for Windows with MSys2 #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Feb 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,16 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
free(quoted);
}

if (getenv("GIT_STRACE_COMMANDS")) {
char **path = get_path_split();
cmd = path_lookup("strace.exe", path, 1);
if (!cmd)
return error("strace not found!");
if (xutftowcs_path(wcmd, cmd) < 0)
return -1;
strbuf_insert(&args, 0, "strace ", 7);
}

wargs = xmalloc((2 * args.len + 1) * sizeof(wchar_t));
xutftowcs(wargs, args.buf, 2 * args.len + 1);
strbuf_release(&args);
Expand Down Expand Up @@ -2216,8 +2226,26 @@ void mingw_startup()
__argv[0] = wcstoutfdup_startup(buffer, _wpgmptr, maxlen);
for (i = 1; i < argc; i++)
__argv[i] = wcstoutfdup_startup(buffer, wargv[i], maxlen);
for (i = 0; wenv[i]; i++)
for (i = 0; wenv[i]; i++) {
environ[i] = wcstoutfdup_startup(buffer, wenv[i], maxlen);
if (starts_with(environ[i], "MSYS2_TZ=")) {
char *to_free = environ[i];
environ[i] = xstrdup(to_free + 6);
free(to_free);
}
if (starts_with(environ[i], "TMP=")) {
/*
* Convert all dir separators to forward slashes,
* to help shell commands called from the Git
* executable (by not mistaking the dir separators
* for escape characters.
*/
char *p;
for (p = environ[i]; *p; p++)
if (*p == '\\')
*p = '/';
}
}
environ[i] = NULL;
free(buffer);

Expand Down
17 changes: 14 additions & 3 deletions compat/mingw.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
#include <stdint.h>
#include <wchar.h>
#include <winsock2.h>
#include <ws2tcpip.h>

/*
* things that are not available in header files
*/

typedef int pid_t;
typedef int uid_t;
typedef int socklen_t;
#define hstrerror strerror

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

#ifndef S_IRWXG
#define S_IRGRP 0
#define S_IWGRP 0
#define S_IXGRP 0
#define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
#endif
#ifndef S_IRWXO
#define S_IROTH 0
#define S_IWOTH 0
#define S_IXOTH 0
#define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
#endif

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

#ifdef NO_UNSETENV
#error "NO_UNSETENV is incompatible with the MinGW startup code!"
#endif

char *mingw_getenv(const char *name);
#define getenv mingw_getenv
int mingw_putenv(const char *namevalue);
Expand Down Expand Up @@ -296,8 +305,10 @@ static inline time_t filetime_to_time_t(const FILETIME *ft)
/*
* Use mingw specific stat()/lstat()/fstat() implementations on Windows.
*/
#ifndef __MINGW64_VERSION_MAJOR
#define off_t off64_t
#define lseek _lseeki64
#endif

/* use struct stat with 64 bit st_size */
#ifdef stat
Expand Down
2 changes: 1 addition & 1 deletion compat/win32/pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ extern pthread_t pthread_self(void);

static inline int pthread_exit(void *ret)
{
ExitThread((DWORD)ret);
ExitThread((DWORD)(size_t)ret);
}

typedef DWORD pthread_key_t;
Expand Down
2 changes: 2 additions & 0 deletions compat/winansi.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static HANDLE hthread, hread, hwrite;
static HANDLE hconsole1, hconsole2;

#ifdef __MINGW32__
#if !defined(__MINGW64_VERSION_MAJOR) || __MINGW64_VERSION_MAJOR < 5
typedef struct _CONSOLE_FONT_INFOEX {
ULONG cbSize;
DWORD nFont;
Expand All @@ -32,6 +33,7 @@ typedef struct _CONSOLE_FONT_INFOEX {
WCHAR FaceName[LF_FACESIZE];
} CONSOLE_FONT_INFOEX, *PCONSOLE_FONT_INFOEX;
#endif
#endif

typedef BOOL (WINAPI *PGETCURRENTCONSOLEFONTEX)(HANDLE, BOOL,
PCONSOLE_FONT_INFOEX);
Expand Down
30 changes: 28 additions & 2 deletions config.mak.uname
Original file line number Diff line number Diff line change
Expand Up @@ -503,12 +503,11 @@ ifneq (,$(findstring MINGW,$(uname_S)))
NO_POSIX_GOODIES = UnfortunatelyYes
DEFAULT_HELP_FORMAT = html
NO_D_INO_IN_DIRENT = YesPlease
COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -D_USE_32BIT_TIME_T -DNOGDI -Icompat -Icompat/win32
COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/win32
COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
COMPAT_OBJS += compat/mingw.o compat/winansi.o \
compat/win32/pthread.o compat/win32/syslog.o \
compat/win32/dirent.o compat/win32/fscache.o
BASIC_LDFLAGS += -Wl,--large-address-aware
EXTLIBS += -lws2_32
GITLIBS += git.res
PTHREAD_LIBS =
Expand All @@ -529,6 +528,33 @@ ifneq (,$(wildcard ../THIS_IS_MSYSGIT))
else
NO_CURL = YesPlease
endif
ifeq (MINGW32,$(MSYSTEM))
prefix = /mingw32/
NO_PYTHON =
endif
ifeq (MINGW64,$(MSYSTEM))
prefix = /mingw64/
NO_PYTHON =
else
COMPAT_CFLAGS += -D_USE_32BIT_TIME_T
BASIC_LDFLAGS += -Wl,--large-address-aware
endif
ifeq (MSYS,$(MSYSTEM))
prefix = /usr/
endif
ifneq (,$(MSYSTEM))
CC = gcc
htmldir = share/doc/git/$(firstword $(subst -, ,$(GIT_VERSION)))/html
INSTALL = /bin/install
NO_R_TO_GCC_LINKER = YesPlease
INTERNAL_QSORT = YesPlease
HAVE_LIBCHARSET_H = YesPlease
NO_GETTEXT =
NO_PYTHON =
USE_LIBPCRE= YesPlease
NO_CURL =
USE_NED_ALLOCATOR =
endif
endif
ifeq ($(uname_S),QNX)
COMPAT_CFLAGS += -DSA_RESTART=0
Expand Down
3 changes: 2 additions & 1 deletion perl/Git.pm
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ sub repository {
};

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

# If --git-dir went ok, this shouldn't die either.
Expand Down
1 change: 1 addition & 0 deletions t/t3300-funny-names.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ tree, index, and tree objects.

HT=' '

test_have_prereq MINGW ||
echo 2>/dev/null > "Name with an${HT}HT"
if ! test -f "Name with an${HT}HT"
then
Expand Down
3 changes: 2 additions & 1 deletion t/t3600-rm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ test_expect_success \
git add -- foo bar baz 'space embedded' -q &&
git commit -m 'add normal files'"

if touch -- 'tab embedded' 'newline

if ! test_have_prereq MINGW && touch -- 'tab embedded' 'newline
embedded' 2>/dev/null
then
test_set_prereq FUNNYNAMES
Expand Down
2 changes: 1 addition & 1 deletion t/t3703-add-magic-pathspec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cat >expected <<EOF
add 'sub/foo'
EOF

if mkdir ":" 2>/dev/null
if ! test_have_prereq MINGW && mkdir ":" 2>/dev/null
then
test_set_prereq COLON_DIR
fi
Expand Down
1 change: 1 addition & 0 deletions t/t3902-quoted.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ GN='純'
HT=' '
DQ='"'

test_have_prereq MINGW ||
echo foo 2>/dev/null > "Name and an${HT}HT"
if ! test -f "Name and an${HT}HT"
then
Expand Down
1 change: 1 addition & 0 deletions t/t4016-diff-quote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ P1='pathname with HT'
P2='pathname with SP'
P3='pathname
with LF'
test_have_prereq !MINGW &&
echo 2>/dev/null >"$P1" && test -f "$P1" && rm -f "$P1" || {
skip_all='Your filesystem does not allow tabs in filenames'
test_done
Expand Down
3 changes: 2 additions & 1 deletion t/t4135-apply-weird-filenames.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ test_expect_success 'setup' '

test_when_finished "rm -f \"tab embedded.txt\"" &&
test_when_finished "rm -f '\''\"quoteembedded\".txt'\''" &&
if touch -- "tab embedded.txt" '\''"quoteembedded".txt'\''
if ! test_have_prereq MINGW &&
touch -- "tab embedded.txt" '\''"quoteembedded".txt'\''
then
test_set_prereq FUNNYNAMES
fi
Expand Down
3 changes: 0 additions & 3 deletions t/t5000-tar-tree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,9 @@ test_expect_success 'archive --list shows only enabled remote filters' '
test_expect_success 'invoke tar filter by format' '
git archive --format=tar.foo HEAD >config.tar.foo &&
tr ab ba <config.tar.foo >config.tar &&
d2u_force config.tar &&
test_cmp_bin b.tar config.tar &&
git archive --format=bar HEAD >config.bar &&
tr ab ba <config.bar >config.tar &&
d2u_force config.tar &&
test_cmp_bin b.tar config.tar
'

Expand All @@ -269,7 +267,6 @@ test_expect_success 'only enabled filters are available remotely' '
test_must_fail git archive --remote=. --format=tar.foo HEAD \
>remote.tar.foo &&
git archive --remote=. --format=bar >remote.bar HEAD &&
d2u_force config.bar &&
test_cmp_bin remote.bar config.bar
'

Expand Down
8 changes: 8 additions & 0 deletions t/t5516-fetch-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ This test checks the following functionality:

. ./test-lib.sh

if test_have_prereq MINGW
then
# Avoid posix-to-windows path mangling
pwd () {
builtin pwd
}
fi

D=`pwd`

mk_empty () {
Expand Down
4 changes: 3 additions & 1 deletion t/t9700/test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ BEGIN
is($r->config_int("test.nonexistent"), undef, "config_int: nonexistent");
ok($r->config_bool("test.booltrue"), "config_bool: true");
ok(!$r->config_bool("test.boolfalse"), "config_bool: false");
is($r->config_path("test.path"), $r->config("test.pathexpanded"),
our $test_path = $r->config_path("test.path");
$test_path =~ s/\\/\//g if ($^O eq 'msys');
is($test_path, $r->config("test.pathexpanded"),
"config_path: ~/foo expansion");
is_deeply([$r->config_path("test.pathmulti")], ["foo", "bar"],
"config_path: multiple values");
Expand Down
2 changes: 1 addition & 1 deletion t/t9903-bash-prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ repo_with_newline='repo
with
newline'

if mkdir "$repo_with_newline" 2>/dev/null
if ! test_have_prereq MINGW && mkdir "$repo_with_newline" 2>/dev/null
then
test_set_prereq FUNNYNAMES
else
Expand Down
8 changes: 0 additions & 8 deletions t/test-lib-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -866,11 +866,3 @@ mingw_read_file_strip_cr_ () {
eval "$1=\$$1\$line"
done
}

# Perform dos2unix line ending conversion for binary files
d2u_force() {
if test_have_prereq MINGW
then
dos2unix --force "$1"
fi
}
10 changes: 8 additions & 2 deletions t/test-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

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

# Keep the original TERM for say_color
Expand Down Expand Up @@ -524,7 +525,12 @@ maybe_setup_valgrind () {
test_eval_ () {
# This is a separate function because some tests use
# "return" to end a test_expect_success block early.
eval </dev/null >&3 2>&4 "$*"
if test -z "$TEST_NO_REDIRECT"
then
eval </dev/null >&3 2>&4 "$*"
else
eval "$*"
fi
}

test_run_ () {
Expand Down Expand Up @@ -942,7 +948,7 @@ test_i18ngrep () {
test_lazy_prereq PIPE '
# test whether the filesystem supports FIFOs
case $(uname -s) in
CYGWIN*)
CYGWIN*|MINGW*)
false
;;
*)
Expand Down