compat: add a mkstemps() compatibility function
PATCH v6 2/3 compat: add a basename() compatibility function
In reply to David AguilarSome systems such as Windows lack libgen.h so provide a basename() implementation for cross-platform use.
This introduces the NO_LIBGEN_H construct to the Makefile and autoconf scripts.
--- Makefile | 12 ++++++++++++ compat/basename.c | 19 +++++++++++++++++++ config.mak.in | 1 + configure.ac | 6 ++++++ git-compat-util.h | 7 +++++++ 5 files changed, 45 insertions(+), 0 deletions(-) create mode 100644 compat/basename.c
Makefile +12 -0
@@ -54,6 +54,8 @@ all:: # # Define NO_MKSTEMPS if you don't have mkstemps in the C library. # +# Define NO_LIBGEN_H if you don't have libgen.h. +# # Define NO_SYS_SELECT_H if you don't have sys/select.h. # # Define NO_SYMLINK_HEAD if you never want .git/HEAD to be a symbolic link.
@@ -834,6 +836,7 @@ ifneq (,$(findstring MINGW,$(uname_S))) NO_PREAD = YesPlease NO_OPENSSL = YesPlease NO_CURL = YesPlease + NO_LIBGEN_H = UnfortunatelyYes NO_SYMLINK_HEAD = YesPlease NO_IPV6 = YesPlease NO_SETENV = YesPlease
@@ -855,6 +858,7 @@ ifneq (,$(findstring MINGW,$(uname_S))) NO_POSIX_ONLY_PROGRAMS = YesPlease NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease NO_NSEC = YesPlease + USE_WIN32_FS = YesPlease USE_WIN32_MMAP = YesPlease UNRELIABLE_FSTAT = UnfortunatelyYes OBJECT_CREATION_USES_RENAMES = UnfortunatelyNeedsTo
@@ -899,6 +903,11 @@ ifndef CC_LD_DYNPATH endif endif +ifdef NO_LIBGEN_H + COMPAT_CFLAGS += -DNO_LIBGEN_H + COMPAT_OBJS += compat/basename.o +endif + ifdef NO_CURL BASIC_CFLAGS += -DNO_CURL else
@@ -1046,6 +1055,9 @@ else COMPAT_OBJS += compat/win32mmap.o endif endif +ifdef USE_WIN32_FS + COMPAT_CFLAGS += -DWIN32_FS +endif ifdef OBJECT_CREATION_USES_RENAMES COMPAT_CFLAGS += -DOBJECT_CREATION_MODE=1 endif
compat/basename.c new file +19 -0
@@ -0,0 +1,19 @@ +#include "../git-compat-util.h" + +/* Adapted from libiberty's basename.c. */ +char *gitbasename (char *path) +{ +const char *base; + +#ifdef USE_WIN32_FS +/* Skip over the disk name in MSDOS pathnames. */ +if (isalpha (path[0 ]) && path[1 ] ==':' ) + path +=2 ; +#endif +for (base = path; *path; path++) { +if (is_dir_sep (*path)) { + base = path +1 ; + } + } +return (char *)base; +}
config.mak.in +1 -0
@@ -30,6 +30,7 @@ NEEDS_SSL_WITH_CRYPTO=@NEEDS_SSL_WITH_CRYPTO@ NO_OPENSSL=@NO_OPENSSL@ NO_CURL=@NO_CURL@ NO_EXPAT=@NO_EXPAT@ +NO_LIBGEN_H=@NO_LIBGEN_H@ NEEDS_LIBICONV=@NEEDS_LIBICONV@ NEEDS_SOCKET=@NEEDS_SOCKET@ NO_SYS_SELECT_H=@NO_SYS_SELECT_H@
configure.ac +6 -0
@@ -627,6 +627,12 @@ AC_SUBST(SNPRINTF_RETURNS_BOGUS) ## (in default C library and libraries checked by AC_CHECK_LIB) AC_MSG_NOTICE([CHECKS for library functions]) # +# Define NO_LIBGEN_H if you don't have libgen.h. +AC_CHECK_HEADER([libgen.h], +[NO_LIBGEN_H=], +[NO_LIBGEN_H=UnfortunatelyYes]) +AC_SUBST(NO_LIBGEN_H) +# # Define NO_STRCASESTR if you don't have strcasestr. GIT_CHECK_FUNC(strcasestr, [NO_STRCASESTR=],
git-compat-util.h +7 -0
@@ -97,6 +97,13 @@#include "compat/mingw.h" #endif /* __MINGW32__ */ +#ifndef NO_LIBGEN_H +#include <libgen.h> +#else +#define basename gitbasename +extern char *gitbasename (char *); +#endif +#ifndef NO_ICONV #include <iconv.h> #endif
Signature · 1 line
1.6.3.1.178.g5b6b2
PATCH v6 3/3 diff: generate pretty filenames in prep_temp_blob()
Naturally, prep_temp_blob() did not care about filenames. As a result, GIT_EXTERNAL_DIFF and textconv generated filenames such as ".diff_XXXXXX".
This modifies prep_temp_blob() to generate user-friendly filenames when creating temporary files.
Diffing "name.ext" now generates "XXXXXX_name.ext".
--- cache.h | 2 ++ diff.c | 12 +++++++++++- path.c | 16 ++++++++++++++++ t/t4020-diff-external.sh | 9 +++++++++ 4 files changed, 38 insertions(+), 1 deletions(-)
cache.h +2 -0
@@ -614,6 +614,8 @@ extern int is_empty_blob_sha1(const unsigned char *sha1);int git_mkstemp (char *path,size_t n,const char *template); +int git_mkstemps (char *path,size_t n,const char *template,int suffix_len); +/* * NOTE NOTE NOTE!! *
diff.c +11 -1
@@ -1964,8 +1964,16 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp, {int fd;struct strbuf buf =STRBUF_INIT ; +struct strbuf template =STRBUF_INIT ; +char *path_dup =xstrdup (path); +const char *base =basename (path_dup); - fd =git_mkstemp (temp->tmp_path,PATH_MAX ,".diff_XXXXXX" ); +/* Generate "XXXXXX_basename.ext" */ +strbuf_addstr (&template,"XXXXXX_" ); +strbuf_addstr (&template, base); + + fd =git_mkstemps (temp->tmp_path,PATH_MAX , template.buf, +strlen (base) +1 );if (fd <0 )die ("unable to create temp-file: %s" ,strerror (errno)); if (convert_to_working_tree(path,
@@ -1981,6 +1989,8 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp, temp->hex[40 ] =0 ;sprintf (temp->mode,"%06o" , mode);strbuf_release (&buf); +strbuf_release (&template); +free (path_dup); } static struct diff_tempfile *prepare_temp_file(const char *name,
path.c +16 -0
@@ -139,6 +139,22 @@ int git_mkstemp(char *path, size_t len, const char *template)return mkstemp (path); } +/* git_mkstemps() - create tmp file with suffix honoring TMPDIR variable. */ +int git_mkstemps (char *path,size_t len,const char *template,int suffix_len) +{ +const char *tmp; +size_t n; + + tmp =getenv ("TMPDIR" ); +if (!tmp) + tmp ="/tmp" ; + n =snprintf (path, len,"%s/%s" , tmp, template); +if (len <= n) { + errno =ENAMETOOLONG ; +return -1 ; + } +return mkstemps (path, suffix_len); +}int validate_headref (const char *path) {
t/t4020-diff-external.sh +9 -0
@@ -136,6 +136,15 @@ test_expect_success 'GIT_EXTERNAL_DIFF with more than one changed files' ' GIT_EXTERNAL_DIFF=echo git diff ' +test_expect_success 'GIT_EXTERNAL_DIFF generates pretty paths' ' + touch file.ext && + git add file.ext && + echo with extension > file.ext && + GIT_EXTERNAL_DIFF=echo git diff file.ext | grep ......_file\.ext && + git update-index --force-remove file.ext && + rm file.ext +' + echo "#!$SHELL_PATH" >fake-diff.sh cat >> fake-diff.sh <<\EOF cat $2 >> crlfed.txt
Signature · 1 line
1.6.3.1.178.g5b6b2
PATCH v6 1/3 compat: add a mkstemps() compatibility function
mkstemps() is a BSD extension so provide an implementation for cross-platform use.
--- Makefile | 19 ++++++++++++++++ compat/mkstemps.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ config.mak.in | 1 + configure.ac | 7 ++++++ git-compat-util.h | 9 +++++++ 5 files changed, 99 insertions(+), 0 deletions(-) create mode 100644 compat/mkstemps.c
Makefile +19 -0
@@ -52,6 +52,8 @@ all:: # # Define NO_MKDTEMP if you don't have mkdtemp in the C library. # +# Define NO_MKSTEMPS if you don't have mkstemps in the C library. +# # Define NO_SYS_SELECT_H if you don't have sys/select.h. # # Define NO_SYMLINK_HEAD if you never want .git/HEAD to be a symbolic link.
@@ -636,10 +638,12 @@ EXTLIBS = ifeq ($(uname_S),Linux) NO_STRLCPY = YesPlease + NO_MKSTEMPS = YesPlease THREADED_DELTA_SEARCH = YesPlease endif ifeq ($(uname_S),GNU/kFreeBSD) NO_STRLCPY = YesPlease + NO_MKSTEMPS = YesPlease THREADED_DELTA_SEARCH = YesPlease endif ifeq ($(uname_S),UnixWare)
@@ -651,6 +655,7 @@ ifeq ($(uname_S),UnixWare) SHELL_PATH = /usr/local/bin/bash NO_IPV6 = YesPlease NO_HSTRERROR = YesPlease + NO_MKSTEMPS = YesPlease BASIC_CFLAGS += -Kthread BASIC_CFLAGS += -I/usr/local/include BASIC_LDFLAGS += -L/usr/local/lib
@@ -674,6 +679,7 @@ ifeq ($(uname_S),SCO_SV) SHELL_PATH = /usr/bin/bash NO_IPV6 = YesPlease NO_HSTRERROR = YesPlease + NO_MKSTEMPS = YesPlease BASIC_CFLAGS += -I/usr/local/include BASIC_LDFLAGS += -L/usr/local/lib NO_STRCASESTR = YesPlease
@@ -702,6 +708,7 @@ ifeq ($(uname_S),SunOS) NO_MEMMEM = YesPlease NO_HSTRERROR = YesPlease NO_MKDTEMP = YesPlease + NO_MKSTEMPS = YesPlease OLD_ICONV = UnfortunatelyYes ifeq ($(uname_R),5.8) NO_UNSETENV = YesPlease
@@ -724,6 +731,7 @@ ifeq ($(uname_O),Cygwin) NO_D_INO_IN_DIRENT = YesPlease NO_STRCASESTR = YesPlease NO_MEMMEM = YesPlease + NO_MKSTEMPS = YesPlease NO_SYMLINK_HEAD = YesPlease NEEDS_LIBICONV = YesPlease NO_FAST_WORKING_DIRECTORY = UnfortunatelyYes
@@ -767,11 +775,13 @@ ifeq ($(uname_S),NetBSD) BASIC_LDFLAGS += -L/usr/pkg/lib $(CC_LD_DYNPATH)/usr/pkg/lib THREADED_DELTA_SEARCH = YesPlease USE_ST_TIMESPEC = YesPlease + NO_MKSTEMPS = YesPlease endif ifeq ($(uname_S),AIX) NO_STRCASESTR=YesPlease NO_MEMMEM = YesPlease NO_MKDTEMP = YesPlease + NO_MKSTEMPS = YesPlease NO_STRLCPY = YesPlease NO_NSEC = YesPlease FREAD_READS_DIRECTORIES = UnfortunatelyYes
@@ -787,12 +797,14 @@ endif ifeq ($(uname_S),GNU) # GNU/Hurd NO_STRLCPY=YesPlease + NO_MKSTEMPS = YesPlease endif ifeq ($(uname_S),IRIX64) NO_IPV6=YesPlease NO_SETENV=YesPlease NO_STRCASESTR=YesPlease NO_MEMMEM = YesPlease + NO_MKSTEMPS = YesPlease NO_STRLCPY = YesPlease NO_SOCKADDR_STORAGE=YesPlease SHELL_PATH=/usr/gnu/bin/bash
@@ -805,6 +817,7 @@ ifeq ($(uname_S),HP-UX) NO_SETENV=YesPlease NO_STRCASESTR=YesPlease NO_MEMMEM = YesPlease + NO_MKSTEMPS = YesPlease NO_STRLCPY = YesPlease NO_MKDTEMP = YesPlease NO_UNSETENV = YesPlease
@@ -834,6 +847,7 @@ ifneq (,$(findstring MINGW,$(uname_S))) NO_C99_FORMAT = YesPlease NO_STRTOUMAX = YesPlease NO_MKDTEMP = YesPlease + NO_MKSTEMPS = YesPlease SNPRINTF_RETURNS_BOGUS = YesPlease NO_SVN_TESTS = YesPlease NO_PERL_MAKEMAKER = YesPlease
@@ -853,6 +867,7 @@ ifneq (,$(findstring MINGW,$(uname_S))) endif ifneq (,$(findstring arm,$(uname_M))) ARM_SHA1 = YesPlease + NO_MKSTEMPS = YesPlease endif -include config.mak.autogen
@@ -1011,6 +1026,10 @@ ifdef NO_MKDTEMP COMPAT_CFLAGS += -DNO_MKDTEMP COMPAT_OBJS += compat/mkdtemp.o endif +ifdef NO_MKSTEMPS + COMPAT_CFLAGS += -DNO_MKSTEMPS + COMPAT_OBJS += compat/mkstemps.o +endif ifdef NO_UNSETENV COMPAT_CFLAGS += -DNO_UNSETENV COMPAT_OBJS += compat/unsetenv.o
compat/mkstemps.c new file +63 -0
63 lines not on this page · raw message
config.mak.in +1 -0
@@ -46,6 +46,7 @@ NO_STRTOUMAX=@NO_STRTOUMAX@ NO_SETENV=@NO_SETENV@ NO_UNSETENV=@NO_UNSETENV@ NO_MKDTEMP=@NO_MKDTEMP@ +NO_MKSTEMPS=@NO_MKSTEMPS@ NO_ICONV=@NO_ICONV@ OLD_ICONV=@OLD_ICONV@ NO_DEFLATE_BOUND=@NO_DEFLATE_BOUND@
configure.ac +7 -0
@@ -677,6 +677,13 @@ GIT_CHECK_FUNC(mkdtemp, [NO_MKDTEMP=YesPlease]) AC_SUBST(NO_MKDTEMP) # +# Define NO_MKSTEMPS if you don't have mkstemps in the C library. +GIT_CHECK_FUNC(mkstemps, +[NO_MKSTEMPS=], +[NO_MKSTEMPS=YesPlease]) +AC_SUBST(NO_MKSTEMPS) +# +# # Define NO_MMAP if you want to avoid mmap. # # Define NO_ICONV if your libc does not properly support iconv.
git-compat-util.h +9 -0
@@ -113,6 +113,10 @@#define PATH_MAX 4096#endif +#ifndef TMP_MAX +#define TMP_MAX 16384 +#endif +#ifndef PRIuMAX#define PRIuMAX "llu"#endif
@@ -232,6 +236,11 @@ extern int gitsetenv(const char *, const char *, int);extern char *gitmkdtemp (char *);#endif +#ifdef NO_MKSTEMPS +#define mkstemps gitmkstemps +extern int gitmkstemps (char *,int ); +#endif +#ifdef NO_UNSETENV #define unsetenv gitunsetenvextern void gitunsetenv (const char *);
Signature · 1 line
1.6.3.1.178.g5b6b2
Re: [PATCH v6 2/3] compat: add a basename() compatibility function
In reply to David AguilarQuoted 11 lines · David Aguilar
Some systems such as Windows lack
libgen.hso provide abasename()implementation for cross-platform use. [...]compat/basename.c new file +2
-0@@ -0,0 +1,19 @@ +#include "../git-compat-util.h" +
compat/basename.c line 12
Quoted 10 lines
compat/basename.c new file +10
-0+/* Adapted from libiberty's basename.c. */ +char *gitbasename (char *path) +{ +const char *base; + +#ifdef USE_WIN32_FS +/* Skip over the disk name in MSDOS pathnames. */ +if (isalpha (path[0 ]) && path[1 ] ==':' ) + path +=2 ; +#endif
Thanks for bearing through this series everyone.. ;)
Can someone with better win32 knowledge let me know if the USE_WIN32_FS stuff is needed for msysgit?
I would really like it if there was a way to do without the #define.
Quoted 7 lines
compat/basename.c new file +7
-0+for (base = path; *path; path++) { +if (is_dir_sep (*path)) { + base = path +1 ; + } + } +return (char *)base; +}
Signature · 1 line
David
Re: [PATCH v6 2/3] compat: add a basename() compatibility function
Quoted 8 lines · David Aguilar
compat/basename.c line 12
Quoted 5 lines
compat/basename.c new file +5
-0+#ifdef USE_WIN32_FS +/* Skip over the disk name in MSDOS pathnames. */ +if (isalpha (path[0 ]) && path[1 ] ==':' ) + path +=2 ; +#endif Thanks for bearing through this series everyone.. ;)
Quoted 5 lines
Can someone with better win32 knowledge let me know if the
USE_WIN32_FSstuff is needed for msysgit?I would really like it if there was a way to do without the #define.
Isn't this essentially the same as has_dos_drive_prefix()?