Note though "noglob" magic is not implemented yet, only its definition for internal use. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> --- builtin/ls-files.c | 2 +- builtin/ls-tree.c | 4 ++-- cache.h | 22 ++++++++++++++++++++-- dir.c | 11 +++++++---- setup.c | 17 ----------------- tree-walk.c | 7 +++---- 6 files changed, 33 insertions(+), 30 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index e8a800d..e687157 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -326,7 +326,7 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix) matchbuf[0] = prefix; matchbuf[1] = NULL; init_pathspec(&pathspec, matchbuf); - pathspec.items[0].use_wildcard = 0; + pathspec.items[0].magic = PATHSPEC_NOGLOB; } else init_pathspec(&pathspec, NULL); if (read_tree(tree, 1, &pathspec)) diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index 6b666e1..f0fa7dd 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -168,8 +168,8 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix) init_pathspec(&pathspec, get_pathspec(prefix, argv + 1)); for (i = 0; i < pathspec.nr; i++) - pathspec.items[i].use_wildcard = 0; - pathspec.has_wildcard = 0; + pathspec.items[i].magic = PATHSPEC_NOGLOB; + pathspec.magic |= PATHSPEC_NOGLOB; tree = parse_tree_indirect(sha1); if (!tree) die("not a tree object"); diff --git a/cache.h b/cache.h index 82e12c8..fe46f1e 100644 --- a/cache.h +++ b/cache.h @@ -521,16 +521,34 @@ extern int index_name_is_other(const struct index_state *, const char *, int); extern int ie_match_stat(const struct index_state *, struct cache_entry *, struct stat *, unsigned int); extern int ie_modified(const struct index_state *, struct cache_entry *, struct stat *, unsigned int); +/* + * Magic pathspec + * + * NEEDSWORK: These need to be moved to dir.h or even to a new + * pathspec.h when we restructure get_pathspec() users to use the + * "struct pathspec" interface. + * + * Possible future magic semantics include stuff like: + * + * { PATHSPEC_NOGLOB, '!', "noglob" }, + * { PATHSPEC_ICASE, '\0', "icase" }, + * { PATHSPEC_RECURSIVE, '*', "recursive" }, + * { PATHSPEC_REGEXP, '\0', "regexp" }, + * + */ +#define PATHSPEC_FROMTOP (1<<0) +#define PATHSPEC_NOGLOB (1<<1) + struct pathspec { const char **raw; /* get_pathspec() result, not freed by free_pathspec() */ int nr; - unsigned int has_wildcard:1; + unsigned magic; unsigned int recursive:1; int max_depth; struct pathspec_item { const char *match; int len; - unsigned int use_wildcard:1; + unsigned magic; } *items; }; diff --git a/dir.c b/dir.c index 08281d2..6c82615 100644 --- a/dir.c +++ b/dir.c @@ -230,7 +230,7 @@ static int match_pathspec_item(const struct pathspec_item *item, int prefix, return MATCHED_RECURSIVELY; } - if (item->use_wildcard && !fnmatch(match, name, 0)) + if (!(item->magic & PATHSPEC_NOGLOB) && !fnmatch(match, name, 0)) return MATCHED_FNMATCH; return 0; @@ -1264,19 +1264,22 @@ int init_pathspec(struct pathspec *pathspec, const char **paths) p++; pathspec->raw = paths; pathspec->nr = p - paths; + pathspec->magic = PATHSPEC_NOGLOB; if (!pathspec->nr) return 0; pathspec->items = xmalloc(sizeof(struct pathspec_item)*pathspec->nr); + memset(pathspec->items, 0, sizeof(struct pathspec_item)*pathspec->nr); for (i = 0; i < pathspec->nr; i++) { struct pathspec_item *item = pathspec->items+i; const char *path = paths[i]; item->match = path; item->len = strlen(path); - item->use_wildcard = !no_wildcard(path); - if (item->use_wildcard) - pathspec->has_wildcard = 1; + if (no_wildcard(path)) + item->magic |= PATHSPEC_NOGLOB; + else + pathspec->magic &= ~PATHSPEC_NOGLOB; } qsort(pathspec->items, pathspec->nr, diff --git a/setup.c b/setup.c index 08f605b..35db910 100644 --- a/setup.c +++ b/setup.c @@ -105,23 +105,6 @@ void verify_non_filename(const char *prefix, const char *arg) "Use '--' to separate filenames from revisions", arg); } -/* - * Magic pathspec - * - * NEEDSWORK: These need to be moved to dir.h or even to a new - * pathspec.h when we restructure get_pathspec() users to use the - * "struct pathspec" interface. - * - * Possible future magic semantics include stuff like: - * - * { PATHSPEC_NOGLOB, '!', "noglob" }, - * { PATHSPEC_ICASE, '\0', "icase" }, - * { PATHSPEC_RECURSIVE, '*', "recursive" }, - * { PATHSPEC_REGEXP, '\0', "regexp" }, - * - */ -#define PATHSPEC_FROMTOP (1<<0) - static struct pathspec_magic { unsigned bit; char mnemonic; /* this cannot be ':'! */ diff --git a/tree-walk.c b/tree-walk.c index 808bb55..db07fd6 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -586,7 +586,7 @@ int tree_entry_interesting(const struct name_entry *entry, { int i; int pathlen, baselen = base->len - base_offset; - int never_interesting = ps->has_wildcard ? 0 : -1; + int never_interesting = ps->magic & PATHSPEC_NOGLOB ? -1 : 0; if (!ps->nr) { if (!ps->recursive || ps->max_depth == -1) @@ -625,7 +625,7 @@ int tree_entry_interesting(const struct name_entry *entry, &never_interesting)) return 1; - if (ps->items[i].use_wildcard) { + if (!(ps->items[i].magic & PATHSPEC_NOGLOB)) { if (!fnmatch(match + baselen, entry->path, 0)) return 1; @@ -636,12 +636,11 @@ int tree_entry_interesting(const struct name_entry *entry, if (ps->recursive && S_ISDIR(entry->mode)) return 1; } - continue; } match_wildcards: - if (!ps->items[i].use_wildcard) + if (ps->items[i].magic & PATHSPEC_NOGLOB) continue; /* -- 1.7.3.1.256.g2539c.dirty -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html