Skip to content

Commit 4339e25

Browse files
committed
Merge branch 'jh/msvc' into jch
Support to build with MSVC has been updated. * jh/msvc: msvc: ignore .dll and incremental compile output msvc: avoid debug assertion windows in Debug Mode msvc: do not pretend to support all signals msvc: add pragmas for common warnings msvc: add a compile-time flag to allow detailed heap debugging msvc: support building Git using MS Visual C++ msvc: update Makefile to allow for spaces in the compiler path msvc: fix detect_msys_tty() msvc: define ftello() msvc: do not re-declare the timespec struct msvc: mark a variable as non-const msvc: define O_ACCMODE msvc: include sigset_t definition msvc: fix dependencies of compat/msvc.c mingw: replace mingw_startup() hack obstack: fix compiler warning cache-tree/blame: avoid reusing the DEBUG constant t0001 (mingw): do not expect a specific order of stdout/stderr Mark .bat files as requiring CR/LF endings mingw: fix a typo in the msysGit-specific section
2 parents 2336262 + 54b6110 commit 4339e25

19 files changed

+620
-62
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*.pl eof=lf diff=perl
66
*.pm eol=lf diff=perl
77
*.py eol=lf diff=python
8+
*.bat eol=crlf
89
/Documentation/**/*.txt eol=lf
910
/command-list.txt eol=lf
1011
/GIT-VERSION-GEN eol=lf

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@
225225
*.user
226226
*.idb
227227
*.pdb
228+
*.ilk
229+
*.iobj
230+
*.ipdb
231+
*.dll
232+
.vs/
228233
/Debug/
229234
/Release/
230235
*.dSYM

Makefile

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ endif
12381238

12391239
ifdef SANE_TOOL_PATH
12401240
SANE_TOOL_PATH_SQ = $(subst ','\'',$(SANE_TOOL_PATH))
1241-
BROKEN_PATH_FIX = 's|^\# @@BROKEN_PATH_FIX@@$$|git_broken_path_fix $(SANE_TOOL_PATH_SQ)|'
1241+
BROKEN_PATH_FIX = 's|^\# @@BROKEN_PATH_FIX@@$$|git_broken_path_fix "$(SANE_TOOL_PATH_SQ)"|'
12421242
PATH := $(SANE_TOOL_PATH):${PATH}
12431243
else
12441244
BROKEN_PATH_FIX = '/^\# @@BROKEN_PATH_FIX@@$$/d'
@@ -2861,6 +2861,33 @@ install: all
28612861
$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
28622862
$(INSTALL) -m 644 $(SCRIPT_LIB) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
28632863
$(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)'
2864+
ifdef MSVC
2865+
# We DO NOT install the individual foo.o.pdb files because they
2866+
# have already been rolled up into the exe's pdb file.
2867+
# We DO NOT have pdb files for the builtin commands (like git-status.exe)
2868+
# because it is just a copy/hardlink of git.exe, rather than a unique binary.
2869+
$(INSTALL) git.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2870+
$(INSTALL) git-shell.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2871+
$(INSTALL) git-upload-pack.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2872+
$(INSTALL) git-credential-store.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2873+
$(INSTALL) git-daemon.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2874+
$(INSTALL) git-fast-import.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2875+
$(INSTALL) git-http-backend.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2876+
$(INSTALL) git-http-fetch.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2877+
$(INSTALL) git-http-push.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2878+
$(INSTALL) git-imap-send.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2879+
$(INSTALL) git-remote-http.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2880+
$(INSTALL) git-remote-testsvn.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2881+
$(INSTALL) git-sh-i18n--envsubst.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2882+
$(INSTALL) git-show-index.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2883+
ifndef DEBUG
2884+
$(INSTALL) $(vcpkg_rel_bin)/*.dll '$(DESTDIR_SQ)$(bindir_SQ)'
2885+
$(INSTALL) $(vcpkg_rel_bin)/*.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2886+
else
2887+
$(INSTALL) $(vcpkg_dbg_bin)/*.dll '$(DESTDIR_SQ)$(bindir_SQ)'
2888+
$(INSTALL) $(vcpkg_dbg_bin)/*.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2889+
endif
2890+
endif
28642891
$(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
28652892
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mergetools_instdir_SQ)'
28662893
$(INSTALL) -m 644 mergetools/* '$(DESTDIR_SQ)$(mergetools_instdir_SQ)'
@@ -3073,6 +3100,19 @@ endif
30733100
$(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-LDFLAGS GIT-BUILD-OPTIONS
30743101
$(RM) GIT-USER-AGENT GIT-PREFIX
30753102
$(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PERL-HEADER GIT-PYTHON-VARS
3103+
ifdef MSVC
3104+
$(RM) $(patsubst %.o,%.o.pdb,$(OBJECTS))
3105+
$(RM) $(patsubst %.exe,%.pdb,$(OTHER_PROGRAMS))
3106+
$(RM) $(patsubst %.exe,%.iobj,$(OTHER_PROGRAMS))
3107+
$(RM) $(patsubst %.exe,%.ipdb,$(OTHER_PROGRAMS))
3108+
$(RM) $(patsubst %.exe,%.pdb,$(PROGRAMS))
3109+
$(RM) $(patsubst %.exe,%.iobj,$(PROGRAMS))
3110+
$(RM) $(patsubst %.exe,%.ipdb,$(PROGRAMS))
3111+
$(RM) $(patsubst %.exe,%.pdb,$(TEST_PROGRAMS))
3112+
$(RM) $(patsubst %.exe,%.iobj,$(TEST_PROGRAMS))
3113+
$(RM) $(patsubst %.exe,%.ipdb,$(TEST_PROGRAMS))
3114+
$(RM) compat/vcbuild/MSVC-DEFS-GEN
3115+
endif
30763116

30773117
.PHONY: all install profile-clean cocciclean clean strip
30783118
.PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell

builtin/blame.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ static size_t blame_date_width;
5959

6060
static struct string_list mailmap = STRING_LIST_INIT_NODUP;
6161

62-
#ifndef DEBUG
63-
#define DEBUG 0
62+
#ifndef DEBUG_BLAME
63+
#define DEBUG_BLAME 0
6464
#endif
6565

6666
static unsigned blame_move_score;
@@ -1062,7 +1062,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
10621062
if (blame_copy_score)
10631063
sb.copy_score = blame_copy_score;
10641064

1065-
sb.debug = DEBUG;
1065+
sb.debug = DEBUG_BLAME;
10661066
sb.on_sanity_fail = &sanity_check_on_fail;
10671067

10681068
sb.show_root = show_root;

cache-tree.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#include "object-store.h"
77
#include "replace-object.h"
88

9-
#ifndef DEBUG
10-
#define DEBUG 0
9+
#ifndef DEBUG_CACHE_TREE
10+
#define DEBUG_CACHE_TREE 0
1111
#endif
1212

1313
struct cache_tree *cache_tree(void)
@@ -111,7 +111,7 @@ static int do_invalidate_path(struct cache_tree *it, const char *path)
111111
int namelen;
112112
struct cache_tree_sub *down;
113113

114-
#if DEBUG
114+
#if DEBUG_CACHE_TREE
115115
fprintf(stderr, "cache-tree invalidate <%s>\n", path);
116116
#endif
117117

@@ -398,7 +398,7 @@ static int update_one(struct cache_tree *it,
398398
strbuf_addf(&buffer, "%o %.*s%c", mode, entlen, path + baselen, '\0');
399399
strbuf_add(&buffer, oid->hash, the_hash_algo->rawsz);
400400

401-
#if DEBUG
401+
#if DEBUG_CACHE_TREE
402402
fprintf(stderr, "cache-tree update-one %o %.*s\n",
403403
mode, entlen, path + baselen);
404404
#endif
@@ -421,7 +421,7 @@ static int update_one(struct cache_tree *it,
421421

422422
strbuf_release(&buffer);
423423
it->entry_count = to_invalidate ? -1 : i - *skip_count;
424-
#if DEBUG
424+
#if DEBUG_CACHE_TREE
425425
fprintf(stderr, "cache-tree update-one (%d ent, %d subtree) %s\n",
426426
it->entry_count, it->subtree_nr,
427427
oid_to_hex(&it->oid));
@@ -462,7 +462,7 @@ static void write_one(struct strbuf *buffer, struct cache_tree *it,
462462
strbuf_add(buffer, path, pathlen);
463463
strbuf_addf(buffer, "%c%d %d\n", 0, it->entry_count, it->subtree_nr);
464464

465-
#if DEBUG
465+
#if DEBUG_CACHE_TREE
466466
if (0 <= it->entry_count)
467467
fprintf(stderr, "cache-tree <%.*s> (%d ent, %d subtree) %s\n",
468468
pathlen, path, it->entry_count, it->subtree_nr,
@@ -536,7 +536,7 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
536536
size -= rawsz;
537537
}
538538

539-
#if DEBUG
539+
#if DEBUG_CACHE_TREE
540540
if (0 <= it->entry_count)
541541
fprintf(stderr, "cache-tree <%s> (%d ent, %d subtree) %s\n",
542542
*buffer, it->entry_count, subtree_nr,

compat/mingw.c

Lines changed: 79 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,10 @@ static int try_shell_exec(const char *cmd, char *const *argv)
15531553
if (prog) {
15541554
int exec_id;
15551555
int argc = 0;
1556-
const char **argv2;
1556+
#ifndef _MSC_VER
1557+
const
1558+
#endif
1559+
char **argv2;
15571560
while (argv[argc]) argc++;
15581561
ALLOC_ARRAY(argv2, argc + 1);
15591562
argv2[0] = (char *)cmd; /* full path to the script file */
@@ -2116,8 +2119,33 @@ int mingw_raise(int sig)
21162119
sigint_fn(SIGINT);
21172120
return 0;
21182121

2122+
#if defined(_MSC_VER)
2123+
case SIGILL:
2124+
case SIGFPE:
2125+
case SIGSEGV:
2126+
case SIGTERM:
2127+
case SIGBREAK:
2128+
case SIGABRT:
2129+
case SIGABRT_COMPAT:
2130+
/*
2131+
* The <signal.h> header in the MS C Runtime defines 8 signals
2132+
* as being supported on the platform. Anything else causes an
2133+
* "Invalid signal or error" (which in DEBUG builds causes the
2134+
* Abort/Retry/Ignore dialog). We by-pass the CRT for things we
2135+
* already know will fail.
2136+
*/
2137+
return raise(sig);
2138+
default:
2139+
errno = EINVAL;
2140+
return -1;
2141+
2142+
#else
2143+
21192144
default:
21202145
return raise(sig);
2146+
2147+
#endif
2148+
21212149
}
21222150
}
21232151

@@ -2301,18 +2329,13 @@ static void setup_windows_environment(void)
23012329
setenv("TERM", "cygwin", 1);
23022330
}
23032331

2332+
#if !defined(_MSC_VER)
23042333
/*
23052334
* Disable MSVCRT command line wildcard expansion (__getmainargs called from
23062335
* mingw startup code, see init.c in mingw runtime).
23072336
*/
23082337
int _CRT_glob = 0;
2309-
2310-
typedef struct {
2311-
int newmode;
2312-
} _startupinfo;
2313-
2314-
extern int __wgetmainargs(int *argc, wchar_t ***argv, wchar_t ***env, int glob,
2315-
_startupinfo *si);
2338+
#endif
23162339

23172340
static NORETURN void die_startup(void)
23182341
{
@@ -2390,21 +2413,40 @@ static void maybe_redirect_std_handles(void)
23902413
GENERIC_WRITE, FILE_FLAG_NO_BUFFERING);
23912414
}
23922415

2393-
void mingw_startup(void)
2416+
#ifdef _MSC_VER
2417+
#ifdef _DEBUG
2418+
#include <crtdbg.h>
2419+
#endif
2420+
#endif
2421+
2422+
/*
2423+
* We implement wmain() and compile with -municode, which would
2424+
* normally ignore main(), but we call the latter from the former
2425+
* so that we can handle non-ASCII command-line parameters
2426+
* appropriately.
2427+
*
2428+
* To be more compatible with the core git code, we convert
2429+
* argv into UTF8 and pass them directly to main().
2430+
*/
2431+
int wmain(int argc, const wchar_t **wargv)
23942432
{
2395-
int i, maxlen, argc;
2396-
char *buffer;
2397-
wchar_t **wenv, **wargv;
2398-
_startupinfo si;
2433+
int i, maxlen, exit_status;
2434+
char *buffer, **save;
2435+
const char **argv;
23992436

24002437
trace2_initialize_clock();
24012438

2402-
maybe_redirect_std_handles();
2439+
#ifdef _MSC_VER
2440+
#ifdef _DEBUG
2441+
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
2442+
#endif
24032443

2404-
/* get wide char arguments and environment */
2405-
si.newmode = 0;
2406-
if (__wgetmainargs(&argc, &wargv, &wenv, _CRT_glob, &si) < 0)
2407-
die_startup();
2444+
#ifdef USE_MSVC_CRTDBG
2445+
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
2446+
#endif
2447+
#endif
2448+
2449+
maybe_redirect_std_handles();
24082450

24092451
/* determine size of argv and environ conversion buffer */
24102452
maxlen = wcslen(wargv[0]);
@@ -2415,9 +2457,16 @@ void mingw_startup(void)
24152457
maxlen = 3 * maxlen + 1;
24162458
buffer = malloc_startup(maxlen);
24172459

2418-
/* convert command line arguments and environment to UTF-8 */
2460+
/*
2461+
* Create a UTF-8 version of w_argv. Also create a "save" copy
2462+
* to remember all the string pointers because parse_options()
2463+
* will remove claimed items from the argv that we pass down.
2464+
*/
2465+
ALLOC_ARRAY(argv, argc + 1);
2466+
ALLOC_ARRAY(save, argc + 1);
24192467
for (i = 0; i < argc; i++)
2420-
__argv[i] = wcstoutfdup_startup(buffer, wargv[i], maxlen);
2468+
argv[i] = save[i] = wcstoutfdup_startup(buffer, wargv[i], maxlen);
2469+
argv[i] = save[i] = NULL;
24212470
free(buffer);
24222471

24232472
/* fix Windows specific environment settings */
@@ -2436,6 +2485,16 @@ void mingw_startup(void)
24362485

24372486
/* initialize Unicode console */
24382487
winansi_init();
2488+
2489+
/* invoke the real main() using our utf8 version of argv. */
2490+
exit_status = main(argc, argv);
2491+
2492+
for (i = 0; i < argc; i++)
2493+
free(save[i]);
2494+
free(save);
2495+
free(argv);
2496+
2497+
return exit_status;
24392498
}
24402499

24412500
int uname(struct utsname *buf)

compat/mingw.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,13 @@ static inline int getrlimit(int resource, struct rlimit *rlp)
352352
#ifndef __MINGW64_VERSION_MAJOR
353353
#define off_t off64_t
354354
#define lseek _lseeki64
355+
#ifndef _MSC_VER
355356
struct timespec {
356357
time_t tv_sec;
357358
long tv_nsec;
358359
};
359360
#endif
361+
#endif
360362

361363
struct mingw_stat {
362364
_dev_t st_dev;
@@ -562,18 +564,18 @@ int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen);
562564
extern CRITICAL_SECTION pinfo_cs;
563565

564566
/*
565-
* A replacement of main() that adds win32 specific initialization.
567+
* Git, like most portable C applications, implements a main() function. On
568+
* Windows, this main() function would receive parameters encoded in the
569+
* current locale, but Git for Windows would prefer UTF-8 encoded parameters.
570+
*
571+
* To make that happen, we still declare main() here, and then declare and
572+
* implement wmain() (which is the Unicode variant of main()) and compile with
573+
* -municode. This wmain() function reencodes the parameters from UTF-16 to
574+
* UTF-8 format, sets up a couple of other things as required on Windows, and
575+
* then hands off to the main() function.
566576
*/
567-
568-
void mingw_startup(void);
569-
#define main(c,v) dummy_decl_mingw_main(void); \
570-
static int mingw_main(c,v); \
571-
int main(int argc, const char **argv) \
572-
{ \
573-
mingw_startup(); \
574-
return mingw_main(__argc, (void *)__argv); \
575-
} \
576-
static int mingw_main(c,v)
577+
int wmain(int argc, const wchar_t **w_argv);
578+
int main(int argc, const char **argv);
577579

578580
/*
579581
* Used by Pthread API implementation for Windows

compat/msvc.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#include <malloc.h>
77
#include <io.h>
88

9+
#pragma warning(disable: 4018) /* signed/unsigned comparison */
10+
#pragma warning(disable: 4244) /* type conversion, possible loss of data */
11+
#pragma warning(disable: 4090) /* 'function' : different 'const' qualifiers (ALLOC_GROW etc.)*/
12+
913
/* porting function */
1014
#define inline __inline
1115
#define __inline__ __inline
@@ -18,6 +22,12 @@
1822

1923
#undef ERROR
2024

25+
#define ftello _ftelli64
26+
27+
typedef int sigset_t;
28+
/* open for reading, writing, or both (not in fcntl.h) */
29+
#define O_ACCMODE (_O_RDONLY | _O_WRONLY | _O_RDWR)
30+
2131
#include "compat/mingw.h"
2232

2333
#endif

compat/obstack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ __extension__ \
496496
( (h)->temp.tempint = (char *) (obj) - (char *) (h)->chunk, \
497497
((((h)->temp.tempint > 0 \
498498
&& (h)->temp.tempint < (h)->chunk_limit - (char *) (h)->chunk)) \
499-
? (int) ((h)->next_free = (h)->object_base \
499+
? (ptrdiff_t) ((h)->next_free = (h)->object_base \
500500
= (h)->temp.tempint + (char *) (h)->chunk) \
501501
: (((obstack_free) ((h), (h)->temp.tempint + (char *) (h)->chunk), 0), 0)))
502502

compat/vcbuild/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/vcpkg/
2+
/MSVC-DEFS-GEN
3+
/VCPKG-DEFS

0 commit comments

Comments
 (0)