Skip to content

Commit 530a7f0

Browse files
jeffhostetlerdscho
authored andcommitted
Merge branch 'msvc'
Signed-off-by: Johannes Schindelin <[email protected]>
2 parents ed48192 + 307b482 commit 530a7f0

18 files changed

+615
-56
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
@@ -227,5 +227,10 @@
227227
*.user
228228
*.idb
229229
*.pdb
230+
*.ilk
231+
*.iobj
232+
*.ipdb
233+
*.dll
234+
.vs/
230235
/Debug/
231236
/Release/

Makefile

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

12051205
ifdef SANE_TOOL_PATH
12061206
SANE_TOOL_PATH_SQ = $(subst ','\'',$(SANE_TOOL_PATH))
1207-
BROKEN_PATH_FIX = 's|^\# @@BROKEN_PATH_FIX@@$$|git_broken_path_fix $(SANE_TOOL_PATH_SQ)|'
1207+
BROKEN_PATH_FIX = 's|^\# @@BROKEN_PATH_FIX@@$$|git_broken_path_fix "$(SANE_TOOL_PATH_SQ)"|'
12081208
PATH := $(SANE_TOOL_PATH):${PATH}
12091209
else
12101210
BROKEN_PATH_FIX = '/^\# @@BROKEN_PATH_FIX@@$$/d'
@@ -2789,6 +2789,33 @@ install: all
27892789
$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
27902790
$(INSTALL) -m 644 $(SCRIPT_LIB) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
27912791
$(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)'
2792+
ifdef MSVC
2793+
# We DO NOT install the individual foo.o.pdb files because they
2794+
# have already been rolled up into the exe's pdb file.
2795+
# We DO NOT have pdb files for the builtin commands (like git-status.exe)
2796+
# because it is just a copy/hardlink of git.exe, rather than a unique binary.
2797+
$(INSTALL) git.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2798+
$(INSTALL) git-shell.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2799+
$(INSTALL) git-upload-pack.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2800+
$(INSTALL) git-credential-store.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2801+
$(INSTALL) git-daemon.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2802+
$(INSTALL) git-fast-import.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2803+
$(INSTALL) git-http-backend.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2804+
$(INSTALL) git-http-fetch.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2805+
$(INSTALL) git-http-push.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2806+
$(INSTALL) git-imap-send.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2807+
$(INSTALL) git-remote-http.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2808+
$(INSTALL) git-remote-testsvn.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2809+
$(INSTALL) git-sh-i18n--envsubst.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2810+
$(INSTALL) git-show-index.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2811+
ifndef DEBUG
2812+
$(INSTALL) $(vcpkg_rel_bin)/*.dll '$(DESTDIR_SQ)$(bindir_SQ)'
2813+
$(INSTALL) $(vcpkg_rel_bin)/*.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2814+
else
2815+
$(INSTALL) $(vcpkg_dbg_bin)/*.dll '$(DESTDIR_SQ)$(bindir_SQ)'
2816+
$(INSTALL) $(vcpkg_dbg_bin)/*.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2817+
endif
2818+
endif
27922819
$(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
27932820
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mergetools_instdir_SQ)'
27942821
$(INSTALL) -m 644 mergetools/* '$(DESTDIR_SQ)$(mergetools_instdir_SQ)'
@@ -3000,6 +3027,19 @@ endif
30003027
$(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-LDFLAGS GIT-BUILD-OPTIONS
30013028
$(RM) GIT-USER-AGENT GIT-PREFIX
30023029
$(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PERL-HEADER GIT-PYTHON-VARS
3030+
ifdef MSVC
3031+
$(RM) $(patsubst %.o,%.o.pdb,$(OBJECTS))
3032+
$(RM) $(patsubst %.exe,%.pdb,$(OTHER_PROGRAMS))
3033+
$(RM) $(patsubst %.exe,%.iobj,$(OTHER_PROGRAMS))
3034+
$(RM) $(patsubst %.exe,%.ipdb,$(OTHER_PROGRAMS))
3035+
$(RM) $(patsubst %.exe,%.pdb,$(PROGRAMS))
3036+
$(RM) $(patsubst %.exe,%.iobj,$(PROGRAMS))
3037+
$(RM) $(patsubst %.exe,%.ipdb,$(PROGRAMS))
3038+
$(RM) $(patsubst %.exe,%.pdb,$(TEST_PROGRAMS))
3039+
$(RM) $(patsubst %.exe,%.iobj,$(TEST_PROGRAMS))
3040+
$(RM) $(patsubst %.exe,%.ipdb,$(TEST_PROGRAMS))
3041+
$(RM) compat/vcbuild/MSVC-DEFS-GEN
3042+
endif
30033043

30043044
.PHONY: all install profile-clean cocciclean clean strip
30053045
.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
@@ -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: 80 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,7 +1580,10 @@ static int try_shell_exec(const char *cmd, char *const *argv)
15801580
prog = path_lookup(interpr, 1);
15811581
if (prog) {
15821582
int argc = 0;
1583-
const char **argv2;
1583+
#ifndef _MSC_VER
1584+
const
1585+
#endif
1586+
char **argv2;
15841587
while (argv[argc]) argc++;
15851588
ALLOC_ARRAY(argv2, argc + 1);
15861589
argv2[0] = (char *)cmd; /* full path to the script file */
@@ -2135,8 +2138,34 @@ int mingw_raise(int sig)
21352138
sigint_fn(SIGINT);
21362139
return 0;
21372140

2141+
#if defined(_MSC_VER)
2142+
/*
2143+
* <signal.h> in the CRT defines 8 signals as being
2144+
* supported on the platform. Anything else causes
2145+
* an "Invalid signal or error" (which in DEBUG builds
2146+
* causes the Abort/Retry/Ignore dialog). We by-pass
2147+
* the CRT for things we already know will fail.
2148+
*/
2149+
/*case SIGINT:*/
2150+
case SIGILL:
2151+
case SIGFPE:
2152+
case SIGSEGV:
2153+
case SIGTERM:
2154+
case SIGBREAK:
2155+
case SIGABRT:
2156+
case SIGABRT_COMPAT:
2157+
return raise(sig);
2158+
default:
2159+
errno = EINVAL;
2160+
return -1;
2161+
2162+
#else
2163+
21382164
default:
21392165
return raise(sig);
2166+
2167+
#endif
2168+
21402169
}
21412170
}
21422171

@@ -2347,18 +2376,13 @@ static void setup_windows_environment(void)
23472376
setenv("TERM", "cygwin", 1);
23482377
}
23492378

2379+
#if !defined(_MSC_VER)
23502380
/*
23512381
* Disable MSVCRT command line wildcard expansion (__getmainargs called from
23522382
* mingw startup code, see init.c in mingw runtime).
23532383
*/
23542384
int _CRT_glob = 0;
2355-
2356-
typedef struct {
2357-
int newmode;
2358-
} _startupinfo;
2359-
2360-
extern int __wgetmainargs(int *argc, wchar_t ***argv, wchar_t ***env, int glob,
2361-
_startupinfo *si);
2385+
#endif
23622386

23632387
static NORETURN void die_startup(void)
23642388
{
@@ -2436,19 +2460,38 @@ static void maybe_redirect_std_handles(void)
24362460
GENERIC_WRITE, FILE_FLAG_NO_BUFFERING);
24372461
}
24382462

2439-
void mingw_startup(void)
2463+
#ifdef _MSC_VER
2464+
#ifdef _DEBUG
2465+
#include <crtdbg.h>
2466+
#endif
2467+
#endif
2468+
2469+
/*
2470+
* We implement wmain() and compile with -municode, which would
2471+
* normally ignore main(), but we call the latter from the former
2472+
* so that we can handle non-ASCII command-line parameters
2473+
* appropriately.
2474+
*
2475+
* To be more compatible with the core git code, we convert
2476+
* argv into UTF8 and pass them directly to main().
2477+
*/
2478+
int wmain(int argc, const wchar_t **wargv)
24402479
{
2441-
int i, maxlen, argc;
2442-
char *buffer;
2443-
wchar_t **wenv, **wargv;
2444-
_startupinfo si;
2480+
int i, maxlen, exit_status;
2481+
char *buffer, **save;
2482+
const char **argv;
24452483

2446-
maybe_redirect_std_handles();
2484+
#ifdef _MSC_VER
2485+
#ifdef _DEBUG
2486+
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
2487+
#endif
24472488

2448-
/* get wide char arguments and environment */
2449-
si.newmode = 0;
2450-
if (__wgetmainargs(&argc, &wargv, &wenv, _CRT_glob, &si) < 0)
2451-
die_startup();
2489+
#ifdef USE_MSVC_CRTDBG
2490+
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
2491+
#endif
2492+
#endif
2493+
2494+
maybe_redirect_std_handles();
24522495

24532496
/* determine size of argv and environ conversion buffer */
24542497
maxlen = wcslen(wargv[0]);
@@ -2459,9 +2502,16 @@ void mingw_startup(void)
24592502
maxlen = 3 * maxlen + 1;
24602503
buffer = malloc_startup(maxlen);
24612504

2462-
/* convert command line arguments and environment to UTF-8 */
2505+
/*
2506+
* Create a UTF-8 version of w_argv. Also create a "save" copy
2507+
* to remember all the string pointers because parse_options()
2508+
* will remove claimed items from the argv that we pass down.
2509+
*/
2510+
ALLOC_ARRAY(argv, argc + 1);
2511+
ALLOC_ARRAY(save, argc + 1);
24632512
for (i = 0; i < argc; i++)
2464-
__argv[i] = wcstoutfdup_startup(buffer, wargv[i], maxlen);
2513+
argv[i] = save[i] = wcstoutfdup_startup(buffer, wargv[i], maxlen);
2514+
argv[i] = save[i] = NULL;
24652515
free(buffer);
24662516

24672517
/* fix Windows specific environment settings */
@@ -2480,6 +2530,16 @@ void mingw_startup(void)
24802530

24812531
/* initialize Unicode console */
24822532
winansi_init();
2533+
2534+
/* invoke the real main() using our utf8 version of argv. */
2535+
exit_status = main(argc, argv);
2536+
2537+
for (i = 0; i < argc; i++)
2538+
free(save[i]);
2539+
free(save);
2540+
free(argv);
2541+
2542+
return exit_status;
24832543
}
24842544

24852545
int uname(struct utsname *buf)

compat/mingw.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,13 @@ static inline int getrlimit(int resource, struct rlimit *rlp)
372372
#ifndef __MINGW64_VERSION_MAJOR
373373
#define off_t off64_t
374374
#define lseek _lseeki64
375+
#ifndef _MSC_VER
375376
struct timespec {
376377
time_t tv_sec;
377378
long tv_nsec;
378379
};
379380
#endif
381+
#endif
380382

381383
struct mingw_stat {
382384
_dev_t st_dev;
@@ -602,18 +604,18 @@ int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen);
602604
extern CRITICAL_SECTION pinfo_cs;
603605

604606
/*
605-
* A replacement of main() that adds win32 specific initialization.
607+
* Git, like most portable C applications, implements a main() function. On
608+
* Windows, this main() function would receive parameters encoded in the
609+
* current locale, but Git for Windows would prefer UTF-8 encoded parameters.
610+
*
611+
* To make that happen, we still declare main() here, and then declare and
612+
* implement wmain() (which is the Unicode variant of main()) and compile with
613+
* -municode. This wmain() function reencodes the parameters from UTF-16 to
614+
* UTF-8 format, sets up a couple of other things as required on Windows, and
615+
* then hands off to the main() function.
606616
*/
607-
608-
void mingw_startup(void);
609-
#define main(c,v) dummy_decl_mingw_main(void); \
610-
static int mingw_main(c,v); \
611-
int main(int argc, const char **argv) \
612-
{ \
613-
mingw_startup(); \
614-
return mingw_main(__argc, (void *)__argv); \
615-
} \
616-
static int mingw_main(c,v)
617+
int wmain(int argc, const wchar_t **w_argv);
618+
int main(int argc, const char **argv);
617619

618620
/*
619621
* For debugging: if a problem occurs, say, in a Git process that is spawned

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
@@ -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)