Very limited pathspec wildcards..
From: Linus Torvalds <torvalds@osdl.org>
Date: 2016-06-15 22:42:03
Subsystem:
the rest · Maintainer:
Linus Torvalds
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])