Skip to content

Commit bd656cc

Browse files
jeffhostetlerdscho
authored andcommitted
Merge branch 'msvc'
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2 parents 6e35431 + d38254a commit bd656cc

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
@@ -1392,7 +1392,10 @@ static int try_shell_exec(const char *cmd, char *const *argv)
13921392
prog = path_lookup(interpr, 1);
13931393
if (prog) {
13941394
int argc = 0;
1395-
const char **argv2;
1395+
#ifndef _MSC_VER
1396+
const
1397+
#endif
1398+
char **argv2;
13961399
while (argv[argc]) argc++;
13971400
ALLOC_ARRAY(argv2, argc + 1);
13981401
argv2[0] = (char *)cmd; /* full path to the script file */
@@ -2073,8 +2076,34 @@ int mingw_raise(int sig)
20732076
sigint_fn(SIGINT);
20742077
return 0;
20752078

2079+
#if defined(_MSC_VER)
2080+
/*
2081+
* <signal.h> in the CRT defines 8 signals as being
2082+
* supported on the platform. Anything else causes
2083+
* an "Invalid signal or error" (which in DEBUG builds
2084+
* causes the Abort/Retry/Ignore dialog). We by-pass
2085+
* the CRT for things we already know will fail.
2086+
*/
2087+
/*case SIGINT:*/
2088+
case SIGILL:
2089+
case SIGFPE:
2090+
case SIGSEGV:
2091+
case SIGTERM:
2092+
case SIGBREAK:
2093+
case SIGABRT:
2094+
case SIGABRT_COMPAT:
2095+
return raise(sig);
2096+
default:
2097+
errno = EINVAL;
2098+
return -1;
2099+
2100+
#else
2101+
20762102
default:
20772103
return raise(sig);
2104+
2105+
#endif
2106+
20782107
}
20792108
}
20802109

@@ -2386,19 +2415,42 @@ static void maybe_redirect_std_handles(void)
23862415
GENERIC_WRITE, FILE_FLAG_NO_BUFFERING);
23872416
}
23882417

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

2396-
maybe_redirect_std_handles();
2443+
#ifdef _MSC_VER
2444+
#ifdef _DEBUG
2445+
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
2446+
#endif
23972447

2398-
/* get wide char arguments and environment */
2399-
si.newmode = 0;
2400-
if (__wgetmainargs(&argc, &wargv, &wenv, _CRT_glob, &si) < 0)
2401-
die_startup();
2448+
#ifdef USE_MSVC_CRTDBG
2449+
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
2450+
#endif
2451+
#endif
2452+
2453+
maybe_redirect_std_handles();
24022454

24032455
/* determine size of argv and environ conversion buffer */
24042456
maxlen = wcslen(wargv[0]);
@@ -2409,9 +2461,16 @@ void mingw_startup(void)
24092461
maxlen = 3 * maxlen + 1;
24102462
buffer = malloc_startup(maxlen);
24112463

2412-
/* convert command line arguments and environment to UTF-8 */
2464+
/*
2465+
* Create a UTF-8 version of w_argv. Also create a "save" copy
2466+
* to remember all the string pointers because parse_options()
2467+
* will remove claimed items from the argv that we pass down.
2468+
*/
2469+
ALLOC_ARRAY(argv, argc + 1);
2470+
ALLOC_ARRAY(save, argc + 1);
24132471
for (i = 0; i < argc; i++)
2414-
__argv[i] = wcstoutfdup_startup(buffer, wargv[i], maxlen);
2472+
argv[i] = save[i] = wcstoutfdup_startup(buffer, wargv[i], maxlen);
2473+
argv[i] = save[i] = NULL;
24152474
free(buffer);
24162475

24172476
/* fix Windows specific environment settings */
@@ -2428,6 +2487,16 @@ void mingw_startup(void)
24282487

24292488
/* initialize Unicode console */
24302489
winansi_init();
2490+
2491+
/* invoke the real main() using our utf8 version of argv. */
2492+
exit_status = main(argc, argv);
2493+
2494+
for (i = 0; i < argc; i++)
2495+
free(save[i]);
2496+
free(save);
2497+
free(argv);
2498+
2499+
return exit_status;
24312500
}
24322501

24332502
int uname(struct utsname *buf)

compat/mingw.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,13 @@ static inline int getrlimit(int resource, struct rlimit *rlp)
358358
#ifndef __MINGW64_VERSION_MAJOR
359359
#define off_t off64_t
360360
#define lseek _lseeki64
361+
#ifndef _MSC_VER
361362
struct timespec {
362363
time_t tv_sec;
363364
long tv_nsec;
364365
};
365366
#endif
367+
#endif
366368

367369
struct mingw_stat {
368370
_dev_t st_dev;
@@ -583,18 +585,18 @@ int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen);
583585
extern CRITICAL_SECTION pinfo_cs;
584586

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

599601
/*
600602
* 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)