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

[PATCH 5/5] Support "**" in .gitignore and .gitattributes patterns using wildmatch()

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Sep 15, 2012, 12:02 UTC
Message-ID
<1347710524-15404-6-git-send-email-pclouds@gmail.com>
In-Reply-To
<1347710524-15404-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/gitignore.txt | 3 +++
 attr.c                      | 4 +++-
 dir.c                       | 5 ++++-
 3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
index c1f692a..eb81d31 100644
--- a/Documentation/gitignore.txt
+++ b/Documentation/gitignore.txt
@@ -93,6 +93,9 @@ PATTERN FORMAT
    For example, "Documentation/{asterisk}.html" matches
    "Documentation/git.html" but not "Documentation/ppc/ppc.html"
    or "tools/perf/Documentation/perf.html".
++
+Contrary to fnmatch(3), git matches "**" to anything including
+slashes, similar to rsync(1).
 
  - A leading slash matches the beginning of the pathname.
    For example, "/{asterisk}.c" matches "cat-file.c" but not
diff --git a/attr.c b/attr.c
index 3430faf..f06ad95 100644
--- a/attr.c
+++ b/attr.c
@@ -12,6 +12,7 @@
 #include "exec_cmd.h"
 #include "attr.h"
 #include "dir.h"
+#include "compat/wildmatch.h"
 
 const char git_attr__true[] = "(builtin)true";
 const char git_attr__false[] = "\0(builtin)false";
@@ -666,7 +667,8 @@ static int path_matches(const char *pathname, int pathlen,
 		return 0;
 	if (baselen != 0)
 		baselen++;
-	return fnmatch_icase(pattern, pathname + baselen, FNM_PATHNAME) == 0;
+	return (ignore_case && iwildmatch(pattern, pathname + baselen)) ||
+		(!ignore_case && wildmatch(pattern, pathname + baselen));
 }
 
 static int macroexpand_one(int attr_nr, int rem);
diff --git a/dir.c b/dir.c
index 4868339..c17f9ff 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;
@@ -575,7 +576,9 @@ int excluded_from_list(const char *pathname,
 			namelen -= prefix;
 		}
 
-		if (!namelen || !fnmatch_icase(exclude, name, FNM_PATHNAME))
+		if (!namelen ||
+		    ((ignore_case && iwildmatch(exclude, name)) ||
+		     (!ignore_case && wildmatch(exclude, name))))
 			return to_exclude;
 	}
 	return -1; /* undecided */
-- 
1.7.12.403.gce5cf6f.dirty
Previous: Nguyễn Thái Ngọc DuyNext: Philip Oakley
Message 7 of 34 in “Support matching "**" in .gitattributes and .gitignore”
  1. 0/5 Support matching "**" in .gitattributes and .gitignoreNguyễn Thái Ngọc Duy, Sep 15, 2012
  2. 1/5 Import wildmatch from rsyncNguyễn Thái Ngọc Duy, Sep 15, 2012
  3. Junio C HamanoSep 16, 2012
  4. 2/5 compat/wildmatch: remove static variable force_lower_caseNguyễn Thái Ngọc Duy, Sep 15, 2012
  5. 3/5 compat/wildmatch: fix case-insensitive matchingNguyễn Thái Ngọc Duy, Sep 15, 2012
  6. 4/5 Integrate wildmatch to gitNguyễn Thái Ngọc Duy, Sep 15, 2012
  7. 5/5 Support "**" in .gitignore and .gitattributes patterns using wildmatch()Nguyễn Thái Ngọc Duy, Sep 15, 2012
  8. How to create the " [PATCH 0/5]" first email?Philip Oakley, Sep 15, 2012
  9. Junio C HamanoSep 15, 2012
  10. Philip OakleySep 17, 2012
  11. Junio C HamanoSep 17, 2012
  12. Jeff KingSep 18, 2012
  13. Junio C HamanoSep 18, 2012
  14. Jeff KingSep 18, 2012
  15. Junio C HamanoSep 18, 2012
  16. Jeff KingSep 18, 2012
  17. Junio C HamanoSep 18, 2012
  18. Philip OakleySep 18, 2012
  19. Jeff KingSep 18, 2012
  20. Jeff KingSep 18, 2012
  21. Wesley J. LandakerSep 18, 2012
  22. Jan EngelhardtSep 23, 2012
  23. 0/5 Support matching "**" in .gitattributes and .gitignoreNguyễn Thái Ngọc Duy, Sep 16, 2012
  24. 1/5 Import wildmatch from rsyncNguyễn Thái Ngọc Duy, Sep 16, 2012
  25. 2/5 compat/wildmatch: remove static variable force_lower_caseNguyễn Thái Ngọc Duy, Sep 16, 2012
  26. 3/5 compat/wildmatch: fix case-insensitive matchingNguyễn Thái Ngọc Duy, Sep 16, 2012
  27. 4/5 Integrate wildmatch to gitNguyễn Thái Ngọc Duy, Sep 16, 2012
  28. Junio C HamanoSep 17, 2012
  29. Junio C HamanoSep 17, 2012
  30. Nguyen Thai Ngoc DuySep 17, 2012
  31. Nguyen Thai Ngoc DuySep 17, 2012
  32. Junio C HamanoSep 17, 2012
  33. 5/5 Support "**" in .gitignore and .gitattributes patterns using wildmatch()Nguyễn Thái Ngọc Duy, Sep 16, 2012
  34. 6/5 side-step a make rule that builds t3070-wildmatchJohannes Sixt, Sep 25, 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.