# Very limited pathspec wildcards..

3 messages from 2005-08-03 to 2005-08-03. Participants: Linus Torvalds, Junio C Hamano.
Thread: https://gitlist.dev/t/1409

## Linus Torvalds, 2005-08-03 17:48

Subject: Very limited pathspec wildcards..
Message-ID: <Pine.LNX.4.58.0508031038320.3258@g5.osdl.org>
URL: https://gitlist.dev/e/Pine.LNX.4.58.0508031038320.3258%40g5.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])

```

## Junio C Hamano, 2005-08-03 19:02

Subject: Re: Very limited pathspec wildcards..
Message-ID: <7voe8ec08j.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7voe8ec08j.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <Pine.LNX.4.58.0508031038320.3258@g5.osdl.org>

```
Linus Torvalds <torvalds@osdl.org> writes:

> 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. 

Wouldn't something like this work equally well?

    #!/bin/sh
    git-whatchanged -r |
    sed -ne '
    /^:/s|aic7xxx/aic79xx|&|p
    /^:/d
    p' | git-diff-helper

```

## Linus Torvalds, 2005-08-03 19:38

Subject: Re: Very limited pathspec wildcards..
Message-ID: <Pine.LNX.4.58.0508031234280.3258@g5.osdl.org>
URL: https://gitlist.dev/e/Pine.LNX.4.58.0508031234280.3258%40g5.osdl.org
In-Reply-To: <7voe8ec08j.fsf@assigned-by-dhcp.cox.net>

```


On Wed, 3 Aug 2005, Junio C Hamano wrote:
> 
> Wouldn't something like this work equally well?

Nope, for several reasons:
 - it's _horribly_ inefficient (ie it traverses directories that it 
   doesn't need to)
 - it shows all the changeset comments, regardless of whether they are 
   releant or not. It just removes the diffs.

Try it out.

Junio, name-based filters _have_ to be done early. This is why
"diffcore-pathspec" isn't used any more - it's _much_ too inefficient to
do it later.

		Linus

```
