git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 10/10] Makefile: add USE_WILDMATCH to use wildmatch as fnmatch

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jan 1, 2013, 02:44 UTC
Message-ID
<1357008251-10014-11-git-send-email-pclouds@gmail.com>
In-Reply-To
<1357008251-10014-1-git-send-email-pclouds@gmail.com>

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 <pclouds@gmail.com>
---
 Makefile          |  6 ++++++
 git-compat-util.h | 13 +++++++++++++
 test-wildmatch.c  |  3 +++
 3 files changed, 22 insertions(+)
diff --git a/Makefile b/Makefile
index bc868d1..24e2774 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 02f48f6..b2c7638 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -106,7 +106,9 @@
 #include <sys/time.h>
 #include <time.h>
 #include <signal.h>
+#ifndef USE_WILDMATCH
 #include <fnmatch.h>
+#endif
 #include <assert.h>
 #include <regex.h>
 #include <utime.h>
@@ -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 ac86800..a3e2643 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"
 
-- 
1.8.0.rc2.23.g1fb49df
Previous: Nguyễn Thái Ngọc Duy
Message 19 of 19 in “fnmatch replacement”
  1. 00/10 fnmatch replacementNguyễn Thái Ngọc Duy, Jan 1, 2013
  2. 01/10 wildmatch: fix "**" special caseNguyễn Thái Ngọc Duy, Jan 1, 2013
  3. Junio C HamanoJan 22, 2013
  4. Junio C HamanoJan 22, 2013
  5. Duy NguyenJan 23, 2013
  6. Junio C HamanoJan 24, 2013
  7. Duy NguyenJan 24, 2013
  8. Junio C HamanoJan 24, 2013
  9. Duy NguyenJan 25, 2013
  10. Junio C HamanoJan 25, 2013
  11. 02/10 compat/fnmatch: respect NO_FNMATCH* even on glibcNguyễn Thái Ngọc Duy, Jan 1, 2013
  12. 03/10 wildmatch: replace variable 'special' with better named onesNguyễn Thái Ngọc Duy, Jan 1, 2013
  13. 04/10 wildmatch: rename constants and update prototypeNguyễn Thái Ngọc Duy, Jan 1, 2013
  14. 05/10 wildmatch: make dowild() take arbitrary flagsNguyễn Thái Ngọc Duy, Jan 1, 2013
  15. 06/10 wildmatch: support "no FNM_PATHNAME" modeNguyễn Thái Ngọc Duy, Jan 1, 2013
  16. 07/10 test-wildmatch: add "perf" command to compare wildmatch and fnmatchNguyễn Thái Ngọc Duy, Jan 1, 2013
  17. 08/10 wildmatch: make a special case for "*/" with FNM_PATHNAMENguyễn Thái Ngọc Duy, Jan 1, 2013
  18. 09/10 wildmatch: advance faster in <asterisk> + <literal> patternsNguyễn Thái Ngọc Duy, Jan 1, 2013
  19. 10/10 Makefile: add USE_WILDMATCH to use wildmatch as fnmatchNguyễn Thái Ngọc Duy, Jan 1, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.