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

[PATCH/RFC 3/3] gitignore: support "**" with wildmatch()

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
May 7, 2012, 13:01 UTC
Message-ID
<1336395717-7799-4-git-send-email-pclouds@gmail.com>
In-Reply-To
<1336395717-7799-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 dir.c |   20 ++++++++++++++++----
 dir.h |    1 +
 2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/dir.c b/dir.c
index e98760c..75140f6 100644
--- a/dir.c
+++ b/dir.c
@@ -8,6 +8,7 @@
 #include "cache.h"
 #include "dir.h"
 #include "refs.h"
+#include "compat/wildmatch.h"
 
 struct path_simplify {
 	int len;
@@ -335,6 +336,11 @@ void add_exclude(const char *string, const char *base,
 		x->flags |= EXC_FLAG_NODIR;
 	if (no_wildcard(string))
 		x->flags |= EXC_FLAG_NOWILDCARD;
+	else if (strstr(string, "**")) {
+		if (ignore_case)
+			warning(_("core.ignorecase is ignored in '%s' because of \"**\""), string);
+		x->flags |= EXC_FLAG_WILDMATCH;
+	}
 	if (*string == '*' && no_wildcard(string+1))
 		x->flags |= EXC_FLAG_ENDSWITH;
 	ALLOC_GROW(which->excludes, which->nr + 1, which->alloc);
@@ -549,11 +555,17 @@ int excluded_from_list(const char *pathname,
 				if (x->flags & EXC_FLAG_NOWILDCARD) {
 					if (!strcmp_icase(exclude, pathname + baselen))
 						return to_exclude;
-				} else {
-					if (fnmatch_icase(exclude, pathname+baselen,
-						    FNM_PATHNAME) == 0)
-					    return to_exclude;
+					continue;
+				}
+
+				if (x->flags & EXC_FLAG_WILDMATCH) {
+					if (wildmatch(exclude, pathname + baselen))
+						return to_exclude;
+					continue;
 				}
+				if (fnmatch_icase(exclude, pathname + baselen,
+						  FNM_PATHNAME) == 0)
+					return to_exclude;
 			}
 		}
 	}
diff --git a/dir.h b/dir.h
index 58b6fc7..794f412 100644
--- a/dir.h
+++ b/dir.h
@@ -10,6 +10,7 @@ struct dir_entry {
 #define EXC_FLAG_NOWILDCARD 2
 #define EXC_FLAG_ENDSWITH 4
 #define EXC_FLAG_MUSTBEDIR 8
+#define EXC_FLAG_WILDMATCH 16
 
 struct exclude_list {
 	int nr;
-- 
1.7.8.36.g69ee2
Previous: Nguyễn Thái Ngọc DuyNext: Junio C Hamano
Message 4 of 5 in “Support ignore rule "**" using wildmatch from rsync”
  1. 0/3 Support ignore rule "**" using wildmatch from rsyncNguyễn Thái Ngọc Duy, May 7, 2012
  2. 1/3 Import wildmatch from rsyncNguyễn Thái Ngọc Duy, May 7, 2012
  3. 2/3 Integrate wildmatch to gitNguyễn Thái Ngọc Duy, May 7, 2012
  4. 3/3 gitignore: support "**" with wildmatch()Nguyễn Thái Ngọc Duy, May 7, 2012
  5. Junio C HamanoMay 7, 2012

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.