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

Very limited pathspec wildcards..

From
Linus Torvalds <torvalds@osdl.org>
Date
Aug 3, 2005, 17:48 UTC
Message-ID
<Pine.LNX.4.58.0508031038320.3258@g5.osdl.org>

I ended up looking at wildcards in pathspecs, but wasn't quite ready enough to pay the price of real wildcards. This limited form is the end result.

It allows a final '*' in the path matching to indicate that we don't care about the "match exact files/subdirectories only" rule.

So while
	git-whatchanged git

will only show the file called "git" (or any changes under a subdirectory called "git"),

	git-whatchanged git*
will show anything that starts with "git".
Note that this _only_ works at the very end. You can't say
	git-whatchanged git-*-script
even though maybe it would be good if we allowed full wildcards some day.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---
Btw, I'm not sure this is a wonderful idea. I found it useful for doing
	git-whatchanged -p drivers/scsi/aic7xxx/aic79xx*

since I was interested in seeign if only that particular driver had had changes. But it's hacky and pretty limited, so I throw this patch out more as a "maybe others think it is a good idea" thing.

So Junio, if you feel this is ugly, just drop it, I certainly won't mind. As it is you can't even escape the '*', so if you actually only want to match a filename that literally ends in an asterisk, this makes that impossible, and will match that file _and_ anything that shares the same prefix..

diff --git a/diff-tree.c b/diff-tree.c
--- a/diff-tree.c
+++ b/diff-tree.c
@@ -163,6 +163,12 @@ static int interesting(void *tree, unsig
 	for (i=0; i < nr_paths; i++) {
 		const char *match = paths[i];
 		int matchlen = pathlens[i];
+		int wildcard = 0;
+
+		if (matchlen && match[matchlen-1] == '*') {
+			matchlen--;
+			wildcard = 1;
+		}
 
 		if (baselen >= matchlen) {
 			/* If it doesn't match, move along... */
@@ -183,7 +189,7 @@ static int interesting(void *tree, unsig
 		if (pathlen > matchlen)
 			continue;
 
-		if (matchlen > pathlen) {
+		if (!wildcard && matchlen > pathlen) {
 			if (match[pathlen] != '/')
 				continue;
 			if (!S_ISDIR(mode))
diff --git a/read-cache.c b/read-cache.c
--- a/read-cache.c
+++ b/read-cache.c
@@ -183,10 +183,17 @@ int ce_path_match(const struct cache_ent
 	name = ce->name;
 	while ((match = *pathspec++) != NULL) {
 		int matchlen = strlen(match);
+		int wildcard = 0;
+		if (matchlen && match[matchlen-1]) {
+			matchlen--;
+			wildcard = 1;
+		}
 		if (matchlen > len)
 			continue;
 		if (memcmp(name, match, matchlen))
 			continue;
+		if (wildcard)
+			return 1;
 		if (matchlen && name[matchlen-1] == '/')
 			return 1;
 		if (name[matchlen] == '/' || !name[matchlen])
Next: Junio C Hamano
Message 1 of 3 in “Very limited pathspec wildcards..”
  1. Linus TorvaldsAug 3, 2005
  2. Junio C HamanoAug 3, 2005
  3. Linus TorvaldsAug 3, 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.