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

[PATCH Cogito] match pathnames in exclude handling

From
Matthias Urlichs <smurf@smurf.noris.de>
Date
May 11, 2005, 05:25 UTC
Message-ID
<20050511052546.GC11192@kiste.smurf.noris.de>
In-Reply-To
<4281281F.6000101@cobite.com>
Hi,
David Mansfield:
> Is there/will there be support for path matching in the ignore files?
> 
> If the answer is no, but people like the idea, I could look into it.
> 
I already did, last week. (I do need to cleanup my changes...)

The idea is that "foo" matches anywhere, "foo/bar" the exact pathname. As a special case, "./foo" matches in the root directory only.

NB: "*" can cross subdirectory paths, so "*/foo/bar" does match
"a/b/c/foo/bar".
Signed-Off-By: Matthias Urlichs <smurf@smurf.noris.de>
---
Index: ls-files.c
===================================================================
--- 972d8624458936868e6f392b40858b7c362af8cd/ls-files.c  (mode:100644)
+++ 12deb13b12cdb338fe3fdc2e77a024490d6c39ea/ls-files.c  (mode:100644)
@@ -80,9 +80,17 @@
 	if (nr_excludes) {
 		const char *basename = strrchr(pathname, '/');
 		basename = (basename) ? basename+1 : pathname;
-		for (i = 0; i < nr_excludes; i++)
-			if (fnmatch(excludes[i], basename, 0) == 0)
-				return 1;
+		for (i = 0; i < nr_excludes; i++) {
+			if (excludes[i][0] != '.' || excludes[i][1] != '/') {
+				if (fnmatch(excludes[i], pathname, 0) == 0)
+					return 1;
+				if (basename != pathname && fnmatch(excludes[i], pathname, 0) == 0)
+					return 1;
+			} else {
+				if (fnmatch(excludes[i]+2, pathname, 0) == 0)
+					return 1;
+			}
+		}
 	}
 	return 0;
 }
@@ -129,10 +137,10 @@
 
 			if (de->d_name[0] == '.')
 				continue;
-			if (excluded(de->d_name) != show_ignored)
-				continue;
 			len = strlen(de->d_name);
 			memcpy(fullname + baselen, de->d_name, len+1);
+			if (excluded(fullname) != show_ignored)
+				continue;
 
 			switch (DTYPE(de)) {
 			struct stat st;
-- 
Matthias Urlichs   |   {M:U} IT Design @ m-u-it.de   |  smurf@smurf.noris.de
Previous: David MansfieldNext: H. Peter Anvin
Message 18 of 22 in “cg-init breaks if . contains sub-dir”
  1. cg-init breaks if . contains sub-dirBrandon Philips, May 9, 2005
  2. Morten WelinderMay 10, 2005
  3. Matthias UrlichsMay 10, 2005
  4. Brian GerstMay 10, 2005
  5. Jan-Benedict GlawMay 10, 2005
  6. Jan-Benedict GlawMay 10, 2005
  7. Matthias UrlichsMay 10, 2005
  8. Martin WaitzMay 10, 2005
  9. Jan-Benedict GlawMay 10, 2005
  10. David GreavesMay 10, 2005
  11. David GreavesMay 10, 2005
  12. Junio C HamanoMay 10, 2005
  13. Jan-Benedict GlawMay 10, 2005
  14. Matthias UrlichsMay 10, 2005
  15. Jan-Benedict GlawMay 10, 2005
  16. Matthias UrlichsMay 10, 2005
  17. David MansfieldMay 10, 2005
  18. match pathnames in exclude handlingMatthias Urlichs, May 11, 2005
  19. H. Peter AnvinMay 11, 2005
  20. Matthias UrlichsMay 12, 2005
  21. H. Peter AnvinMay 10, 2005
  22. Petr BaudisMay 12, 2005

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.