Merge branch 'rj/mingw-cygwin'
authorJunio C Hamano <gitster@pobox.com>
Tue, 11 Jun 2013 20:30:20 +0000 (13:30 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 11 Jun 2013 20:30:20 +0000 (13:30 -0700)
Update build for Cygwin 1.[57]. Torsten Bögershausen reports that
this is fine with Cygwin 1.7 ($gmane/225824) so let's try moving it
ahead.

* rj/mingw-cygwin:
cygwin: Remove the CYGWIN_V15_WIN32API build variable
mingw: rename WIN32 cpp macro to GIT_WINDOWS_NATIVE

1  2 
Makefile
config.mak.uname
git-compat-util.h
help.c
test-chmtime.c
diff --combined Makefile
index a748133ae51515a2e08bb2dfc0f731d96abda8df,32c49ba16e7b06c9c9fd8e1dabe78a8c38e1aecb..03524d022c3bea71a71d736214c07a8667d625d8
+++ b/Makefile
@@@ -69,9 -69,6 +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.
  #
  #
  # Define NO_REGEX if you have no or inferior regex support in your C library.
  #
- # Define CYGWIN_V15_WIN32API if you are using Cygwin v1.7.x but are not
- # using the current w32api packages. The recommended approach, however,
- # is to update your installation if compilation errors occur.
- #
  # Define HAVE_DEV_TTY if your system can open /dev/tty to interact with the
  # user.
  #
@@@ -467,7 -456,6 +463,7 @@@ SCRIPT_SH += git-mergetool.s
  SCRIPT_SH += git-pull.sh
  SCRIPT_SH += git-quiltimport.sh
  SCRIPT_SH += git-rebase.sh
 +SCRIPT_SH += git-remote-testgit.sh
  SCRIPT_SH += git-repack.sh
  SCRIPT_SH += git-request-pull.sh
  SCRIPT_SH += git-stash.sh
@@@ -495,17 -483,11 +491,17 @@@ SCRIPT_PERL += git-svn.per
  SCRIPT_PYTHON += git-remote-testpy.py
  SCRIPT_PYTHON += git-p4.py
  
 +NO_INSTALL += git-remote-testpy
 +
  # Generated files for scripts
  SCRIPT_SH_GEN = $(patsubst %.sh,%,$(SCRIPT_SH))
  SCRIPT_PERL_GEN = $(patsubst %.perl,%,$(SCRIPT_PERL))
  SCRIPT_PYTHON_GEN = $(patsubst %.py,%,$(SCRIPT_PYTHON))
  
 +SCRIPT_SH_INS = $(filter-out $(NO_INSTALL),$(SCRIPT_SH_GEN))
 +SCRIPT_PERL_INS = $(filter-out $(NO_INSTALL),$(SCRIPT_PERL_GEN))
 +SCRIPT_PYTHON_INS = $(filter-out $(NO_INSTALL),$(SCRIPT_PYTHON_GEN))
 +
  # Individual rules to allow e.g.
  # "make -C ../.. SCRIPT_PERL=contrib/foo/bar.perl build-perl-script"
  # from subdirectories like contrib/*/
@@@ -515,12 -497,12 +511,12 @@@ build-sh-script: $(SCRIPT_SH_GEN
  build-python-script: $(SCRIPT_PYTHON_GEN)
  
  .PHONY: install-perl-script install-sh-script install-python-script
 -install-sh-script: $(SCRIPT_SH_GEN)
 -      $(INSTALL) $(SCRIPT_SH_GEN) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 -install-perl-script: $(SCRIPT_PERL_GEN)
 -      $(INSTALL) $(SCRIPT_PERL_GEN) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 -install-python-script: $(SCRIPT_PYTHON_GEN)
 -      $(INSTALL) $(SCRIPT_PYTHON_GEN) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 +install-sh-script: $(SCRIPT_SH_INS)
 +      $(INSTALL) $^ '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 +install-perl-script: $(SCRIPT_PERL_INS)
 +      $(INSTALL) $^ '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 +install-python-script: $(SCRIPT_PYTHON_INS)
 +      $(INSTALL) $^ '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
  
  .PHONY: clean-perl-script clean-sh-script clean-python-script
  clean-sh-script:
@@@ -530,9 -512,9 +526,9 @@@ clean-perl-script
  clean-python-script:
        $(RM) $(SCRIPT_PYTHON_GEN)
  
 -SCRIPTS = $(SCRIPT_SH_GEN) \
 -        $(SCRIPT_PERL_GEN) \
 -        $(SCRIPT_PYTHON_GEN) \
 +SCRIPTS = $(SCRIPT_SH_INS) \
 +        $(SCRIPT_PERL_INS) \
 +        $(SCRIPT_PYTHON_INS) \
          git-instaweb
  
  ETAGS_TARGET = TAGS
@@@ -687,8 -669,6 +683,8 @@@ LIB_H += help.
  LIB_H += http.h
  LIB_H += kwset.h
  LIB_H += levenshtein.h
 +LIB_H += line-log.h
 +LIB_H += line-range.h
  LIB_H += list-objects.h
  LIB_H += ll-merge.h
  LIB_H += log-tree.h
@@@ -700,6 -680,7 +696,6 @@@ LIB_H += notes-cache.
  LIB_H += notes-merge.h
  LIB_H += notes.h
  LIB_H += object.h
 -LIB_H += pack-refs.h
  LIB_H += pack-revindex.h
  LIB_H += pack.h
  LIB_H += parse-options.h
@@@ -816,8 -797,6 +812,8 @@@ LIB_OBJS += hex.
  LIB_OBJS += ident.o
  LIB_OBJS += kwset.o
  LIB_OBJS += levenshtein.o
 +LIB_OBJS += line-log.o
 +LIB_OBJS += line-range.o
  LIB_OBJS += list-objects.o
  LIB_OBJS += ll-merge.o
  LIB_OBJS += lockfile.o
@@@ -834,6 -813,7 +830,6 @@@ LIB_OBJS += notes-cache.
  LIB_OBJS += notes-merge.o
  LIB_OBJS += object.o
  LIB_OBJS += pack-check.o
 -LIB_OBJS += pack-refs.o
  LIB_OBJS += pack-revindex.o
  LIB_OBJS += pack-write.o
  LIB_OBJS += pager.o
@@@ -1070,11 -1050,6 +1066,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
  
@@@ -1408,17 -1383,11 +1404,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
@@@ -1476,9 -1445,6 +1472,6 @@@ ifdef NO_REGE
        COMPAT_CFLAGS += -Icompat/regex
        COMPAT_OBJS += compat/regex/regex.o
  endif
- ifdef CYGWIN_V15_WIN32API
-       COMPAT_CFLAGS += -DCYGWIN_V15_WIN32API
- endif
  
  ifdef USE_NED_ALLOCATOR
         COMPAT_CFLAGS += -Icompat/nedmalloc
@@@ -1493,11 -1459,6 +1486,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
@@@ -1535,7 -1496,6 +1528,7 @@@ ifndef 
        QUIET_MSGFMT   = @echo '   ' MSGFMT $@;
        QUIET_GCOV     = @echo '   ' GCOV $@;
        QUIET_SP       = @echo '   ' SP $<;
 +      QUIET_RC       = @echo '   ' RC $@;
        QUIET_SUBDIR0  = +@subdir=
        QUIET_SUBDIR1  = ;$(NO_SUBDIR) echo '   ' SUBDIR $$subdir; \
                         $(MAKE) $(PRINT_DIR) -C $$subdir
@@@ -1678,7 -1638,7 +1671,7 @@@ please_set_SHELL_PATH_to_a_more_modern_
  shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell
  
  strip: $(PROGRAMS) git$X
 -      $(STRIP) $(STRIP_OPTS) $(PROGRAMS) git$X
 +      $(STRIP) $(STRIP_OPTS) $^
  
  ### Target-specific flags and dependencies
  
@@@ -1738,9 -1698,9 +1731,9 @@@ version.sp version.s version.o: EXTRA_C
  
  $(BUILT_INS): git$X
        $(QUIET_BUILT_IN)$(RM) $@ && \
 -      ln git$X $@ 2>/dev/null || \
 -      ln -s git$X $@ 2>/dev/null || \
 -      cp git$X $@
 +      ln $< $@ 2>/dev/null || \
 +      ln -s $< $@ 2>/dev/null || \
 +      cp $< $@
  
  common-cmds.h: ./generate-cmdlist.sh command-list.txt
  
@@@ -1781,11 -1741,6 +1774,11 @@@ $(SCRIPT_LIB) : % : %.sh GIT-SCRIPT-DEF
        $(QUIET_GEN)$(cmd_munge_script) && \
        mv $@+ $@
  
 +git.res: git.rc GIT-VERSION-FILE
 +      $(QUIET_RC)$(RC) \
 +        $(join -DMAJOR= -DMINOR= -DPATCH=, $(wordlist 1,3,$(subst -, ,$(subst ., ,$(GIT_VERSION))))) \
 +        -DGIT_VERSION="\\\"$(GIT_VERSION)\\\"" $< -o $@
 +
  ifndef NO_PERL
  $(patsubst %.perl,%,$(SCRIPT_PERL)): perl/perl.mak
  
@@@ -1810,7 -1765,7 +1803,7 @@@ $(patsubst %.perl,%,$(SCRIPT_PERL)): % 
            -e '        x' \
            -e '}' \
            -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
 -          $@.perl >$@+ && \
 +          $< >$@+ && \
        chmod +x $@+ && \
        mv $@+ $@
  
@@@ -1834,8 -1789,8 +1827,8 @@@ $(patsubst %.perl,%,$(SCRIPT_PERL)) git
  endif # NO_PERL
  
  ifndef NO_PYTHON
 -$(patsubst %.py,%,$(SCRIPT_PYTHON)): GIT-CFLAGS GIT-PREFIX GIT-PYTHON-VARS
 -$(patsubst %.py,%,$(SCRIPT_PYTHON)): % : %.py
 +$(SCRIPT_PYTHON_GEN): GIT-CFLAGS GIT-PREFIX GIT-PYTHON-VARS
 +$(SCRIPT_PYTHON_GEN): % : %.py
        $(QUIET_GEN)$(RM) $@ $@+ && \
        INSTLIBDIR=`MAKEFLAGS= $(MAKE) -C git_remote_helpers -s \
                --no-print-directory prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' \
        sed -e '1s|#!.*python|#!$(PYTHON_PATH_SQ)|' \
            -e 's|\(os\.getenv("GITPYTHONLIB"\)[^)]*)|\1,"@@INSTLIBDIR@@")|' \
            -e 's|@@INSTLIBDIR@@|'"$$INSTLIBDIR"'|g' \
 -          $@.py >$@+ && \
 +          $< >$@+ && \
        chmod +x $@+ && \
        mv $@+ $@
  else # NO_PYTHON
 -$(patsubst %.py,%,$(SCRIPT_PYTHON)): % : unimplemented.sh
 +$(SCRIPT_PYTHON_GEN): % : unimplemented.sh
        $(QUIET_GEN)$(RM) $@ $@+ && \
        sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
            -e 's|@@REASON@@|NO_PYTHON=$(NO_PYTHON)|g' \
@@@ -2042,7 -1997,6 +2035,7 @@@ endi
  ifdef USE_NED_ALLOCATOR
  compat/nedmalloc/nedmalloc.sp compat/nedmalloc/nedmalloc.o: EXTRA_CPPFLAGS = \
        -DNDEBUG -DOVERRIDE_STRDUP -DREPLACE_SYSTEM_ALLOCATOR
 +compat/nedmalloc/nedmalloc.sp: SPARSE_FLAGS += -Wno-non-pointer-null
  endif
  
  git-%$X: %.o GIT-LDFLAGS $(GITLIBS)
@@@ -2198,9 -2152,6 +2191,9 @@@ GIT-BUILD-OPTIONS: FORC
        @echo NO_PERL=\''$(subst ','\'',$(subst ','\'',$(NO_PERL)))'\' >>$@
        @echo NO_PYTHON=\''$(subst ','\'',$(subst ','\'',$(NO_PYTHON)))'\' >>$@
        @echo NO_UNIX_SOCKETS=\''$(subst ','\'',$(subst ','\'',$(NO_UNIX_SOCKETS)))'\' >>$@
 +ifdef TEST_OUTPUT_DIRECTORY
 +      @echo TEST_OUTPUT_DIRECTORY=\''$(subst ','\'',$(subst ','\'',$(TEST_OUTPUT_DIRECTORY)))'\' >>$@
 +endif
  ifdef GIT_TEST_OPTS
        @echo GIT_TEST_OPTS=\''$(subst ','\'',$(subst ','\'',$(GIT_TEST_OPTS)))'\' >>$@
  endif
@@@ -2485,8 -2436,8 +2478,8 @@@ profile-clean
        $(RM) $(addsuffix *.gcda,$(addprefix $(PROFILE_DIR)/, $(object_dirs)))
        $(RM) $(addsuffix *.gcno,$(addprefix $(PROFILE_DIR)/, $(object_dirs)))
  
 -clean: profile-clean
 -      $(RM) *.o block-sha1/*.o ppc/*.o compat/*.o compat/*/*.o xdiff/*.o vcs-svn/*.o \
 +clean: profile-clean coverage-clean
 +      $(RM) *.o *.res block-sha1/*.o ppc/*.o compat/*.o compat/*/*.o xdiff/*.o vcs-svn/*.o \
                builtin/*.o $(LIB_FILE) $(XDIFF_LIB) $(VCSSVN_LIB)
        $(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) git$X
        $(RM) $(TEST_PROGRAMS)
@@@ -2566,34 -2517,29 +2559,34 @@@ check-builtins:
  
  ### Test suite coverage testing
  #
 -.PHONY: coverage coverage-clean coverage-build coverage-report
 +.PHONY: coverage coverage-clean coverage-compile coverage-test coverage-report
 +.PHONY: coverage-clean-results
  
  coverage:
 -      $(MAKE) coverage-build
 -      $(MAKE) coverage-report
 +      $(MAKE) coverage-test
 +      $(MAKE) coverage-untested-functions
  
  object_dirs := $(sort $(dir $(OBJECTS)))
 -coverage-clean:
 +coverage-clean-results:
        $(RM) $(addsuffix *.gcov,$(object_dirs))
        $(RM) $(addsuffix *.gcda,$(object_dirs))
 -      $(RM) $(addsuffix *.gcno,$(object_dirs))
        $(RM) coverage-untested-functions
        $(RM) -r cover_db/
        $(RM) -r cover_db_html/
  
 +coverage-clean: coverage-clean-results
 +      $(RM) $(addsuffix *.gcno,$(object_dirs))
 +
  COVERAGE_CFLAGS = $(CFLAGS) -O0 -ftest-coverage -fprofile-arcs
  COVERAGE_LDFLAGS = $(CFLAGS)  -O0 -lgcov
  GCOVFLAGS = --preserve-paths --branch-probabilities --all-blocks
  
 -coverage-build: coverage-clean
 +coverage-compile:
        $(MAKE) CFLAGS="$(COVERAGE_CFLAGS)" LDFLAGS="$(COVERAGE_LDFLAGS)" all
 +
 +coverage-test: coverage-clean-results coverage-compile
        $(MAKE) CFLAGS="$(COVERAGE_CFLAGS)" LDFLAGS="$(COVERAGE_LDFLAGS)" \
 -              -j1 test
 +              DEFAULT_TEST_TARGET=test -j1 test
  
  coverage-report:
        $(QUIET_GCOV)for dir in $(object_dirs); do \
diff --combined config.mak.uname
index 53540075883b15040ebdfce1403e6145532a6cc5,28aa239be0dbeadd6a6fb8d6ffed750cba1a905f..7ac541e9ebbe77b339846d8efafdd0b6f33fee95
@@@ -95,7 -95,6 +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
@@@ -159,7 -158,6 +159,6 @@@ ifeq ($(uname_O),Cygwin
                NO_SYMLINK_HEAD = YesPlease
                NO_IPV6 = YesPlease
                OLD_ICONV = UnfortunatelyYes
-               CYGWIN_V15_WIN32API = YesPlease
        endif
        NO_THREAD_SAFE_PREAD = YesPlease
        NEEDS_LIBICONV = YesPlease
@@@ -481,6 -479,7 +480,6 @@@ ifneq (,$(findstring MINGW,$(uname_S))
        NO_FNMATCH = YesPlease
        NO_MEMMEM = YesPlease
        NEEDS_LIBICONV = YesPlease
 -      OLD_ICONV = YesPlease
        NO_STRTOUMAX = YesPlease
        NO_MKDTEMP = YesPlease
        NO_MKSTEMPS = YesPlease
        NO_INET_PTON = YesPlease
        NO_INET_NTOP = YesPlease
        NO_POSIX_GOODIES = UnfortunatelyYes
 +      DEFAULT_HELP_FORMAT = html
        COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/win32
        COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
        COMPAT_OBJS += compat/mingw.o compat/winansi.o \
                compat/win32/pthread.o compat/win32/syslog.o \
                compat/win32/dirent.o
 +      BASIC_LDFLAGS += -Wl,--large-address-aware
        EXTLIBS += -lws2_32
 +      GITLIBS += git.res
        PTHREAD_LIBS =
 +      RC = windres -O coff
        NATIVE_CRLF = YesPlease
        X = .exe
        SPARSE_FLAGS = -Wno-one-bit-signed-bitfield
@@@ -522,7 -517,6 +521,7 @@@ ifneq (,$(wildcard ../THIS_IS_MSYSGIT)
        NO_R_TO_GCC_LINKER = YesPlease
        INTERNAL_QSORT = YesPlease
        HAVE_LIBCHARSET_H = YesPlease
 +      NO_GETTEXT = YesPlease
  else
        NO_CURL = YesPlease
  endif
diff --combined git-compat-util.h
index aa0404ef418410905c3dfa7c88a8700cf41c6110,eeed5069729f07aeb6beff073d010f1cf6f229e9..ff193f4aa236727cc9b87ddbaeac1975b8c40fa7
  #define _NETBSD_SOURCE 1
  #define _SGI_SOURCE 1
  
- #ifdef WIN32 /* Both MinGW and MSVC */
+ #if defined(WIN32) && !defined(__CYGWIN__) /* 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>
+ #define GIT_WINDOWS_NATIVE
  #endif
  
  #include <unistd.h>
  #else
  #include <poll.h>
  #endif
 +
 +extern int get_st_mode_bits(const char *path, int *mode);
 +
  #if defined(__MINGW32__)
  /* pull in Windows compatibility stuff */
  #include "compat/mingw.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);
@@@ -699,9 -693,8 +700,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);
diff --combined help.c
index bebfce96e637fe2444fb8bd13f69c3d9cc147dd2,3d70d7a3fe3b87059833e3dee52d943fff5184d7..08c54ef1c1669edce960c52948b80340c36eb119
--- 1/help.c
--- 2/help.c
+++ b/help.c
@@@ -7,7 -7,6 +7,7 @@@
  #include "string-list.h"
  #include "column.h"
  #include "version.h"
 +#include "refs.h"
  
  void add_cmdname(struct cmdnames *cmds, const char *name, int len)
  {
@@@ -107,7 -106,7 +107,7 @@@ static int is_executable(const char *na
            !S_ISREG(st.st_mode))
                return 0;
  
- #if defined(WIN32) || defined(__CYGWIN__)
+ #if defined(GIT_WINDOWS_NATIVE) || defined(__CYGWIN__)
  #if defined(__CYGWIN__)
  if ((st.st_mode & S_IXUSR) == 0)
  #endif
@@@ -405,52 -404,3 +405,52 @@@ int cmd_version(int argc, const char **
        printf("git version %s\n", git_version_string);
        return 0;
  }
 +
 +struct similar_ref_cb {
 +      const char *base_ref;
 +      struct string_list *similar_refs;
 +};
 +
 +static int append_similar_ref(const char *refname, const unsigned char *sha1,
 +                            int flags, void *cb_data)
 +{
 +      struct similar_ref_cb *cb = (struct similar_ref_cb *)(cb_data);
 +      char *branch = strrchr(refname, '/') + 1;
 +      /* A remote branch of the same name is deemed similar */
 +      if (!prefixcmp(refname, "refs/remotes/") &&
 +          !strcmp(branch, cb->base_ref))
 +              string_list_append(cb->similar_refs,
 +                                 refname + strlen("refs/remotes/"));
 +      return 0;
 +}
 +
 +static struct string_list guess_refs(const char *ref)
 +{
 +      struct similar_ref_cb ref_cb;
 +      struct string_list similar_refs = STRING_LIST_INIT_NODUP;
 +
 +      ref_cb.base_ref = ref;
 +      ref_cb.similar_refs = &similar_refs;
 +      for_each_ref(append_similar_ref, &ref_cb);
 +      return similar_refs;
 +}
 +
 +void help_unknown_ref(const char *ref, const char *cmd, const char *error)
 +{
 +      int i;
 +      struct string_list suggested_refs = guess_refs(ref);
 +
 +      fprintf_ln(stderr, _("%s: %s - %s"), cmd, ref, error);
 +
 +      if (suggested_refs.nr > 0) {
 +              fprintf_ln(stderr,
 +                         Q_("\nDid you mean this?",
 +                            "\nDid you mean one of these?",
 +                            suggested_refs.nr));
 +              for (i = 0; i < suggested_refs.nr; i++)
 +                      fprintf(stderr, "\t%s\n", suggested_refs.items[i].string);
 +      }
 +
 +      string_list_clear(&suggested_refs, 0);
 +      exit(1);
 +}
diff --combined test-chmtime.c
index 94903c4bff1ea7fa8818032b5fd310c98007eee3,1cffa126569b359720a2442af065d1e7a6a9593f..923bf327f8ac8243c59292879a60e1f7364b6070
@@@ -56,7 -56,7 +56,7 @@@ static int timespec_arg(const char *arg
        return 1;
  }
  
 -int main(int argc, const char *argv[])
 +int main(int argc, char *argv[])
  {
        static int verbose;
  
@@@ -87,7 -87,7 +87,7 @@@
                        return -1;
                }
  
- #ifdef WIN32
+ #ifdef GIT_WINDOWS_NATIVE
                if (!(sb.st_mode & S_IWUSR) &&
                                chmod(argv[i], sb.st_mode | S_IWUSR)) {
                        fprintf(stderr, "Could not make user-writable %s: %s",