Skip to content

Commit cddcf33

Browse files
jeffhostetlerdscho
authored andcommitted
Merge branch 'msvc'
Signed-off-by: Johannes Schindelin <[email protected]>
2 parents c26853b + ad06cbe commit cddcf33

18 files changed

+614
-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
@@ -1242,7 +1242,7 @@ endif
12421242

12431243
ifdef SANE_TOOL_PATH
12441244
SANE_TOOL_PATH_SQ = $(subst ','\'',$(SANE_TOOL_PATH))
1245-
BROKEN_PATH_FIX = 's|^\# @@BROKEN_PATH_FIX@@$$|git_broken_path_fix $(SANE_TOOL_PATH_SQ)|'
1245+
BROKEN_PATH_FIX = 's|^\# @@BROKEN_PATH_FIX@@$$|git_broken_path_fix "$(SANE_TOOL_PATH_SQ)"|'
12461246
PATH := $(SANE_TOOL_PATH):${PATH}
12471247
else
12481248
BROKEN_PATH_FIX = '/^\# @@BROKEN_PATH_FIX@@$$/d'
@@ -2875,6 +2875,33 @@ install: all
28752875
$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
28762876
$(INSTALL) -m 644 $(SCRIPT_LIB) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
28772877
$(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)'
2878+
ifdef MSVC
2879+
# We DO NOT install the individual foo.o.pdb files because they
2880+
# have already been rolled up into the exe's pdb file.
2881+
# We DO NOT have pdb files for the builtin commands (like git-status.exe)
2882+
# because it is just a copy/hardlink of git.exe, rather than a unique binary.
2883+
$(INSTALL) git.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2884+
$(INSTALL) git-shell.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2885+
$(INSTALL) git-upload-pack.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2886+
$(INSTALL) git-credential-store.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2887+
$(INSTALL) git-daemon.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2888+
$(INSTALL) git-fast-import.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2889+
$(INSTALL) git-http-backend.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2890+
$(INSTALL) git-http-fetch.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2891+
$(INSTALL) git-http-push.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2892+
$(INSTALL) git-imap-send.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2893+
$(INSTALL) git-remote-http.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2894+
$(INSTALL) git-remote-testsvn.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2895+
$(INSTALL) git-sh-i18n--envsubst.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2896+
$(INSTALL) git-show-index.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2897+
ifndef DEBUG
2898+
$(INSTALL) $(vcpkg_rel_bin)/*.dll '$(DESTDIR_SQ)$(bindir_SQ)'
2899+
$(INSTALL) $(vcpkg_rel_bin)/*.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2900+
else
2901+
$(INSTALL) $(vcpkg_dbg_bin)/*.dll '$(DESTDIR_SQ)$(bindir_SQ)'
2902+
$(INSTALL) $(vcpkg_dbg_bin)/*.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2903+
endif
2904+
endif
28782905
$(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
28792906
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mergetools_instdir_SQ)'
28802907
$(INSTALL) -m 644 mergetools/* '$(DESTDIR_SQ)$(mergetools_instdir_SQ)'
@@ -3087,6 +3114,19 @@ endif
30873114
$(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-LDFLAGS GIT-BUILD-OPTIONS
30883115
$(RM) GIT-USER-AGENT GIT-PREFIX
30893116
$(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PERL-HEADER GIT-PYTHON-VARS
3117+
ifdef MSVC
3118+
$(RM) $(patsubst %.o,%.o.pdb,$(OBJECTS))
3119+
$(RM) $(patsubst %.exe,%.pdb,$(OTHER_PROGRAMS))
3120+
$(RM) $(patsubst %.exe,%.iobj,$(OTHER_PROGRAMS))
3121+
$(RM) $(patsubst %.exe,%.ipdb,$(OTHER_PROGRAMS))
3122+
$(RM) $(patsubst %.exe,%.pdb,$(PROGRAMS))
3123+
$(RM) $(patsubst %.exe,%.iobj,$(PROGRAMS))
3124+
$(RM) $(patsubst %.exe,%.ipdb,$(PROGRAMS))
3125+
$(RM) $(patsubst %.exe,%.pdb,$(TEST_PROGRAMS))
3126+
$(RM) $(patsubst %.exe,%.iobj,$(TEST_PROGRAMS))
3127+
$(RM) $(patsubst %.exe,%.ipdb,$(TEST_PROGRAMS))
3128+
$(RM) compat/vcbuild/MSVC-DEFS-GEN
3129+
endif
30903130

30913131
.PHONY: all install profile-clean cocciclean clean strip
30923132
.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
@@ -7,8 +7,8 @@
77
#include "replace-object.h"
88
#include "promisor-remote.h"
99

10-
#ifndef DEBUG
11-
#define DEBUG 0
10+
#ifndef DEBUG_CACHE_TREE
11+
#define DEBUG_CACHE_TREE 0
1212
#endif
1313

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

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

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

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

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

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

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

compat/mingw.c

Lines changed: 80 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,10 @@ static int try_shell_exec(const char *cmd, char *const *argv)
15811581
if (prog) {
15821582
int exec_id;
15831583
int argc = 0;
1584-
const char **argv2;
1584+
#ifndef _MSC_VER
1585+
const
1586+
#endif
1587+
char **argv2;
15851588
while (argv[argc]) argc++;
15861589
ALLOC_ARRAY(argv2, argc + 1);
15871590
argv2[0] = (char *)cmd; /* full path to the script file */
@@ -2144,8 +2147,34 @@ int mingw_raise(int sig)
21442147
sigint_fn(SIGINT);
21452148
return 0;
21462149

2150+
#if defined(_MSC_VER)
2151+
/*
2152+
* <signal.h> in the CRT defines 8 signals as being
2153+
* supported on the platform. Anything else causes
2154+
* an "Invalid signal or error" (which in DEBUG builds
2155+
* causes the Abort/Retry/Ignore dialog). We by-pass
2156+
* the CRT for things we already know will fail.
2157+
*/
2158+
/*case SIGINT:*/
2159+
case SIGILL:
2160+
case SIGFPE:
2161+
case SIGSEGV:
2162+
case SIGTERM:
2163+
case SIGBREAK:
2164+
case SIGABRT:
2165+
case SIGABRT_COMPAT:
2166+
return raise(sig);
2167+
default:
2168+
errno = EINVAL;
2169+
return -1;
2170+
2171+
#else
2172+
21472173
default:
21482174
return raise(sig);
2175+
2176+
#endif
2177+
21492178
}
21502179
}
21512180

@@ -2329,18 +2358,13 @@ static void setup_windows_environment(void)
23292358
setenv("TERM", "cygwin", 1);
23302359
}
23312360

2361+
#if !defined(_MSC_VER)
23322362
/*
23332363
* Disable MSVCRT command line wildcard expansion (__getmainargs called from
23342364
* mingw startup code, see init.c in mingw runtime).
23352365
*/
23362366
int _CRT_glob = 0;
2337-
2338-
typedef struct {
2339-
int newmode;
2340-
} _startupinfo;
2341-
2342-
extern int __wgetmainargs(int *argc, wchar_t ***argv, wchar_t ***env, int glob,
2343-
_startupinfo *si);
2367+
#endif
23442368

23452369
static NORETURN void die_startup(void)
23462370
{
@@ -2418,21 +2442,40 @@ static void maybe_redirect_std_handles(void)
24182442
GENERIC_WRITE, FILE_FLAG_NO_BUFFERING);
24192443
}
24202444

2421-
void mingw_startup(void)
2445+
#ifdef _MSC_VER
2446+
#ifdef _DEBUG
2447+
#include <crtdbg.h>
2448+
#endif
2449+
#endif
2450+
2451+
/*
2452+
* We implement wmain() and compile with -municode, which would
2453+
* normally ignore main(), but we call the latter from the former
2454+
* so that we can handle non-ASCII command-line parameters
2455+
* appropriately.
2456+
*
2457+
* To be more compatible with the core git code, we convert
2458+
* argv into UTF8 and pass them directly to main().
2459+
*/
2460+
int wmain(int argc, const wchar_t **wargv)
24222461
{
2423-
int i, maxlen, argc;
2424-
char *buffer;
2425-
wchar_t **wenv, **wargv;
2426-
_startupinfo si;
2462+
int i, maxlen, exit_status;
2463+
char *buffer, **save;
2464+
const char **argv;
24272465

24282466
trace2_initialize_clock();
24292467

2430-
maybe_redirect_std_handles();
2468+
#ifdef _MSC_VER
2469+
#ifdef _DEBUG
2470+
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
2471+
#endif
24312472

2432-
/* get wide char arguments and environment */
2433-
si.newmode = 0;
2434-
if (__wgetmainargs(&argc, &wargv, &wenv, _CRT_glob, &si) < 0)
2435-
die_startup();
2473+
#ifdef USE_MSVC_CRTDBG
2474+
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
2475+
#endif
2476+
#endif
2477+
2478+
maybe_redirect_std_handles();
24362479

24372480
/* determine size of argv and environ conversion buffer */
24382481
maxlen = wcslen(wargv[0]);
@@ -2443,9 +2486,16 @@ void mingw_startup(void)
24432486
maxlen = 3 * maxlen + 1;
24442487
buffer = malloc_startup(maxlen);
24452488

2446-
/* convert command line arguments and environment to UTF-8 */
2489+
/*
2490+
* Create a UTF-8 version of w_argv. Also create a "save" copy
2491+
* to remember all the string pointers because parse_options()
2492+
* will remove claimed items from the argv that we pass down.
2493+
*/
2494+
ALLOC_ARRAY(argv, argc + 1);
2495+
ALLOC_ARRAY(save, argc + 1);
24472496
for (i = 0; i < argc; i++)
2448-
__argv[i] = wcstoutfdup_startup(buffer, wargv[i], maxlen);
2497+
argv[i] = save[i] = wcstoutfdup_startup(buffer, wargv[i], maxlen);
2498+
argv[i] = save[i] = NULL;
24492499
free(buffer);
24502500

24512501
/* fix Windows specific environment settings */
@@ -2464,6 +2514,16 @@ void mingw_startup(void)
24642514

24652515
/* initialize Unicode console */
24662516
winansi_init();
2517+
2518+
/* invoke the real main() using our utf8 version of argv. */
2519+
exit_status = main(argc, argv);
2520+
2521+
for (i = 0; i < argc; i++)
2522+
free(save[i]);
2523+
free(save);
2524+
free(argv);
2525+
2526+
return exit_status;
24672527
}
24682528

24692529
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
* 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)