Skip to content

Commit 1169e1e

Browse files
jeffhostetlerdscho
authored andcommitted
Merge branch 'msvc'
Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 573dbb1 + ba53545 commit 1169e1e

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
@@ -228,6 +228,11 @@
228228
*.user
229229
*.idb
230230
*.pdb
231+
*.ilk
232+
*.iobj
233+
*.ipdb
234+
*.dll
235+
.vs/
231236
/Debug/
232237
/Release/
233238
*.dSYM

Makefile

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

12301230
ifdef SANE_TOOL_PATH
12311231
SANE_TOOL_PATH_SQ = $(subst ','\'',$(SANE_TOOL_PATH))
1232-
BROKEN_PATH_FIX = 's|^\# @@BROKEN_PATH_FIX@@$$|git_broken_path_fix $(SANE_TOOL_PATH_SQ)|'
1232+
BROKEN_PATH_FIX = 's|^\# @@BROKEN_PATH_FIX@@$$|git_broken_path_fix "$(SANE_TOOL_PATH_SQ)"|'
12331233
PATH := $(SANE_TOOL_PATH):${PATH}
12341234
else
12351235
BROKEN_PATH_FIX = '/^\# @@BROKEN_PATH_FIX@@$$/d'
@@ -2835,6 +2835,33 @@ install: all
28352835
$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
28362836
$(INSTALL) -m 644 $(SCRIPT_LIB) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
28372837
$(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)'
2838+
ifdef MSVC
2839+
# We DO NOT install the individual foo.o.pdb files because they
2840+
# have already been rolled up into the exe's pdb file.
2841+
# We DO NOT have pdb files for the builtin commands (like git-status.exe)
2842+
# because it is just a copy/hardlink of git.exe, rather than a unique binary.
2843+
$(INSTALL) git.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2844+
$(INSTALL) git-shell.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2845+
$(INSTALL) git-upload-pack.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2846+
$(INSTALL) git-credential-store.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2847+
$(INSTALL) git-daemon.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2848+
$(INSTALL) git-fast-import.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2849+
$(INSTALL) git-http-backend.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2850+
$(INSTALL) git-http-fetch.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2851+
$(INSTALL) git-http-push.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2852+
$(INSTALL) git-imap-send.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2853+
$(INSTALL) git-remote-http.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2854+
$(INSTALL) git-remote-testsvn.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2855+
$(INSTALL) git-sh-i18n--envsubst.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2856+
$(INSTALL) git-show-index.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2857+
ifndef DEBUG
2858+
$(INSTALL) $(vcpkg_rel_bin)/*.dll '$(DESTDIR_SQ)$(bindir_SQ)'
2859+
$(INSTALL) $(vcpkg_rel_bin)/*.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2860+
else
2861+
$(INSTALL) $(vcpkg_dbg_bin)/*.dll '$(DESTDIR_SQ)$(bindir_SQ)'
2862+
$(INSTALL) $(vcpkg_dbg_bin)/*.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2863+
endif
2864+
endif
28382865
$(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
28392866
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mergetools_instdir_SQ)'
28402867
$(INSTALL) -m 644 mergetools/* '$(DESTDIR_SQ)$(mergetools_instdir_SQ)'
@@ -3046,6 +3073,19 @@ endif
30463073
$(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-LDFLAGS GIT-BUILD-OPTIONS
30473074
$(RM) GIT-USER-AGENT GIT-PREFIX
30483075
$(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PERL-HEADER GIT-PYTHON-VARS
3076+
ifdef MSVC
3077+
$(RM) $(patsubst %.o,%.o.pdb,$(OBJECTS))
3078+
$(RM) $(patsubst %.exe,%.pdb,$(OTHER_PROGRAMS))
3079+
$(RM) $(patsubst %.exe,%.iobj,$(OTHER_PROGRAMS))
3080+
$(RM) $(patsubst %.exe,%.ipdb,$(OTHER_PROGRAMS))
3081+
$(RM) $(patsubst %.exe,%.pdb,$(PROGRAMS))
3082+
$(RM) $(patsubst %.exe,%.iobj,$(PROGRAMS))
3083+
$(RM) $(patsubst %.exe,%.ipdb,$(PROGRAMS))
3084+
$(RM) $(patsubst %.exe,%.pdb,$(TEST_PROGRAMS))
3085+
$(RM) $(patsubst %.exe,%.iobj,$(TEST_PROGRAMS))
3086+
$(RM) $(patsubst %.exe,%.ipdb,$(TEST_PROGRAMS))
3087+
$(RM) compat/vcbuild/MSVC-DEFS-GEN
3088+
endif
30493089

30503090
.PHONY: all install profile-clean cocciclean clean strip
30513091
.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

@@ -2320,18 +2349,13 @@ static void setup_windows_environment(void)
23202349
setenv("TERM", "cygwin", 1);
23212350
}
23222351

2352+
#if !defined(_MSC_VER)
23232353
/*
23242354
* Disable MSVCRT command line wildcard expansion (__getmainargs called from
23252355
* mingw startup code, see init.c in mingw runtime).
23262356
*/
23272357
int _CRT_glob = 0;
2328-
2329-
typedef struct {
2330-
int newmode;
2331-
} _startupinfo;
2332-
2333-
extern int __wgetmainargs(int *argc, wchar_t ***argv, wchar_t ***env, int glob,
2334-
_startupinfo *si);
2358+
#endif
23352359

23362360
static NORETURN void die_startup(void)
23372361
{
@@ -2409,19 +2433,38 @@ static void maybe_redirect_std_handles(void)
24092433
GENERIC_WRITE, FILE_FLAG_NO_BUFFERING);
24102434
}
24112435

2412-
void mingw_startup(void)
2436+
#ifdef _MSC_VER
2437+
#ifdef _DEBUG
2438+
#include <crtdbg.h>
2439+
#endif
2440+
#endif
2441+
2442+
/*
2443+
* We implement wmain() and compile with -municode, which would
2444+
* normally ignore main(), but we call the latter from the former
2445+
* so that we can handle non-ASCII command-line parameters
2446+
* appropriately.
2447+
*
2448+
* To be more compatible with the core git code, we convert
2449+
* argv into UTF8 and pass them directly to main().
2450+
*/
2451+
int wmain(int argc, const wchar_t **wargv)
24132452
{
2414-
int i, maxlen, argc;
2415-
char *buffer;
2416-
wchar_t **wenv, **wargv;
2417-
_startupinfo si;
2453+
int i, maxlen, exit_status;
2454+
char *buffer, **save;
2455+
const char **argv;
24182456

2419-
maybe_redirect_std_handles();
2457+
#ifdef _MSC_VER
2458+
#ifdef _DEBUG
2459+
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
2460+
#endif
24202461

2421-
/* get wide char arguments and environment */
2422-
si.newmode = 0;
2423-
if (__wgetmainargs(&argc, &wargv, &wenv, _CRT_glob, &si) < 0)
2424-
die_startup();
2462+
#ifdef USE_MSVC_CRTDBG
2463+
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
2464+
#endif
2465+
#endif
2466+
2467+
maybe_redirect_std_handles();
24252468

24262469
/* determine size of argv and environ conversion buffer */
24272470
maxlen = wcslen(wargv[0]);
@@ -2432,9 +2475,16 @@ void mingw_startup(void)
24322475
maxlen = 3 * maxlen + 1;
24332476
buffer = malloc_startup(maxlen);
24342477

2435-
/* convert command line arguments and environment to UTF-8 */
2478+
/*
2479+
* Create a UTF-8 version of w_argv. Also create a "save" copy
2480+
* to remember all the string pointers because parse_options()
2481+
* will remove claimed items from the argv that we pass down.
2482+
*/
2483+
ALLOC_ARRAY(argv, argc + 1);
2484+
ALLOC_ARRAY(save, argc + 1);
24362485
for (i = 0; i < argc; i++)
2437-
__argv[i] = wcstoutfdup_startup(buffer, wargv[i], maxlen);
2486+
argv[i] = save[i] = wcstoutfdup_startup(buffer, wargv[i], maxlen);
2487+
argv[i] = save[i] = NULL;
24382488
free(buffer);
24392489

24402490
/* fix Windows specific environment settings */
@@ -2453,6 +2503,16 @@ void mingw_startup(void)
24532503

24542504
/* initialize Unicode console */
24552505
winansi_init();
2506+
2507+
/* invoke the real main() using our utf8 version of argv. */
2508+
exit_status = main(argc, argv);
2509+
2510+
for (i = 0; i < argc; i++)
2511+
free(save[i]);
2512+
free(save);
2513+
free(argv);
2514+
2515+
return exit_status;
24562516
}
24572517

24582518
int uname(struct utsname *buf)

compat/mingw.h

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

362364
struct mingw_stat {
363365
_dev_t st_dev;
@@ -563,18 +565,18 @@ int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen);
563565
extern CRITICAL_SECTION pinfo_cs;
564566

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

579581
/*
580582
* 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
@@ -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)