Skip to content

Commit cebcab1

Browse files
pcloudsgitster
authored andcommitted
Makefile: add USE_WILDMATCH to use wildmatch as fnmatch
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6f1a31f commit cebcab1

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ all::
9999
# Define NO_FNMATCH_CASEFOLD if your fnmatch function doesn't have the
100100
# FNM_CASEFOLD GNU extension.
101101
#
102+
# Define USE_WILDMATCH if you want to use Git's wildmatch
103+
# implementation as fnmatch
104+
#
102105
# Define NO_GECOS_IN_PWENT if you don't have pw_gecos in struct passwd
103106
# in the C library.
104107
#
@@ -1625,6 +1628,9 @@ ifdef NO_FNMATCH_CASEFOLD
16251628
COMPAT_OBJS += compat/fnmatch/fnmatch.o
16261629
endif
16271630
endif
1631+
ifdef USE_WILDMATCH
1632+
COMPAT_CFLAGS += -DUSE_WILDMATCH
1633+
endif
16281634
ifdef NO_SETENV
16291635
COMPAT_CFLAGS += -DNO_SETENV
16301636
COMPAT_OBJS += compat/setenv.o

git-compat-util.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@
106106
#include <sys/time.h>
107107
#include <time.h>
108108
#include <signal.h>
109+
#ifndef USE_WILDMATCH
109110
#include <fnmatch.h>
111+
#endif
110112
#include <assert.h>
111113
#include <regex.h>
112114
#include <utime.h>
@@ -238,6 +240,17 @@ extern char *gitbasename(char *);
238240

239241
#include "compat/bswap.h"
240242

243+
#ifdef USE_WILDMATCH
244+
#include "wildmatch.h"
245+
#define FNM_PATHNAME WM_PATHNAME
246+
#define FNM_CASEFOLD WM_CASEFOLD
247+
#define FNM_NOMATCH WM_NOMATCH
248+
static inline int fnmatch(const char *pattern, const char *string, int flags)
249+
{
250+
return wildmatch(pattern, string, flags, NULL);
251+
}
252+
#endif
253+
241254
/* General helper functions */
242255
extern void vreportf(const char *prefix, const char *err, va_list params);
243256
extern void vwritef(int fd, const char *prefix, const char *err, va_list params);

test-wildmatch.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#ifdef USE_WILDMATCH
2+
#undef USE_WILDMATCH /* We need real fnmatch implementation here */
3+
#endif
14
#include "cache.h"
25
#include "wildmatch.h"
36

0 commit comments

Comments
 (0)