Merge branch 'ef/win32-dirent'
authorJunio C Hamano <gitster@pobox.com>
Mon, 13 Dec 2010 05:49:52 +0000 (21:49 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 Dec 2010 05:49:52 +0000 (21:49 -0800)
* ef/win32-dirent:
win32: use our own dirent.h
msvc: opendir: handle paths ending with a slash
win32: dirent: handle errors
msvc: opendir: do not start the search
msvc: opendir: allocate enough memory
msvc: opendir: fix malloc-failure

Conflicts:
Makefile

1  2 
Makefile
compat/mingw.c
compat/mingw.h
diff --combined Makefile
index fd0053fa210792d653a983f1137d238c3ba9ed59,5bc9b19c57467e34141455c3504b2475b20e70ec..6439c7bd390777afbf5f89d5ba59be0e13d3839d
+++ b/Makefile
@@@ -70,11 -70,6 +70,11 @@@ all:
  #
  # Define NO_STRTOK_R if you don't have strtok_r in the C library.
  #
 +# Define NO_FNMATCH if you don't have fnmatch in the C library.
 +#
 +# Define NO_FNMATCH_CASEFOLD if your fnmatch function doesn't have the
 +# FNM_CASEFOLD GNU extension.
 +#
  # Define NO_LIBGEN_H if you don't have libgen.h.
  #
  # Define NEEDS_LIBGEN if your libgen needs -lgen when linking
  # Define NO_ST_BLOCKS_IN_STRUCT_STAT if your platform does not have st_blocks
  # field that counts the on-disk footprint in 512-byte blocks.
  #
 -# Define ASCIIDOC8 if you want to format documentation with AsciiDoc 8
 +# Define ASCIIDOC7 if you want to format documentation with AsciiDoc 7
  #
  # Define DOCBOOK_XSL_172 if you want to format man pages with DocBook XSL v1.72
  # (not v1.73 or v1.71).
  #
 -# Define ASCIIDOC_NO_ROFF if your DocBook XSL escapes raw roff directives
 -# (versions 1.72 and later and 1.68.1 and earlier).
 +# Define ASCIIDOC_ROFF if your DocBook XSL does not escape raw roff directives
 +# (versions 1.68.1 through v1.72).
  #
  # Define GNU_ROFF if your target system uses GNU groff.  This forces
  # apostrophes to be ASCII so that cut&pasting examples to the shell
@@@ -504,6 -499,7 +504,7 @@@ LIB_H += compat/mingw.
  LIB_H += compat/win32/pthread.h
  LIB_H += compat/win32/syslog.h
  LIB_H += compat/win32/sys/poll.h
+ LIB_H += compat/win32/dirent.h
  LIB_H += csum-file.h
  LIB_H += decorate.h
  LIB_H += delta.h
@@@ -525,7 -521,6 +526,7 @@@ LIB_H += mailmap.
  LIB_H += merge-recursive.h
  LIB_H += notes.h
  LIB_H += notes-cache.h
 +LIB_H += notes-merge.h
  LIB_H += object.h
  LIB_H += pack.h
  LIB_H += pack-refs.h
@@@ -616,7 -611,6 +617,7 @@@ LIB_OBJS += merge-recursive.
  LIB_OBJS += name-hash.o
  LIB_OBJS += notes.o
  LIB_OBJS += notes-cache.o
 +LIB_OBJS += notes-merge.o
  LIB_OBJS += object.o
  LIB_OBJS += pack-check.o
  LIB_OBJS += pack-refs.o
@@@ -672,7 -666,6 +673,7 @@@ LIB_OBJS += write_or_die.
  LIB_OBJS += ws.o
  LIB_OBJS += wt-status.o
  LIB_OBJS += xdiff-interface.o
 +LIB_OBJS += zlib.o
  
  BUILTIN_OBJS += builtin/add.o
  BUILTIN_OBJS += builtin/annotate.o
@@@ -739,8 -732,6 +740,8 @@@ BUILTIN_OBJS += builtin/read-tree.
  BUILTIN_OBJS += builtin/receive-pack.o
  BUILTIN_OBJS += builtin/reflog.o
  BUILTIN_OBJS += builtin/remote.o
 +BUILTIN_OBJS += builtin/remote-ext.o
 +BUILTIN_OBJS += builtin/remote-fd.o
  BUILTIN_OBJS += builtin/replace.o
  BUILTIN_OBJS += builtin/rerere.o
  BUILTIN_OBJS += builtin/reset.o
@@@ -859,7 -850,6 +860,7 @@@ ifeq ($(uname_S),SunOS
        NO_MKDTEMP = YesPlease
        NO_MKSTEMPS = YesPlease
        NO_REGEX = YesPlease
 +      NO_FNMATCH_CASEFOLD = YesPlease
        ifeq ($(uname_R),5.6)
                SOCKLEN_T = int
                NO_HSTRERROR = YesPlease
@@@ -1066,7 -1056,6 +1067,7 @@@ ifeq ($(uname_S),Windows
        NO_STRCASESTR = YesPlease
        NO_STRLCPY = YesPlease
        NO_STRTOK_R = YesPlease
 +      NO_FNMATCH = YesPlease
        NO_MEMMEM = YesPlease
        # NEEDS_LIBICONV = YesPlease
        NO_ICONV = YesPlease
        AR = compat/vcbuild/scripts/lib.pl
        CFLAGS =
        BASIC_CFLAGS = -nologo -I. -I../zlib -Icompat/vcbuild -Icompat/vcbuild/include -DWIN32 -D_CONSOLE -DHAVE_STRING_H -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE
-       COMPAT_OBJS = compat/msvc.o compat/winansi.o compat/win32/pthread.o compat/win32/syslog.o compat/win32/sys/poll.o
 -      COMPAT_OBJS = compat/msvc.o compat/fnmatch/fnmatch.o compat/winansi.o \
++      COMPAT_OBJS = compat/msvc.o compat/winansi.o \
+               compat/win32/pthread.o compat/win32/syslog.o \
+               compat/win32/sys/poll.o compat/win32/dirent.o
 -      COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DNOGDI -DHAVE_STRING_H -DHAVE_ALLOCA_H -Icompat -Icompat/fnmatch -Icompat/regex -Icompat/fnmatch -Icompat/win32 -DSTRIP_EXTENSION=\".exe\"
 +      COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DNOGDI -DHAVE_STRING_H -DHAVE_ALLOCA_H -Icompat -Icompat/regex -Icompat/win32 -DSTRIP_EXTENSION=\".exe\"
        BASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO -SUBSYSTEM:CONSOLE -NODEFAULTLIB:MSVCRT.lib
        EXTLIBS = advapi32.lib shell32.lib wininet.lib ws2_32.lib
        PTHREAD_LIBS =
  endif
        X = .exe
  endif
 +ifeq ($(uname_S),Interix)
 +      NO_SYS_POLL_H = YesPlease
 +      NO_INTTYPES_H = YesPlease
 +      NO_INITGROUPS = YesPlease
 +      NO_IPV6 = YesPlease
 +      NO_MEMMEM = YesPlease
 +      NO_MKDTEMP = YesPlease
 +      NO_STRTOUMAX = YesPlease
 +      NO_NSEC = YesPlease
 +      NO_MKSTEMPS = YesPlease
 +      ifeq ($(uname_R),3.5)
 +              NO_INET_NTOP = YesPlease
 +              NO_INET_PTON = YesPlease
 +      endif
 +      ifeq ($(uname_R),5.2)
 +              NO_INET_NTOP = YesPlease
 +              NO_INET_PTON = YesPlease
 +      endif
 +endif
  ifneq (,$(findstring MINGW,$(uname_S)))
        pathsep = ;
        NO_PREAD = YesPlease
        NO_STRCASESTR = YesPlease
        NO_STRLCPY = YesPlease
        NO_STRTOK_R = YesPlease
 +      NO_FNMATCH = YesPlease
        NO_MEMMEM = YesPlease
        NEEDS_LIBICONV = YesPlease
        OLD_ICONV = YesPlease
        NO_INET_PTON = YesPlease
        NO_INET_NTOP = YesPlease
        NO_POSIX_GOODIES = UnfortunatelyYes
 -      COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/fnmatch -Icompat/win32
 +      COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/win32
        COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
 -      COMPAT_OBJS += compat/mingw.o compat/fnmatch/fnmatch.o compat/winansi.o \
 +      COMPAT_OBJS += compat/mingw.o compat/winansi.o \
                compat/win32/pthread.o compat/win32/syslog.o \
-               compat/win32/sys/poll.o
+               compat/win32/sys/poll.o compat/win32/dirent.o
        EXTLIBS += -lws2_32
        PTHREAD_LIBS =
        X = .exe
@@@ -1377,17 -1348,6 +1380,17 @@@ ifdef NO_STRTOK_
        COMPAT_CFLAGS += -DNO_STRTOK_R
        COMPAT_OBJS += compat/strtok_r.o
  endif
 +ifdef NO_FNMATCH
 +      COMPAT_CFLAGS += -Icompat/fnmatch
 +      COMPAT_CFLAGS += -DNO_FNMATCH
 +      COMPAT_OBJS += compat/fnmatch/fnmatch.o
 +else
 +ifdef NO_FNMATCH_CASEFOLD
 +      COMPAT_CFLAGS += -Icompat/fnmatch
 +      COMPAT_CFLAGS += -DNO_FNMATCH_CASEFOLD
 +      COMPAT_OBJS += compat/fnmatch/fnmatch.o
 +endif
 +endif
  ifdef NO_SETENV
        COMPAT_CFLAGS += -DNO_SETENV
        COMPAT_OBJS += compat/setenv.o
@@@ -1406,15 -1366,6 +1409,15 @@@ endi
  ifdef NO_SYS_SELECT_H
        BASIC_CFLAGS += -DNO_SYS_SELECT_H
  endif
 +ifdef NO_SYS_POLL_H
 +      BASIC_CFLAGS += -DNO_SYS_POLL_H
 +endif
 +ifdef NO_INTTYPES_H
 +      BASIC_CFLAGS += -DNO_INTTYPES_H
 +endif
 +ifdef NO_INITGROUPS
 +      BASIC_CFLAGS += -DNO_INITGROUPS
 +endif
  ifdef NO_MMAP
        COMPAT_CFLAGS += -DNO_MMAP
        COMPAT_OBJS += compat/mmap.o
@@@ -1579,8 -1530,8 +1582,8 @@@ ifndef 
  endif
  endif
  
 -ifdef ASCIIDOC8
 -      export ASCIIDOC8
 +ifdef ASCIIDOC7
 +      export ASCIIDOC7
  endif
  
  # Shell quote (do not use $(call) to accommodate ancient setups);
@@@ -1827,8 -1778,6 +1830,8 @@@ XDIFF_OBJS = xdiff/xdiffi.o xdiff/xprep
        xdiff/xmerge.o xdiff/xpatience.o
  VCSSVN_OBJS = vcs-svn/string_pool.o vcs-svn/line_buffer.o \
        vcs-svn/repo_tree.o vcs-svn/fast_export.o vcs-svn/svndump.o
 +VCSSVN_TEST_OBJS = test-obj-pool.o test-string-pool.o \
 +      test-line-buffer.o test-treap.o
  OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) $(VCSSVN_OBJS)
  
  dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d)
@@@ -1937,12 -1886,13 +1940,12 @@@ builtin/branch.o builtin/checkout.o bui
  builtin/bundle.o bundle.o transport.o: bundle.h
  builtin/bisect--helper.o builtin/rev-list.o bisect.o: bisect.h
  builtin/clone.o builtin/fetch-pack.o transport.o: fetch-pack.h
 -builtin/grep.o: thread-utils.h
 +builtin/grep.o builtin/pack-objects.o transport-helper.o: thread-utils.h
  builtin/send-pack.o transport.o: send-pack.h
  builtin/log.o builtin/shortlog.o: shortlog.h
  builtin/prune.o builtin/reflog.o reachable.o: reachable.h
  builtin/commit.o builtin/revert.o wt-status.o: wt-status.h
  builtin/tar-tree.o archive-tar.o: tar.h
 -builtin/pack-objects.o: thread-utils.h
  connect.o transport.o http-backend.o: url.h
  http-fetch.o http-walker.o remote-curl.o transport.o walker.o: walker.h
  http.o http-walker.o http-push.o http-fetch.o remote-curl.o: http.h
@@@ -1951,12 -1901,10 +1954,12 @@@ xdiff-interface.o $(XDIFF_OBJS): 
        xdiff/xinclude.h xdiff/xmacros.h xdiff/xdiff.h xdiff/xtypes.h \
        xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h
  
 -$(VCSSVN_OBJS): \
 +$(VCSSVN_OBJS) $(VCSSVN_TEST_OBJS): $(LIB_H) \
        vcs-svn/obj_pool.h vcs-svn/trp.h vcs-svn/string_pool.h \
        vcs-svn/line_buffer.h vcs-svn/repo_tree.h vcs-svn/fast_export.h \
        vcs-svn/svndump.h
 +
 +test-svn-fe.o: vcs-svn/svndump.h
  endif
  
  exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
@@@ -1991,7 -1939,7 +1994,7 @@@ git-%$X: %.o $(GITLIBS
  
  git-imap-send$X: imap-send.o $(GITLIBS)
        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
 -              $(LIBS) $(OPENSSL_LINK) $(OPENSSL_LIBSSL)
 +              $(LIBS) $(OPENSSL_LINK) $(OPENSSL_LIBSSL) $(LIB_4_CRYPTO)
  
  git-http-fetch$X: revision.o http.o http-walker.o http-fetch.o $(GITLIBS)
        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
diff --combined compat/mingw.c
index fdbf093f6eb704ec0ca0e5abf6baf1f94350676b,071863ae7e201fa4574fa5590b93e3458892acb4..bee605441910caeddd1e94eb7795f615a3d1348a
@@@ -198,10 -198,9 +198,10 @@@ static inline time_t filetime_to_time_t
   */
  static int do_lstat(int follow, const char *file_name, struct stat *buf)
  {
 +      int err;
        WIN32_FILE_ATTRIBUTE_DATA fdata;
  
 -      if (!(errno = get_file_attr(file_name, &fdata))) {
 +      if (!(err = get_file_attr(file_name, &fdata))) {
                buf->st_ino = 0;
                buf->st_gid = 0;
                buf->st_uid = 0;
                }
                return 0;
        }
 +      errno = err;
        return -1;
  }
  
@@@ -1566,63 -1564,3 +1566,3 @@@ pid_t waitpid(pid_t pid, int *status, u
        errno = EINVAL;
        return -1;
  }
- #ifndef NO_MINGW_REPLACE_READDIR
- /* MinGW readdir implementation to avoid extra lstats for Git */
- struct mingw_DIR
- {
-       struct _finddata_t      dd_dta;         /* disk transfer area for this dir */
-       struct mingw_dirent     dd_dir;         /* Our own implementation, including d_type */
-       long                    dd_handle;      /* _findnext handle */
-       int                     dd_stat;        /* 0 = next entry to read is first entry, -1 = off the end, positive = 0 based index of next entry */
-       char                    dd_name[1];     /* given path for dir with search pattern (struct is extended) */
- };
- struct dirent *mingw_readdir(DIR *dir)
- {
-       WIN32_FIND_DATAA buf;
-       HANDLE handle;
-       struct mingw_DIR *mdir = (struct mingw_DIR*)dir;
-       if (!dir->dd_handle) {
-               errno = EBADF; /* No set_errno for mingw */
-               return NULL;
-       }
-       if (dir->dd_handle == (long)INVALID_HANDLE_VALUE && dir->dd_stat == 0)
-       {
-               DWORD lasterr;
-               handle = FindFirstFileA(dir->dd_name, &buf);
-               lasterr = GetLastError();
-               dir->dd_handle = (long)handle;
-               if (handle == INVALID_HANDLE_VALUE && (lasterr != ERROR_NO_MORE_FILES)) {
-                       errno = err_win_to_posix(lasterr);
-                       return NULL;
-               }
-       } else if (dir->dd_handle == (long)INVALID_HANDLE_VALUE) {
-               return NULL;
-       } else if (!FindNextFileA((HANDLE)dir->dd_handle, &buf)) {
-               DWORD lasterr = GetLastError();
-               FindClose((HANDLE)dir->dd_handle);
-               dir->dd_handle = (long)INVALID_HANDLE_VALUE;
-               /* POSIX says you shouldn't set errno when readdir can't
-                  find any more files; so, if another error we leave it set. */
-               if (lasterr != ERROR_NO_MORE_FILES)
-                       errno = err_win_to_posix(lasterr);
-               return NULL;
-       }
-       /* We get here if `buf' contains valid data.  */
-       strcpy(dir->dd_dir.d_name, buf.cFileName);
-       ++dir->dd_stat;
-       /* Set file type, based on WIN32_FIND_DATA */
-       mdir->dd_dir.d_type = 0;
-       if (buf.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
-               mdir->dd_dir.d_type |= DT_DIR;
-       else
-               mdir->dd_dir.d_type |= DT_REG;
-       return (struct dirent*)&dir->dd_dir;
- }
- #endif // !NO_MINGW_REPLACE_READDIR
diff --combined compat/mingw.h
index 35d9813b6badb34068601f35302f8859a786db05,40434d33955f76c6f8b7745146db70a494abf080..228307110971c7b3259953730687c0e90b07a49c
@@@ -37,9 -37,6 +37,9 @@@ typedef int socklen_t
  #define WEXITSTATUS(x) ((x) & 0xff)
  #define WTERMSIG(x) SIGTERM
  
 +#define EWOULDBLOCK EAGAIN
 +#define SHUT_WR SD_SEND
 +
  #define SIGHUP 1
  #define SIGQUIT 3
  #define SIGKILL 9
@@@ -322,35 -319,6 +322,6 @@@ int main(int argc, const char **argv) 
  } \
  static int mingw_main(c,v)
  
- #ifndef NO_MINGW_REPLACE_READDIR
- /*
-  * A replacement of readdir, to ensure that it reads the file type at
-  * the same time. This avoid extra unneeded lstats in git on MinGW
-  */
- #undef DT_UNKNOWN
- #undef DT_DIR
- #undef DT_REG
- #undef DT_LNK
- #define DT_UNKNOWN    0
- #define DT_DIR                1
- #define DT_REG                2
- #define DT_LNK                3
- struct mingw_dirent
- {
-       long            d_ino;                  /* Always zero. */
-       union {
-               unsigned short  d_reclen;       /* Always zero. */
-               unsigned char   d_type;         /* Reimplementation adds this */
-       };
-       unsigned short  d_namlen;               /* Length of name in d_name. */
-       char            d_name[FILENAME_MAX];   /* File name. */
- };
- #define dirent mingw_dirent
- #define readdir(x) mingw_readdir(x)
- struct dirent *mingw_readdir(DIR *dir);
- #endif // !NO_MINGW_REPLACE_READDIR
  /*
   * Used by Pthread API implementation for Windows
   */