Using VC build git (new patch)
New patch.
pull from git://repo.or.cz/tgit.git
branch vcpatch
From 3136d3b72e199ad1484629e8ff4563a918cad953 Mon Sep 17 00:00:00 2001
From: Frank Li <[email protected]>
Date: Tue, 4 Aug 2009 23:53:38 +0800
Subject: [PATCH] Enable Visual Studio 2008 Build Git
Enable VC Build Git. Reuse many msysgit porting working. Build Git need some external library, such zlib. Please read Readme to get how to build git with VS2008
--- builtin-fast-export.c | 1 + compat/fnmatch/fnmatch.c | 2 + compat/mingw.c | 68 ++- compat/mingw.h | 21 +- compat/regex/regex.c | 8 +- compat/snprintf.c | 7 +- compat/vcbuild/.gitignore | 3 + compat/vcbuild/ReadMe | 13 + compat/vcbuild/git/git.vcproj | 197 +++++ compat/vcbuild/include/dirent.h | 127 ++++ compat/vcbuild/include/unistd.h | 174 +++++ compat/vcbuild/libgit/libgit.vcproj | 1347 +++++++++++++++++++++++++++++++++++ compat/vcbuild/porting.c | 13 + compat/vcbuild/sys/time.h | 21 + compat/winansi.c | 8 + git-compat-util.h | 2 +- help.c | 5 +- pager.c | 4 +- run-command.c | 11 +- run-command.h | 2 +- setup.c | 2 +- 21 files changed, 2011 insertions(+), 25 deletions(-) create mode 100644 compat/vcbuild/.gitignore create mode 100644 compat/vcbuild/ReadMe create mode 100644 compat/vcbuild/git/git.vcproj create mode 100644 compat/vcbuild/include/dirent.h create mode 100644 compat/vcbuild/include/unistd.h create mode 100644 compat/vcbuild/include/utime.h create mode 100644 compat/vcbuild/libgit/libgit.vcproj create mode 100644 compat/vcbuild/porting.c create mode 100644 compat/vcbuild/sys/param.h create mode 100644 compat/vcbuild/sys/socket.h create mode 100644 compat/vcbuild/sys/time.h
builtin-fast-export.c +1 -0
@@ -24,6 +24,7 @@ static const char *fast_export_usage[] = {static int progress;static enum {ABORT ,VERBATIM ,WARN ,STRIP } signed_tag_mode =ABORT ; +#undef ERRORstatic enum {ERROR ,DROP ,REWRITE } tag_of_filtered_mode =ABORT ;static int fake_missing_tagger;
compat/fnmatch/fnmatch.c +2 -0
@@ -16,6 +16,8 @@write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "git-compat-util.h" +#if HAVE_CONFIG_H # include <config.h> #endif
compat/mingw.c +61 -7
132 lines not on this page · raw message
compat/mingw.h +20 -1
@@ -171,14 +171,31 @@ int mingw_getpagesize(void);/* Use mingw_lstat() instead of lstat()/stat() and * mingw_fstat() instead of fstat() on Windows. */ +#undef off_t#define off_t off64_t + +#ifdef _MSC_VER +#define stat (x,y) mingw_lstat(x,y) +#define stat _stat64 +#else #define stat _stati64 +#endif + +#undef lseek#define lseek _lseeki64 +int mingw_lstat (const char *file_name,struct stat *buf);int mingw_fstat (int fd,struct stat *buf); + +#undef fstat#define fstat mingw_fstat + +#undef lstat#define lstat mingw_lstat + +#ifndef _MSC_VER#define _stati64 (x,y) mingw_lstat(x,y) +#endif int mingw_utime (const char *file_name,const struct utimbuf *times);#define utime mingw_utime
@@ -197,7 +214,9 @@ sig_handler_t mingw_signal(int sig, sig_handler_t handler);/* * ANSI emulation wrappers */ - +#ifdef _MSC_VER +#define __attribute__ (x) +#endif int winansi_fputs (const char *str,FILE *stream);int winansi_printf (const char *format, ...) __attribute__((format (printf,1 ,2 )));int winansi_fprintf (FILE *stream,const char *format, ...) __attribute__((format (printf,2 ,3 )));
compat/regex/regex.c +3 -5
@@ -20,6 +20,8 @@Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* AIX requires this to be the first thing in the file. */ +#include "git-compat-util.h" +#if defined (_AIX) && !defined (REGEX_MALLOC )#pragma alloca#endif
@@ -4852,11 +4854,7 @@ regexec (preg, string, nmatch, pmatch, eflags)from either regcomp or regexec. We don't use PREG here. */ size_t -regerror (errcode, preg, errbuf, errbuf_size) -int errcode; -const regex_t *preg; -char *errbuf; -size_t errbuf_size; +regerror (int errcode,const regex_t * preg,char * errbuf,size_t errbuf_size) {const char *msg;size_t msg_size;
compat/snprintf.c +6 -1
@@ -6,7 +6,7 @@* number of characters to write without the trailing NUL. */ #ifndef SNPRINTF_SIZE_CORR -#if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ <4 +#if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ <4 || defined(_MSC_VER)#define SNPRINTF_SIZE_CORR 1#else #define SNPRINTF_SIZE_CORR 0
@@ -14,6 +14,11 @@#endif #undef vsnprintf + +#if defined(_MSC_VER) +#define vsnprintf _vsnprintf +#endif +int git_vsnprintf (char *str,size_t maxsize,const char *format,va_list ap) {char *s;
compat/vcbuild/.gitignore new file +3 -0
@@ -0,0 +1,3 @@ +Debug +Release +*.user
compat/vcbuild/ReadMe new file +13 -0
@@ -0,0 +1,13 @@ +The Steps of Build Git with VS2008 + +1. Create VC Build Environment. + + git clone git://repo.or.cz/gitbuild.git + + gitbuild include VS solution file and library such as zlib. + +2. Get Submodule + + git submodule update + +3. Open gitbuild\gitbuild.sln with VS2008. Then press F7.
compat/vcbuild/git/git.vcproj new file +197 -0
197 lines not on this page · raw message
compat/vcbuild/include/dirent.h new file +127 -0
127 lines not on this page · raw message
compat/vcbuild/include/unistd.h new file +174 -0
175 lines not on this page · raw message
compat/vcbuild/include/utime.h new file +0 -0
compat/vcbuild/libgit/libgit.vcproj new file +1347 -0
1,347 lines not on this page · raw message
compat/vcbuild/porting.c new file +13 -0
@@ -0,0 +1,13 @@ +#include "stdio.h" +#include "STDARG.H" +#include <string.h> +#include "dirent.h" +#include "unistd.h" + +int strcasecmp (const char *s1,const char *s2) +{ +int size1=strlen (s1); +int sisz2=strlen (s2); + +return _strnicmp (s1,s2,sisz2>size1?sisz2:size1); +}
compat/vcbuild/sys/param.h new file +0 -0
compat/vcbuild/sys/socket.h new file +0 -0
compat/vcbuild/sys/time.h new file +21 -0
@@ -0,0 +1,21 @@ +#ifndef _UTIME_H_ +#define _UTIME_H_ +/* +* Structure used by _utime function. +*/ +struct _utimbuf +{ +time_t actime;/* Access time */ +time_t modtime;/* Modification time */ +}; + +#ifndef _NO_OLDNAMES +/* NOTE: Must be the same as _utimbuf above. */ +struct utimbuf +{ +time_t actime; +time_t modtime; +}; +#endif /* Not _NO_OLDNAMES */ + +#endif
compat/winansi.c +8 -0
@@ -3,7 +3,11 @@*/ #include <windows.h> +#ifdef _MSC_VER +#include <stdio.h> +#else #include "../git-compat-util.h" +#endif /* Functions to be wrapped:
@@ -310,9 +314,13 @@ static int winansi_vfprintf(FILE *stream, const char *format, va_list list)if (!console) goto abort; +#ifndef _MSC_VERva_copy (cp, list); len =vsnprintf (small_buf,sizeof (small_buf), format, cp);va_end (cp); +#else + len=sizeof (small_buf) ; +#endif if (len >sizeof (small_buf) -1 ) { buf =malloc (len +1 );
git-compat-util.h +1 -1
@@ -87,7 +87,7 @@#include <assert.h> #include <regex.h> #include <utime.h> -#ifndef __MINGW32__ +#if !defined(__MINGW32__) && !defined(_MSC_VER)#include <sys/wait.h> #include <sys/poll.h> #include <sys/socket.h>
help.c +3 -2
@@ -126,8 +126,8 @@ static int is_executable(const char *name) !S_ISREG(st.st_mode))return 0 ; -#ifdef __MINGW32__ -/* cannot trust the executable bit, peek into the file instead */ +#if defined(__MINGW32__) || defined(_MSC_VER) +{/* cannot trust the executable bit, peek into the file instead */ char buf[3 ] = {0 };int n;int fd =open (name,O_RDONLY );
@@ -140,6 +140,7 @@ static int is_executable(const char *name) st.st_mode |=S_IXUSR ; close(fd); } +}#endif return st.st_mode &S_IXUSR ; }
pager.c +2 -2
@@ -9,7 +9,7 @@static int spawned_pager; -#ifndef __MINGW32__ +#if !defined(__MINGW32__) && !defined(_MSC_VER)static void pager_preexec (void ) {/*
@@ -70,7 +70,7 @@ void setup_pager(void) pager_argv[2 ] = pager; pager_process.argv = pager_argv; pager_process.in =-1 ; -#ifndef __MINGW32__ +#if !defined(__MINGW32__) && !defined(_MSC_VER) pager_process.preexec_cb = pager_preexec;#endif if (start_command (&pager_process))
run-command.c +7 -4
@@ -67,7 +67,7 @@ int start_command(struct child_process *cmd)trace_argv_printf (cmd->argv,"trace: run_command:" ); -#ifndef __MINGW32__ +#if !defined(__MINGW32__) && !defined(_MSC_VER)fflush (NULL ); cmd->pid =fork ();if (!cmd->pid) {
@@ -123,6 +123,7 @@ int start_command(struct child_process *cmd) exit(127); }#else +{int s0 =-1 , s1 =-1 , s2 =-1 ;/* backups of stdin, stdout, stderr */ const char **sargv = cmd->argv;char **env = environ;
@@ -186,6 +187,7 @@ int start_command(struct child_process *cmd)dup2 (s1,1 ),close (s1);if (s2 >=0 ) dup2(s2, 2), close(s2); +}#endif if (cmd->pid <0 ) {
@@ -292,7 +294,8 @@ int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, constreturn run_command (&cmd); } -#ifdef __MINGW32__ +#if defined(__MINGW32__) || defined(_MSC_VER) +#define __stdcallstatic __stdcall unsigned run_thread (void *data) {struct async *async = data;
@@ -308,7 +311,7 @@ int start_async(struct async *async)return error ("cannot create pipe: %s" ,strerror (errno)); async->out = pipe_out[0 ]; -#ifndef __MINGW32__ +#if !defined(__MINGW32__) && !defined(_MSC_VER)/* Flush stdio before fork() to avoid cloning buffers */ fflush (NULL );
@@ -337,7 +340,7 @@ int start_async(struct async *async)int finish_async (struct async *async) { -#ifndef __MINGW32__ +#if !defined(__MINGW32__) && !defined(_MSC_VER)int ret =0 ;if (wait_or_whine (async->pid))
run-command.h +1 -1
@@ -79,7 +79,7 @@ struct async {int (*proc)(int fd,void *data);void *data;int out;/* caller reads from here and closes it */ -#ifndef __MINGW32__ +#if !defined(__MINGW32__) && !defined(_MSC_VER)pid_t pid;#else HANDLE tid;
setup.c +1 -1
@@ -41,7 +41,7 @@ const char *prefix_path(const char *prefix, int len, const char *path)const char *prefix_filename (const char *pfx,int pfx_len,const char *arg) {static char path[PATH_MAX ]; -#ifndef __MINGW32__ +#if !defined(__MINGW32__) && !defined(_MSC_VER)if (!pfx || !*pfx ||is_absolute_path (arg))return arg;memcpy (path, pfx, pfx_len);
Signature · 1 line
1.6.4.msysgit.0
Hi,
Quoted 1 line · Frank Li
New patch.
A single monster patch?
Hmm.
Please understand that I will not review that unless it is split up into nice little and reviewable chunks.
This diffstat does not let me expect well-defined changes, either, sorry:
builtin-fast-export.c | 1 + compat/fnmatch/fnmatch.c | 2 + compat/mingw.c | 68 ++- compat/mingw.h | 21 +- compat/regex/regex.c | 8 +- compat/snprintf.c | 7 +- compat/vcbuild/.gitignore | 3 + compat/vcbuild/ReadMe | 13 + compat/vcbuild/git/git.vcproj | 197 +++++ compat/vcbuild/include/dirent.h | 127 ++++ compat/vcbuild/include/unistd.h | 174 +++++ compat/vcbuild/libgit/libgit.vcproj | 1347 +++++++++++++++++++++++++++++++++++ compat/vcbuild/porting.c | 13 + compat/vcbuild/sys/time.h | 21 + compat/winansi.c | 8 + git-compat-util.h | 2 +- help.c | 5 +- pager.c | 4 +- run-command.c | 11 +- run-command.h | 2 +- setup.c | 2 +- 21 files changed, 2011 insertions(+), 25 deletions(-)
It still modifies mingw.c and mingw.h, even if it has been strongly suggested to leave those alone.
It touches all kinds of files that appear to be completely unrelated to Microsoft Visual C++.
Remember: breaking things for existing users (and changing something that works for them quite well readily risks that) is not an option.
And the commit message does not even explain half of it...
Ciao,
Dscho
Hi,
Quoted 6 lines · Johannes Schindelin
A single monster patch?
Hmm.
Please understand that I will not review that unless it is split up into nice little and reviewable chunks.
Well, I try to improve.
So I had a look at your patch. The changes fall naturally into one of the following categories:
- decl-after-statement fixes
- missing #include "git-compat-util.h"
- converting a K&R style function definition to modern C
- #undef's only needed for Microsoft Visual C++
- the addition of O_BINARY in the file modes
- disabling link() (why?)
- double-#define'ing stat (which puzzles me greatly)
- dummy #define'ing of a few compiler attributes
- adding _MSVC to a conditional to avoid #define'ing SNPRINTF_SIZE_CORR yourself
- #define'ing several symbols without leading underscore to the MS-specific version with a leading underscore
- implementing strcasecmp() in a misnamed file
- "fixing" the return value of winansi_vfprintf for Microsoft Visual C++ (I think this fix is wrong)
- correctly adding a Visual C++-specific conditional to git-compat-util.h, pager.c, run-command.c, run-command.h, setup.c and help.c, although the latter five could use some refactoring into git-compat-util.h
Maybe there is also room to change the MinGW-conditional into a NO_TRUSTABLE_FILEMODE one
- adding several headers missing from Visual C++'s installation
- adding _huge_ .vcproj files (can they not be smaller?)
As you can see, there is a pretty natural way to split that huge patch into chunks that most people on these lists can review easily, and that would actually be a pleasure to look at.
Even better, there are a few fixes (the first three, if you ask me), which are not even Windows-specific.
Further, I would like to suggest adding a header file compat/msvc.h which contains all the #undef's and #define's necessary only for Visual C++, and which can be #include'd from git-compat-util.h, to better separate your work from the other platforms (who do not want those changes). That should avoid those unwanted changes to mingw.c and mingw.h. You just have to make sure that msvc.h is #include'd before mingw.h.
With these comments, I look forward to your next iteration.
Ciao,
Dscho
2009/8/16 Johannes Schindelin <[email protected]>:
Quoted 16 lines
Hi,
Quoted 6 lines · Johannes Schindelin
A single monster patch?
Hmm.
Please understand that I will not review that unless it is split up into nice little and reviewable chunks.
Well, I try to improve.
So I had a look at your patch. The changes fall naturally into one of the following categories:
Quoted 7 lines
- decl-after-statement fixes
- missing #include "
git-compat-util.h"- converting a K&R style function definition to modern C
- #undef's only needed for Microsoft Visual C++
#undef ERROR is necessary.
#undef in mingw.h is only for clean some warning.
Quoted 2 lines
- the addition of
O_BINARYin the file modes
Yes, default is text mode if no O_BINARY, _read _write will
do union code and cr\cf convert.
Quoted 2 lines
- disabling
link()(why?)
VC report stack error. I also don't know why. I have not deep debug this problem.
Quoted 2 lines
- double-#define'ing stat (which puzzles me greatly)
old define is
#define stat stati64
#define stati64 msys_stati64.
stat is used for both struct and function name.
In C code:
struct stat a;
stat -> stati64 -> msys_stati64, so compiler report structmsys_stati64 have not defined.
Quoted 11 lines
- dummy #define'ing of a few compiler attributes
- adding
_MSVCto a conditional to avoid #define'ingSNPRINTF_SIZE_CORRyourself- #define'ing several symbols without leading underscore to the MS-specific version with a leading underscore
- implementing
strcasecmp()in a misnamed file
Quoted 7 lines
- "fixing" the return value of
winansi_vfprintffor Microsoft Visual C++ (I think this fix is wrong)- correctly adding a Visual C++-specific conditional to
git-compat-util.h,pager.c,run-command.c,run-command.h,setup.candhelp.c, although the latter five could use some refactoring intogit-compat-util.h
Do you means add
#ifdef _MSC_VER
#include git-compat-util.h
#endifQuoted 7 lines
Maybe there is also room to change the MinGW-conditional into a
NO_TRUSTABLE_FILEMODEone- adding several headers missing from Visual C++'s installation
- adding _huge_ .vcproj files (can they not be smaller?)
It is created by VS2008. I think it is difficult to make smaller.
Quoted 8 lines
As you can see, there is a pretty natural way to split that huge patch into chunks that most people on these lists can review easily, and that would actually be a pleasure to look at.
Even better, there are a few fixes (the first three, if you ask me), which are not even Windows-specific.
Quoted 6 lines
Further, I would like to suggest adding a header file
compat/msvc.hwhich contains all the #undef's and #define's necessary only for Visual C++, and which can be #include'd fromgit-compat-util.h, to better separate your work from the other platforms (who do not want those changes). That should avoid those unwanted changes tomingw.candmingw.h. You just have to make sure thatmsvc.his #include'd beforemingw.h.
VC build will reuse msysgit work.
I will reduce change to mingw.c and mingw.h
But there are some problem at mingw.c and mingw.h
1. stat defination. Because both struct and function use the same name stat.
2. open need binary mode.
3. mingw.c use C99 style to break build at VC.
4. mingw.c use special DIR structure, So I need add open_dir in mingw.c.
If I don't change mingw.c, I need copy it to new file totally.
Quoted 9 lines
With these comments, I look forward to your next iteration.
Ciao,
Dscho
Hi,
[please quote only those parts that you actually reply to.]
Quoted 6 lines · Frank Li
2009/8/16 Johannes Schindelin <[email protected]>:
Quoted 1 line
- the addition of
O_BINARYin the file modesYes, default is text mode if no
O_BINARY,_read_writewill do union code and cr\cf convert.
As Git _never_ wants to open files in text mode, this is a change that can come _separately_ from your VC patches. It could even be considered a bug fix (MinGW's current GCC implies O_BINARY, but previous ones may not, and it is wrong of us to rely on this magic).
Quoted 4 lines
Quoted 1 line
- disabling
link()(why?)VC report stack error. I also don't know why. I have not deep debug this problem.
You should. What with Visual Studio's superior debugging capabilities, it should not be a problem. Right?
Quoted 5 lines
Quoted 1 line
- double-#define'ing stat (which puzzles me greatly)
old define is
#define stat stati64 #define stati64 msys_stati64.
Not exactly.
#define stat _stati64 [...] #define _stati64(x,y) mingw_lstat(x,y)
And even VC should handle that just fine.
Quoted 5 lines
stat is used for both struct and function name.
In C code:struct stat a;stat -> stati64 ->
msys_stati64, so compiler report structmsys_stati64have not defined.
It is a real pity that you did not inline your patch, and that I could not quote it as a consequence, because now we could discuss code properly:
The original code was done on purpose as it is, to use the _stati64 struct (which allows long pointers, as Microsoft decided off_t was not good enough to represent 64 bit offsets). I could imagine that your patch breaks that for Visual C++.
Quoted 3 lines
Quoted 1 line
- adding _huge_ .vcproj files (can they not be smaller?)
It is created by VS2008. I think it is difficult to make smaller.
Is there not some magic to make a compact export version?
But maybe it is not that bad? I have 72 (out of 1730) files in my repository that are larger, gitk being the king.
FWIW I would have loved it if _you_ defended the size of the file, instead of having to do it myself.
Quoted 9 lines
Quoted 7 lines
Further, I would like to suggest adding a header file
compat/msvc.hwhich contains all the #undef's and #define's necessary only for Visual C++, and which can be #include'd fromgit-compat-util.h, to better separate your work from the other platforms (who do not want those changes). That should avoid those unwanted changes tomingw.candmingw.h. You just have to make sure thatmsvc.his #include'd beforemingw.h.VC build will reuse msysgit work.
That is no question. We made it easy for you.
Quoted 4 lines
I will reduce change to
mingw.candmingw.h
But there are some problem atmingw.candmingw.h1. stat defination. Because both struct and function use the same name stat.
That needs to be resolved somehow, and you would get _much_ more help if you had split your patch series properly and this was _one_ patch.
Quoted 1 line
2. open need binary mode.
As I said, this can be a separate change. In my original reply I _implied_ that it is okay, and in this reply I elaborated on that (namely that it might be considered a bug fix).
Quoted 1 line
3.
mingw.cuse C99 style to break build at VC.
The same applies here as to O_BINARY.
Quoted 1 line
4.
mingw.cuse special DIR structure, So I need addopen_dirinmingw.c.
No, you do not need to add that to mingw.c. MinGW does not need it. So it has no place in mingw.c.
Quoted 1 line
If I don't change
mingw.c, I need copy it to new file totally.
NOOOO!!!
You #include it after making sure that you have #undef'ed and #define'd whatever needs to, and in a separate file -- which is only referenced in the .vcproj -- you can implement whatever Visual C++ misses.
Quoted 4 lines
Quoted 4 lines
With these comments, I look forward to your next iteration.
Ciao,
Dscho
Please, please, PLEASE, do not quote things that you are not addressing. And please, please, PLEASE adher to Documentation/SubmittingPatches.
Actually, the only thing SubmittingPatches does is spell out how to make things easier for reviewers, should you not know how to do so.
Remember: the more time it takes me to cull the quoted parts of your mail, the more time it takes me to have a look at your patches, the more time it takes me to refer to your patch and make suggestions, the more am I inclined to spend my time elsewhere, doing something that is much more enjoyable.
Ciao,
Dscho