Merge branch 'fc/macos-x-clipped-write' into maint
authorJunio C Hamano <gitster@pobox.com>
Sun, 30 Jun 2013 22:33:40 +0000 (15:33 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 30 Jun 2013 22:33:40 +0000 (15:33 -0700)
Mac OS X does not like to write(2) more than INT_MAX number of
bytes; work it around by chopping write(2) into smaller pieces.

* fc/macos-x-clipped-write:
compate/clipped-write.c: large write(2) fails on Mac OS X/XNU

1  2 
Makefile
config.mak.uname
git-compat-util.h
diff --combined Makefile
index 5e7cadf0173eb6ea5b02dbabedc527327b975fa4,0434715f0e86ec0d055c4a7fbf55d975c06b825d..11d89a5d272a426e1eab2b0f43b1561cb8141232
+++ b/Makefile
@@@ -69,6 -69,9 +69,9 @@@ all:
  # Define NO_MSGFMT_EXTENDED_OPTIONS if your implementation of msgfmt
  # doesn't support GNU extensions like --check and --statistics
  #
+ # Define NEEDS_CLIPPED_WRITE if your write(2) cannot write more than
+ # INT_MAX bytes at once (e.g. MacOS X).
+ #
  # Define HAVE_PATHS_H if you have paths.h and want to use the default PATH
  # it specifies.
  #
  # specify your own (or DarwinPort's) include directories and
  # library directories by defining CFLAGS and LDFLAGS appropriately.
  #
 +# Define NO_APPLE_COMMON_CRYPTO if you are building on Darwin/Mac OS X
 +# and do not want to use Apple's CommonCrypto library.  This allows you
 +# to provide your own OpenSSL library, for example from MacPorts.
 +#
  # Define BLK_SHA1 environment variable to make use of the bundled
  # optimized C SHA1 routine.
  #
@@@ -362,39 -361,33 +365,39 @@@ STRIP ?= stri
  # Among the variables below, these:
  #   gitexecdir
  #   template_dir
 -#   mandir
 -#   infodir
 -#   htmldir
  #   sysconfdir
  # can be specified as a relative path some/where/else;
  # this is interpreted as relative to $(prefix) and "git" at
  # runtime figures out where they are based on the path to the executable.
 +# Additionally, the following will be treated as relative by "git" if they
 +# begin with "$(prefix)/":
 +#   mandir
 +#   infodir
 +#   htmldir
  # This can help installing the suite in a relocatable way.
  
  prefix = $(HOME)
  bindir_relative = bin
  bindir = $(prefix)/$(bindir_relative)
 -mandir = share/man
 -infodir = share/info
 +mandir = $(prefix)/share/man
 +infodir = $(prefix)/share/info
  gitexecdir = libexec/git-core
  mergetoolsdir = $(gitexecdir)/mergetools
  sharedir = $(prefix)/share
  gitwebdir = $(sharedir)/gitweb
  localedir = $(sharedir)/locale
  template_dir = share/git-core/templates
 -htmldir = share/doc/git-doc
 +htmldir = $(prefix)/share/doc/git-doc
  ETC_GITCONFIG = $(sysconfdir)/gitconfig
  ETC_GITATTRIBUTES = $(sysconfdir)/gitattributes
  lib = lib
  # DESTDIR =
  pathsep = :
  
 +mandir_relative = $(patsubst $(prefix)/%,%,$(mandir))
 +infodir_relative = $(patsubst $(prefix)/%,%,$(infodir))
 +htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir))
 +
  export prefix bindir sharedir sysconfdir gitwebdir localedir
  
  CC = cc
@@@ -627,6 -620,22 +630,6 @@@ LIB_FILE = libgit.
  XDIFF_LIB = xdiff/lib.a
  VCSSVN_LIB = vcs-svn/lib.a
  
 -LIB_H += xdiff/xinclude.h
 -LIB_H += xdiff/xmacros.h
 -LIB_H += xdiff/xdiff.h
 -LIB_H += xdiff/xtypes.h
 -LIB_H += xdiff/xutils.h
 -LIB_H += xdiff/xprepare.h
 -LIB_H += xdiff/xdiffi.h
 -LIB_H += xdiff/xemit.h
 -
 -LIB_H += vcs-svn/line_buffer.h
 -LIB_H += vcs-svn/sliding_window.h
 -LIB_H += vcs-svn/repo_tree.h
 -LIB_H += vcs-svn/fast_export.h
 -LIB_H += vcs-svn/svndiff.h
 -LIB_H += vcs-svn/svndump.h
 -
  GENERATED_H += common-cmds.h
  
  LIB_H += advice.h
@@@ -728,24 -737,11 +731,24 @@@ LIB_H += url.
  LIB_H += userdiff.h
  LIB_H += utf8.h
  LIB_H += varint.h
 +LIB_H += vcs-svn/fast_export.h
 +LIB_H += vcs-svn/line_buffer.h
 +LIB_H += vcs-svn/repo_tree.h
 +LIB_H += vcs-svn/sliding_window.h
 +LIB_H += vcs-svn/svndiff.h
 +LIB_H += vcs-svn/svndump.h
  LIB_H += walker.h
  LIB_H += wildmatch.h
  LIB_H += wt-status.h
  LIB_H += xdiff-interface.h
  LIB_H += xdiff/xdiff.h
 +LIB_H += xdiff/xdiffi.h
 +LIB_H += xdiff/xemit.h
 +LIB_H += xdiff/xinclude.h
 +LIB_H += xdiff/xmacros.h
 +LIB_H += xdiff/xprepare.h
 +LIB_H += xdiff/xtypes.h
 +LIB_H += xdiff/xutils.h
  
  LIB_OBJS += abspath.o
  LIB_OBJS += advice.o
@@@ -1058,11 -1054,6 +1061,11 @@@ ifeq ($(uname_S),Darwin
                        BASIC_LDFLAGS += -L/opt/local/lib
                endif
        endif
 +      ifndef NO_APPLE_COMMON_CRYPTO
 +              APPLE_COMMON_CRYPTO = YesPlease
 +              COMPAT_CFLAGS += -DAPPLE_COMMON_CRYPTO
 +      endif
 +      NO_REGEX = YesPlease
        PTHREAD_LIBS =
  endif
  
@@@ -1396,17 -1387,11 +1399,17 @@@ ifdef PPC_SHA
        SHA1_HEADER = "ppc/sha1.h"
        LIB_OBJS += ppc/sha1.o ppc/sha1ppc.o
        LIB_H += ppc/sha1.h
 +else
 +ifdef APPLE_COMMON_CRYPTO
 +      COMPAT_CFLAGS += -DCOMMON_DIGEST_FOR_OPENSSL
 +      SHA1_HEADER = <CommonCrypto/CommonDigest.h>
  else
        SHA1_HEADER = <openssl/sha.h>
        EXTLIBS += $(LIB_4_CRYPTO)
  endif
  endif
 +endif
 +
  ifdef NO_PERL_MAKEMAKER
        export NO_PERL_MAKEMAKER
  endif
@@@ -1481,6 -1466,11 +1484,11 @@@ ifndef NO_MSGFMT_EXTENDED_OPTION
        MSGFMT += --check --statistics
  endif
  
+ ifdef NEEDS_CLIPPED_WRITE
+       BASIC_CFLAGS += -DNEEDS_CLIPPED_WRITE
+       COMPAT_OBJS += compat/clipped-write.o
+ endif
  ifneq (,$(XDL_FAST_HASH))
        BASIC_CFLAGS += -DXDL_FAST_HASH
  endif
@@@ -1560,12 -1550,12 +1568,12 @@@ ETC_GITATTRIBUTES_SQ = $(subst ','\'',$
  DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
  bindir_SQ = $(subst ','\'',$(bindir))
  bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
 -mandir_SQ = $(subst ','\'',$(mandir))
 -infodir_SQ = $(subst ','\'',$(infodir))
 +mandir_relative_SQ = $(subst ','\'',$(mandir_relative))
 +infodir_relative_SQ = $(subst ','\'',$(infodir_relative))
  localedir_SQ = $(subst ','\'',$(localedir))
  gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
  template_dir_SQ = $(subst ','\'',$(template_dir))
 -htmldir_SQ = $(subst ','\'',$(htmldir))
 +htmldir_relative_SQ = $(subst ','\'',$(htmldir_relative))
  prefix_SQ = $(subst ','\'',$(prefix))
  gitwebdir_SQ = $(subst ','\'',$(gitwebdir))
  
@@@ -1697,9 -1687,9 +1705,9 @@@ strip: $(PROGRAMS) git$
  
  git.sp git.s git.o: GIT-PREFIX
  git.sp git.s git.o: EXTRA_CPPFLAGS = \
 -      '-DGIT_HTML_PATH="$(htmldir_SQ)"' \
 -      '-DGIT_MAN_PATH="$(mandir_SQ)"' \
 -      '-DGIT_INFO_PATH="$(infodir_SQ)"'
 +      '-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \
 +      '-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \
 +      '-DGIT_INFO_PATH="$(infodir_relative_SQ)"'
  
  git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS)
        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ git.o \
@@@ -1709,9 -1699,9 +1717,9 @@@ help.sp help.s help.o: common-cmds.
  
  builtin/help.sp builtin/help.s builtin/help.o: common-cmds.h GIT-PREFIX
  builtin/help.sp builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \
 -      '-DGIT_HTML_PATH="$(htmldir_SQ)"' \
 -      '-DGIT_MAN_PATH="$(mandir_SQ)"' \
 -      '-DGIT_INFO_PATH="$(infodir_SQ)"'
 +      '-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \
 +      '-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \
 +      '-DGIT_INFO_PATH="$(infodir_relative_SQ)"'
  
  version.sp version.s version.o: GIT-VERSION-FILE GIT-USER-AGENT
  version.sp version.s version.o: EXTRA_CPPFLAGS = \
diff --combined config.mak.uname
index d78fd3df5b211130ba8ff77197a3f852c32aab86,e689a9a867e1b0aae24197ba95dac8e8d7e019e2..174703b67cc75fc48fd3bf5345468e9eeca89fc2
@@@ -95,6 -95,7 +95,7 @@@ ifeq ($(uname_S),Darwin
        NO_MEMMEM = YesPlease
        USE_ST_TIMESPEC = YesPlease
        HAVE_DEV_TTY = YesPlease
+       NEEDS_CLIPPED_WRITE = YesPlease
        COMPAT_OBJS += compat/precompose_utf8.o
        BASIC_CFLAGS += -DPRECOMPOSE_UNICODE
  endif
@@@ -326,6 -327,7 +327,6 @@@ ifeq ($(uname_S),Windows
        # NEEDS_LIBICONV = YesPlease
        NO_ICONV = YesPlease
        NO_STRTOUMAX = YesPlease
 -      NO_STRTOULL = YesPlease
        NO_MKDTEMP = YesPlease
        NO_MKSTEMPS = YesPlease
        SNPRINTF_RETURNS_BOGUS = YesPlease
        NO_CURL = YesPlease
        NO_PYTHON = YesPlease
        BLK_SHA1 = YesPlease
 +      ETAGS_TARGET = ETAGS
 +      NO_INET_PTON = YesPlease
 +      NO_INET_NTOP = YesPlease
        NO_POSIX_GOODIES = UnfortunatelyYes
        NATIVE_CRLF = YesPlease
        DEFAULT_HELP_FORMAT = html
@@@ -507,7 -506,6 +508,7 @@@ ifneq (,$(findstring MINGW,$(uname_S))
                compat/win32/dirent.o
        EXTLIBS += -lws2_32
        PTHREAD_LIBS =
 +      NATIVE_CRLF = YesPlease
        X = .exe
        SPARSE_FLAGS = -Wno-one-bit-signed-bitfield
  ifneq (,$(wildcard ../THIS_IS_MSYSGIT))
diff --combined git-compat-util.h
index c1f8a477fb96730612e1ddd06294270a4651649f,3144b8da1e0a7346739ee5acbf5865de3da7d210..660b7f012ac8a94a25da818c0ec6667ff3378add
@@@ -86,9 -86,6 +86,9 @@@
  #define _SGI_SOURCE 1
  
  #ifdef WIN32 /* Both MinGW and MSVC */
 +# if defined (_MSC_VER)
 +#  define _WIN32_WINNT 0x0502
 +# endif
  #define WIN32_LEAN_AND_MEAN  /* stops windows.h including winsock.h */
  #include <winsock2.h>
  #include <windows.h>
  typedef long intptr_t;
  typedef unsigned long uintptr_t;
  #endif
 +int get_st_mode_bits(const char *path, int *mode);
  #if defined(__CYGWIN__)
  #undef _XOPEN_SOURCE
  #include <grp.h>
  #define probe_utf8_pathname_composition(a,b)
  #endif
  
+ #ifdef NEEDS_CLIPPED_WRITE
+ ssize_t clipped_write(int fildes, const void *buf, size_t nbyte);
+ #define write(x,y,z) clipped_write((x),(y),(z))
+ #endif
  #ifdef MKDIR_WO_TRAILING_SLASH
  #define mkdir(a,b) compat_mkdir_wo_trailing_slash((a),(b))
  extern int compat_mkdir_wo_trailing_slash(const char*, mode_t);
@@@ -217,17 -218,6 +222,17 @@@ extern char *gitbasename(char *)
  #include <openssl/err.h>
  #endif
  
 +/* On most systems <netdb.h> would have given us this, but
 + * not on some systems (e.g. z/OS).
 + */
 +#ifndef NI_MAXHOST
 +#define NI_MAXHOST 1025
 +#endif
 +
 +#ifndef NI_MAXSERV
 +#define NI_MAXSERV 32
 +#endif
 +
  /* On most systems <limits.h> would have given us this, but
   * not on some systems (e.g. GNU/Hurd).
   */
@@@ -331,7 -321,6 +336,7 @@@ extern void warning(const char *err, ..
  
  extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params));
  extern void set_error_routine(void (*routine)(const char *err, va_list params));
 +extern void set_die_is_recursing_routine(int (*routine)(void));
  
  extern int prefixcmp(const char *str, const char *prefix);
  extern int suffixcmp(const char *str, const char *suffix);
@@@ -692,9 -681,8 +697,9 @@@ int remove_or_warn(unsigned int mode, c
   * Call access(2), but warn for any error except "missing file"
   * (ENOENT or ENOTDIR).
   */
 -int access_or_warn(const char *path, int mode);
 -int access_or_die(const char *path, int mode);
 +#define ACCESS_EACCES_OK (1U << 0)
 +int access_or_warn(const char *path, int mode, unsigned flag);
 +int access_or_die(const char *path, int mode, unsigned flag);
  
  /* Warn on an inaccessible file that ought to be accessible */
  void warn_on_inaccessible(const char *path);