From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 2/6] Replace has_wildcard with PATHSPEC_NOGLOB
Date: Wed, 12 Oct 2011 09:44:39 +1100 [thread overview]
Message-ID: <1318373083-13840-3-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1318373083-13840-1-git-send-email-pclouds@gmail.com>
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@gmail.com>
---
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
next prev parent reply other threads:[~2011-10-11 22:45 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-11 22:44 [PATCH 0/6] Negation magic pathspec Nguyễn Thái Ngọc Duy
2011-10-11 22:44 ` [PATCH 1/6] Recognize magic pathspec as filenames Nguyễn Thái Ngọc Duy
2011-10-12 20:49 ` Junio C Hamano
2011-10-13 4:23 ` Nguyen Thai Ngoc Duy
2011-10-13 6:06 ` Junio C Hamano
2011-10-11 22:44 ` Nguyễn Thái Ngọc Duy [this message]
2011-10-11 22:44 ` [PATCH 3/6] Convert prefix_pathspec() to produce struct pathspec_item Nguyễn Thái Ngọc Duy
2011-10-11 22:44 ` [PATCH 4/6] Implement parse_pathspec() Nguyễn Thái Ngọc Duy
2011-10-11 22:44 ` [PATCH 5/6] Convert simple init_pathspec() cases to parse_pathspec() Nguyễn Thái Ngọc Duy
2011-10-13 0:29 ` Junio C Hamano
2011-10-11 22:44 ` [PATCH 6/6] Implement negative pathspec Nguyễn Thái Ngọc Duy
2011-10-11 23:17 ` [PATCH 0/6] Negation magic pathspec Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1318373083-13840-3-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).