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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]