{"thread":{"id":"11009","subject":"[RFC/PATCH] Making ce_path_match() more useful by accepting globs","startedAt":"2007-11-25T20:35:18Z","lastAt":"2007-11-26T19:56:59Z","messageCount":2,"participants":["Junio C Hamano","Alex Riesen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"60848","messageId":"7vsl2ujc6x.fsf@gitster.siamese.dyndns.org","threadId":"11009","inReplyTo":null,"subject":"[RFC/PATCH] Making ce_path_match() more useful by accepting globs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-11-25T20:35:18Z","receivedAt":"2007-11-25T20:35:18Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Currently, these do not work:\n\n   git diff-files 't/*.sh'\n   git diff-index HEAD 'xdiff/*.c'\n   git update-index -g 'Documentation/howto/*.txt'\n\nThis is because ce_path_match(), the underlying function that is used to\nsee if a cache entry matches the set of pathspecs, only understands\nleading directory match.\n\nThis teaches ce_path_match() to use the match_pathspec() used in\ngit-ls-files, which knows about glob patterns.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n [SORRY FOR A RESEND -- I screwed up the To: field of the previous message]\n\n * Having two different behaviours of pathspec matching has been\n   bothering me for quite some time.  The changes here look trivially\n   correct and the result passes all the tests, but this is quite close\n   to the core part of the system, and would benefit greatly from extra\n   set of eyes.\n\n   This patch does not touch the tree walker, and does not affect\n   diff-tree nor ancestry pruning done in the revision traversal.  That\n   however is even closer to the core and is performance critical.  It\n   needs to be done carefully not to descend into trees that would never\n   match needlessly.  IOW, not today.\n\n dir.c        |    5 +++--\n read-cache.c |   17 ++---------------\n 2 files changed, 5 insertions(+), 17 deletions(-)\n\ndiff --git a/dir.c b/dir.c\nindex 225fdfb..be640c9 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -98,20 +98,21 @@ int match_pathspec(const char **pathspec, const char *name, int namelen, int pre\n {\n \tint retval;\n \tconst char *match;\n+\tint want_seen = !!seen;\n \n \tname += prefix;\n \tnamelen -= prefix;\n \n \tfor (retval = 0; (match = *pathspec++) != NULL; seen++) {\n \t\tint how;\n-\t\tif (retval && *seen == MATCHED_EXACTLY)\n+\t\tif (retval && seen && want_seen && *seen == MATCHED_EXACTLY)\n \t\t\tcontinue;\n \t\tmatch += prefix;\n \t\thow = match_one(match, name, namelen);\n \t\tif (how) {\n \t\t\tif (retval < how)\n \t\t\t\tretval = how;\n-\t\t\tif (*seen < how)\n+\t\t\tif (want_seen && *seen < how)\n \t\t\t\t*seen = how;\n \t\t}\n \t}\ndiff --git a/read-cache.c b/read-cache.c\nindex 7db5588..767464e 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -472,7 +472,7 @@ int ce_same_name(struct cache_entry *a, struct cache_entry *b)\n \n int ce_path_match(const struct cache_entry *ce, const char **pathspec)\n {\n-\tconst char *match, *name;\n+\tconst char *name;\n \tint len;\n \n \tif (!pathspec)\n@@ -480,20 +480,7 @@ int ce_path_match(const struct cache_entry *ce, const char **pathspec)\n \n \tlen = ce_namelen(ce);\n \tname = ce->name;\n-\twhile ((match = *pathspec++) != NULL) {\n-\t\tint matchlen = strlen(match);\n-\t\tif (matchlen > len)\n-\t\t\tcontinue;\n-\t\tif (memcmp(name, match, matchlen))\n-\t\t\tcontinue;\n-\t\tif (matchlen && name[matchlen-1] == '/')\n-\t\t\treturn 1;\n-\t\tif (name[matchlen] == '/' || !name[matchlen])\n-\t\t\treturn 1;\n-\t\tif (!matchlen)\n-\t\t\treturn 1;\n-\t}\n-\treturn 0;\n+\treturn !!match_pathspec(pathspec, name, len, 0, NULL);\n }\n \n /*\n"},{"id":"60966","messageId":"20071126195659.GC3675@steel.home","threadId":"11009","inReplyTo":"7vsl2ujc6x.fsf@gitster.siamese.dyndns.org","subject":"Re: [RFC/PATCH] Making ce_path_match() more useful by accepting globs","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-11-26T19:56:59Z","receivedAt":"2007-11-26T19:56:59Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Junio C Hamano, Sun, Nov 25, 2007 21:35:18 +0100:\n> Currently, these do not work:\n> \n>    git diff-files 't/*.sh'\n>    git diff-index HEAD 'xdiff/*.c'\n>    git update-index -g 'Documentation/howto/*.txt'\n> \n> This is because ce_path_match(), the underlying function that is used to\n> see if a cache entry matches the set of pathspecs, only understands\n> leading directory match.\n> \n> This teaches ce_path_match() to use the match_pathspec() used in\n> git-ls-files, which knows about glob patterns.\n> \n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n> \n>  [SORRY FOR A RESEND -- I screwed up the To: field of the previous message]\n> \n>  * Having two different behaviours of pathspec matching has been\n>    bothering me for quite some time.  The changes here look trivially\n>    correct and the result passes all the tests, but this is quite close\n>    to the core part of the system, and would benefit greatly from extra\n>    set of eyes.\n\nHow about doing the same what was done with recursive directory\nwalker (no, I'm not confusing pathname filters with paths)? Always\nhave the glob expansion for porcelain (git-diff, git-log, git-show),\nand add a command-line option to activate for plumbing?\n\n(Well, the oldtimers as yourself will probably find it hard to\nseparate git-diff-tree from git-diff).\n"}]}