Skip to content

Commit 4bd3c49

Browse files
jeffhostetlerdscho
authored andcommitted
Merge branch 'msvc'
Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 4f781a9 + d38254a commit 4bd3c49

18 files changed

+616
-48
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/git-*.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
@@ -222,5 +222,10 @@
222222
*.user
223223
*.idb
224224
*.pdb
225+
*.ilk
226+
*.iobj
227+
*.ipdb
228+
*.dll
229+
.vs/
225230
/Debug/
226231
/Release/

Makefile

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

11801180
ifdef SANE_TOOL_PATH
11811181
SANE_TOOL_PATH_SQ = $(subst ','\'',$(SANE_TOOL_PATH))
1182-
BROKEN_PATH_FIX = 's|^\# @@BROKEN_PATH_FIX@@$$|git_broken_path_fix $(SANE_TOOL_PATH_SQ)|'
1182+
BROKEN_PATH_FIX = 's|^\# @@BROKEN_PATH_FIX@@$$|git_broken_path_fix "$(SANE_TOOL_PATH_SQ)"|'
11831183
PATH := $(SANE_TOOL_PATH):${PATH}
11841184
else
11851185
BROKEN_PATH_FIX = '/^\# @@BROKEN_PATH_FIX@@$$/d'
@@ -2749,6 +2749,33 @@ install: all
27492749
$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
27502750
$(INSTALL) -m 644 $(SCRIPT_LIB) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
27512751
$(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)'
2752+
ifdef MSVC
2753+
# We DO NOT install the individual foo.o.pdb files because they
2754+
# have already been rolled up into the exe's pdb file.
2755+
# We DO NOT have pdb files for the builtin commands (like git-status.exe)
2756+
# because it is just a copy/hardlink of git.exe, rather than a unique binary.
2757+
$(INSTALL) git.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2758+
$(INSTALL) git-shell.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2759+
$(INSTALL) git-upload-pack.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2760+
$(INSTALL) git-credential-store.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2761+
$(INSTALL) git-daemon.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2762+
$(INSTALL) git-fast-import.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2763+
$(INSTALL) git-http-backend.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2764+
$(INSTALL) git-http-fetch.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2765+
$(INSTALL) git-http-push.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2766+
$(INSTALL) git-imap-send.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2767+
$(INSTALL) git-remote-http.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2768+
$(INSTALL) git-remote-testsvn.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2769+
$(INSTALL) git-sh-i18n--envsubst.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2770+
$(INSTALL) git-show-index.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2771+
ifndef DEBUG
2772+
$(INSTALL) $(vcpkg_rel_bin)/*.dll '$(DESTDIR_SQ)$(bindir_SQ)'
2773+
$(INSTALL) $(vcpkg_rel_bin)/*.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2774+
else
2775+
$(INSTALL) $(vcpkg_dbg_bin)/*.dll '$(DESTDIR_SQ)$(bindir_SQ)'
2776+
$(INSTALL) $(vcpkg_dbg_bin)/*.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2777+
endif
2778+
endif
27522779
$(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
27532780
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mergetools_instdir_SQ)'
27542781
$(INSTALL) -m 644 mergetools/* '$(DESTDIR_SQ)$(mergetools_instdir_SQ)'
@@ -2949,6 +2976,19 @@ endif
29492976
$(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-LDFLAGS GIT-BUILD-OPTIONS
29502977
$(RM) GIT-USER-AGENT GIT-PREFIX
29512978
$(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PERL-HEADER GIT-PYTHON-VARS
2979+
ifdef MSVC
2980+
$(RM) $(patsubst %.o,%.o.pdb,$(OBJECTS))
2981+
$(RM) $(patsubst %.exe,%.pdb,$(OTHER_PROGRAMS))
2982+
$(RM) $(patsubst %.exe,%.iobj,$(OTHER_PROGRAMS))
2983+
$(RM) $(patsubst %.exe,%.ipdb,$(OTHER_PROGRAMS))
2984+
$(RM) $(patsubst %.exe,%.pdb,$(PROGRAMS))
2985+
$(RM) $(patsubst %.exe,%.iobj,$(PROGRAMS))
2986+
$(RM) $(patsubst %.exe,%.ipdb,$(PROGRAMS))
2987+
$(RM) $(patsubst %.exe,%.pdb,$(TEST_PROGRAMS))
2988+
$(RM) $(patsubst %.exe,%.iobj,$(TEST_PROGRAMS))
2989+
$(RM) $(patsubst %.exe,%.ipdb,$(TEST_PROGRAMS))
2990+
$(RM) compat/vcbuild/MSVC-DEFS-GEN
2991+
endif
29522992

29532993
.PHONY: all install profile-clean cocciclean clean strip
29542994
.PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell

cache-tree.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#include "cache-tree.h"
66
#include "object-store.h"
77

8-
#ifndef DEBUG
9-
#define DEBUG 0
8+
#ifndef DEBUG_CACHE_TREE
9+
#define DEBUG_CACHE_TREE 0
1010
#endif
1111

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

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

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

396-
#if DEBUG
396+
#if DEBUG_CACHE_TREE
397397
fprintf(stderr, "cache-tree update-one %o %.*s\n",
398398
mode, entlen, path + baselen);
399399
#endif
@@ -416,7 +416,7 @@ static int update_one(struct cache_tree *it,
416416

417417
strbuf_release(&buffer);
418418
it->entry_count = to_invalidate ? -1 : i - *skip_count;
419-
#if DEBUG
419+
#if DEBUG_CACHE_TREE
420420
fprintf(stderr, "cache-tree update-one (%d ent, %d subtree) %s\n",
421421
it->entry_count, it->subtree_nr,
422422
oid_to_hex(&it->oid));
@@ -455,7 +455,7 @@ static void write_one(struct strbuf *buffer, struct cache_tree *it,
455455
strbuf_add(buffer, path, pathlen);
456456
strbuf_addf(buffer, "%c%d %d\n", 0, it->entry_count, it->subtree_nr);
457457

458-
#if DEBUG
458+
#if DEBUG_CACHE_TREE
459459
if (0 <= it->entry_count)
460460
fprintf(stderr, "cache-tree <%.*s> (%d ent, %d subtree) %s\n",
461461
pathlen, path, it->entry_count, it->subtree_nr,
@@ -529,7 +529,7 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
529529
size -= rawsz;
530530
}
531531

532-
#if DEBUG
532+
#if DEBUG_CACHE_TREE
533533
if (0 <= it->entry_count)
534534
fprintf(stderr, "cache-tree <%s> (%d ent, %d subtree) %s\n",
535535
*buffer, it->entry_count, subtree_nr,

compat/mingw.c

Lines changed: 82 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,10 @@ static int try_shell_exec(const char *cmd, char *const *argv)
14461446
prog = path_lookup(interpr, 1);
14471447
if (prog) {
14481448
int argc = 0;
1449-
const char **argv2;
1449+
#ifndef _MSC_VER
1450+
const
1451+
#endif
1452+
char **argv2;
14501453
while (argv[argc]) argc++;
14511454
ALLOC_ARRAY(argv2, argc + 1);
14521455
argv2[0] = (char *)cmd; /* full path to the script file */
@@ -2127,8 +2130,34 @@ int mingw_raise(int sig)
21272130
sigint_fn(SIGINT);
21282131
return 0;
21292132

2133+
#if defined(_MSC_VER)
2134+
/*
2135+
* <signal.h> in the CRT defines 8 signals as being
2136+
* supported on the platform. Anything else causes
2137+
* an "Invalid signal or error" (which in DEBUG builds
2138+
* causes the Abort/Retry/Ignore dialog). We by-pass
2139+
* the CRT for things we already know will fail.
2140+
*/
2141+
/*case SIGINT:*/
2142+
case SIGILL:
2143+
case SIGFPE:
2144+
case SIGSEGV:
2145+
case SIGTERM:
2146+
case SIGBREAK:
2147+
case SIGABRT:
2148+
case SIGABRT_COMPAT:
2149+
return raise(sig);
2150+
default:
2151+
errno = EINVAL;
2152+
return -1;
2153+
2154+
#else
2155+
21302156
default:
21312157
return raise(sig);
2158+
2159+
#endif
2160+
21322161
}
21332162
}
21342163

@@ -2440,19 +2469,42 @@ static void maybe_redirect_std_handles(void)
24402469
GENERIC_WRITE, FILE_FLAG_NO_BUFFERING);
24412470
}
24422471

2443-
void mingw_startup(void)
2472+
#ifdef _MSC_VER
2473+
#ifdef _DEBUG
2474+
#include <crtdbg.h>
2475+
#endif
2476+
#endif
2477+
2478+
#ifdef _DEBUG
2479+
#include <crtdbg.h>
2480+
#endif
2481+
2482+
/*
2483+
* We implement wmain() and compile with -municode, which would
2484+
* normally ignore main(), but we call the latter from the former
2485+
* so that we can handle non-ASCII command-line parameters
2486+
* appropriately.
2487+
*
2488+
* To be more compatible with the core git code, we convert
2489+
* argv into UTF8 and pass them directly to main().
2490+
*/
2491+
int wmain(int argc, const wchar_t **wargv)
24442492
{
2445-
int i, maxlen, argc;
2446-
char *buffer;
2447-
wchar_t **wenv, **wargv;
2448-
_startupinfo si;
2493+
int i, maxlen, exit_status;
2494+
char *buffer, **save;
2495+
const char **argv;
24492496

2450-
maybe_redirect_std_handles();
2497+
#ifdef _MSC_VER
2498+
#ifdef _DEBUG
2499+
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
2500+
#endif
24512501

2452-
/* get wide char arguments and environment */
2453-
si.newmode = 0;
2454-
if (__wgetmainargs(&argc, &wargv, &wenv, _CRT_glob, &si) < 0)
2455-
die_startup();
2502+
#ifdef USE_MSVC_CRTDBG
2503+
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
2504+
#endif
2505+
#endif
2506+
2507+
maybe_redirect_std_handles();
24562508

24572509
/* determine size of argv and environ conversion buffer */
24582510
maxlen = wcslen(wargv[0]);
@@ -2463,9 +2515,16 @@ void mingw_startup(void)
24632515
maxlen = 3 * maxlen + 1;
24642516
buffer = malloc_startup(maxlen);
24652517

2466-
/* convert command line arguments and environment to UTF-8 */
2518+
/*
2519+
* Create a UTF-8 version of w_argv. Also create a "save" copy
2520+
* to remember all the string pointers because parse_options()
2521+
* will remove claimed items from the argv that we pass down.
2522+
*/
2523+
ALLOC_ARRAY(argv, argc + 1);
2524+
ALLOC_ARRAY(save, argc + 1);
24672525
for (i = 0; i < argc; i++)
2468-
__argv[i] = wcstoutfdup_startup(buffer, wargv[i], maxlen);
2526+
argv[i] = save[i] = wcstoutfdup_startup(buffer, wargv[i], maxlen);
2527+
argv[i] = save[i] = NULL;
24692528
free(buffer);
24702529

24712530
/* fix Windows specific environment settings */
@@ -2484,6 +2543,16 @@ void mingw_startup(void)
24842543

24852544
/* initialize Unicode console */
24862545
winansi_init();
2546+
2547+
/* invoke the real main() using our utf8 version of argv. */
2548+
exit_status = main(argc, argv);
2549+
2550+
for (i = 0; i < argc; i++)
2551+
free(save[i]);
2552+
free(save);
2553+
free(argv);
2554+
2555+
return exit_status;
24872556
}
24882557

24892558
int uname(struct utsname *buf)

compat/mingw.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,13 @@ static inline int getrlimit(int resource, struct rlimit *rlp)
361361
#ifndef __MINGW64_VERSION_MAJOR
362362
#define off_t off64_t
363363
#define lseek _lseeki64
364+
#ifndef _MSC_VER
364365
struct timespec {
365366
time_t tv_sec;
366367
long tv_nsec;
367368
};
368369
#endif
370+
#endif
369371

370372
struct mingw_stat {
371373
_dev_t st_dev;
@@ -589,18 +591,18 @@ int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen);
589591
extern CRITICAL_SECTION pinfo_cs;
590592

591593
/*
592-
* A replacement of main() that adds win32 specific initialization.
594+
* Git, like most portable C applications, implements a main() function. On
595+
* Windows, this main() function would receive parameters encoded in the
596+
* current locale, but Git for Windows would prefer UTF-8 encoded parameters.
597+
*
598+
* To make that happen, we still declare main() here, and then declare and
599+
* implement wmain() (which is the Unicode variant of main()) and compile with
600+
* -municode. This wmain() function reencodes the parameters from UTF-16 to
601+
* UTF-8 format, sets up a couple of other things as required on Windows, and
602+
* then hands off to the main() function.
593603
*/
594-
595-
void mingw_startup(void);
596-
#define main(c,v) dummy_decl_mingw_main(void); \
597-
static int mingw_main(c,v); \
598-
int main(int argc, const char **argv) \
599-
{ \
600-
mingw_startup(); \
601-
return mingw_main(__argc, (void *)__argv); \
602-
} \
603-
static int mingw_main(c,v)
604+
int wmain(int argc, const wchar_t **w_argv);
605+
int main(int argc, const char **argv);
604606

605607
/*
606608
* 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
@@ -24,6 +28,12 @@ static __inline int strcasecmp (const char *s1, const char *s2)
2428

2529
#undef ERROR
2630

31+
#define ftello _ftelli64
32+
33+
typedef int sigset_t;
34+
/* open for reading, writing, or both (not in fcntl.h) */
35+
#define O_ACCMODE (_O_RDONLY | _O_WRONLY | _O_RDWR)
36+
2737
#include "compat/mingw.h"
2838

2939
#endif

compat/obstack.h

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

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)