{"thread":{"id":"1409","subject":"Very limited pathspec wildcards..","startedAt":"2005-08-03T17:48:03Z","lastAt":"2005-08-03T19:38:44Z","messageCount":3,"participants":["Linus Torvalds","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"6767","messageId":"Pine.LNX.4.58.0508031038320.3258@g5.osdl.org","threadId":"1409","inReplyTo":null,"subject":"Very limited pathspec wildcards..","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-08-03T17:48:03Z","receivedAt":"2005-08-03T17:48:03Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nI ended up looking at wildcards in pathspecs, but wasn't quite ready\nenough to pay the price of real wildcards. This limited form is the end\nresult.\n\nIt allows a final '*' in the path matching to indicate that we don't care \nabout the \"match exact files/subdirectories only\" rule.\n\nSo while\n\n\tgit-whatchanged git\n\nwill only show the file called \"git\" (or any changes under a subdirectory\ncalled \"git\"),\n\n\tgit-whatchanged git*\n\nwill show anything that starts with \"git\".\n\nNote that this _only_ works at the very end. You can't say\n\n\tgit-whatchanged git-*-script\n\neven though maybe it would be good if we allowed full wildcards some day.\n\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\n---\n\nBtw, I'm not sure this is a wonderful idea. I found it useful for doing\n\n\tgit-whatchanged -p drivers/scsi/aic7xxx/aic79xx*\n\nsince I was interested in seeign if only that particular driver had had \nchanges. But it's hacky and pretty limited, so I throw this patch out more \nas a \"maybe others think it is a good idea\" thing. \n\nSo Junio, if you feel this is ugly, just drop it, I certainly won't mind.  \nAs it is you can't even escape the '*', so if you actually only want to\nmatch a filename that literally ends in an asterisk, this makes that\nimpossible, and will match that file _and_ anything that shares the same\nprefix..\n\ndiff --git a/diff-tree.c b/diff-tree.c\n--- a/diff-tree.c\n+++ b/diff-tree.c\n@@ -163,6 +163,12 @@ static int interesting(void *tree, unsig\n \tfor (i=0; i < nr_paths; i++) {\n \t\tconst char *match = paths[i];\n \t\tint matchlen = pathlens[i];\n+\t\tint wildcard = 0;\n+\n+\t\tif (matchlen && match[matchlen-1] == '*') {\n+\t\t\tmatchlen--;\n+\t\t\twildcard = 1;\n+\t\t}\n \n \t\tif (baselen >= matchlen) {\n \t\t\t/* If it doesn't match, move along... */\n@@ -183,7 +189,7 @@ static int interesting(void *tree, unsig\n \t\tif (pathlen > matchlen)\n \t\t\tcontinue;\n \n-\t\tif (matchlen > pathlen) {\n+\t\tif (!wildcard && matchlen > pathlen) {\n \t\t\tif (match[pathlen] != '/')\n \t\t\t\tcontinue;\n \t\t\tif (!S_ISDIR(mode))\ndiff --git a/read-cache.c b/read-cache.c\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -183,10 +183,17 @@ int ce_path_match(const struct cache_ent\n \tname = ce->name;\n \twhile ((match = *pathspec++) != NULL) {\n \t\tint matchlen = strlen(match);\n+\t\tint wildcard = 0;\n+\t\tif (matchlen && match[matchlen-1]) {\n+\t\t\tmatchlen--;\n+\t\t\twildcard = 1;\n+\t\t}\n \t\tif (matchlen > len)\n \t\t\tcontinue;\n \t\tif (memcmp(name, match, matchlen))\n \t\t\tcontinue;\n+\t\tif (wildcard)\n+\t\t\treturn 1;\n \t\tif (matchlen && name[matchlen-1] == '/')\n \t\t\treturn 1;\n \t\tif (name[matchlen] == '/' || !name[matchlen])\n"},{"id":"6777","messageId":"7voe8ec08j.fsf@assigned-by-dhcp.cox.net","threadId":"1409","inReplyTo":"Pine.LNX.4.58.0508031038320.3258@g5.osdl.org","subject":"Re: Very limited pathspec wildcards..","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-08-03T19:02:36Z","receivedAt":"2005-08-03T19:02:36Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Linus Torvalds <torvalds@osdl.org> writes:\n\n> Btw, I'm not sure this is a wonderful idea. I found it useful for doing\n>\n> \tgit-whatchanged -p drivers/scsi/aic7xxx/aic79xx*\n>\n> since I was interested in seeign if only that particular driver had had \n> changes. But it's hacky and pretty limited, so I throw this patch out more \n> as a \"maybe others think it is a good idea\" thing. \n\nWouldn't something like this work equally well?\n\n    #!/bin/sh\n    git-whatchanged -r |\n    sed -ne '\n    /^:/s|aic7xxx/aic79xx|&|p\n    /^:/d\n    p' | git-diff-helper\n"},{"id":"6779","messageId":"Pine.LNX.4.58.0508031234280.3258@g5.osdl.org","threadId":"1409","inReplyTo":"7voe8ec08j.fsf@assigned-by-dhcp.cox.net","subject":"Re: Very limited pathspec wildcards..","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-08-03T19:38:44Z","receivedAt":"2005-08-03T19:38:44Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Wed, 3 Aug 2005, Junio C Hamano wrote:\n> \n> Wouldn't something like this work equally well?\n\nNope, for several reasons:\n - it's _horribly_ inefficient (ie it traverses directories that it \n   doesn't need to)\n - it shows all the changeset comments, regardless of whether they are \n   releant or not. It just removes the diffs.\n\nTry it out.\n\nJunio, name-based filters _have_ to be done early. This is why\n\"diffcore-pathspec\" isn't used any more - it's _much_ too inefficient to\ndo it later.\n\n\t\tLinus\n"}]}