From cebcab189aa7727af5027f0215e798bbe66f2815 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Tue, 1 Jan 2013 09:44:11 +0700 Subject: [PATCH] Makefile: add USE_WILDMATCH to use wildmatch as fnmatch MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This is similar to NO_FNMATCH but it uses wildmatch instead of compat/fnmatch. This is an intermediate step to let wildmatch be used as fnmatch replacement for wider audience before it replaces fnmatch completely and compat/fnmatch is removed. fnmatch in test-wildmatch is not impacted by this and is the only place that NO_FNMATCH or NO_FNMATCH_CASEFOLD remain active when USE_WILDMATCH is set. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- Makefile | 6 ++++++ git-compat-util.h | 13 +++++++++++++ test-wildmatch.c | 3 +++ 3 files changed, 22 insertions(+) diff --git a/Makefile b/Makefile index bc868d154..24e277481 100644 --- a/Makefile +++ b/Makefile @@ -99,6 +99,9 @@ all:: # Define NO_FNMATCH_CASEFOLD if your fnmatch function doesn't have the # FNM_CASEFOLD GNU extension. # +# Define USE_WILDMATCH if you want to use Git's wildmatch +# implementation as fnmatch +# # Define NO_GECOS_IN_PWENT if you don't have pw_gecos in struct passwd # in the C library. # @@ -1625,6 +1628,9 @@ ifdef NO_FNMATCH_CASEFOLD COMPAT_OBJS += compat/fnmatch/fnmatch.o endif endif +ifdef USE_WILDMATCH + COMPAT_CFLAGS += -DUSE_WILDMATCH +endif ifdef NO_SETENV COMPAT_CFLAGS += -DNO_SETENV COMPAT_OBJS += compat/setenv.o diff --git a/git-compat-util.h b/git-compat-util.h index 02f48f653..b2c7638ae 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -106,7 +106,9 @@ #include #include #include +#ifndef USE_WILDMATCH #include +#endif #include #include #include @@ -238,6 +240,17 @@ extern char *gitbasename(char *); #include "compat/bswap.h" +#ifdef USE_WILDMATCH +#include "wildmatch.h" +#define FNM_PATHNAME WM_PATHNAME +#define FNM_CASEFOLD WM_CASEFOLD +#define FNM_NOMATCH WM_NOMATCH +static inline int fnmatch(const char *pattern, const char *string, int flags) +{ + return wildmatch(pattern, string, flags, NULL); +} +#endif + /* General helper functions */ extern void vreportf(const char *prefix, const char *err, va_list params); extern void vwritef(int fd, const char *prefix, const char *err, va_list params); diff --git a/test-wildmatch.c b/test-wildmatch.c index ac86800d5..a3e2643fb 100644 --- a/test-wildmatch.c +++ b/test-wildmatch.c @@ -1,3 +1,6 @@ +#ifdef USE_WILDMATCH +#undef USE_WILDMATCH /* We need real fnmatch implementation here */ +#endif #include "cache.h" #include "wildmatch.h" -- 2.26.2