path: root/pathspec.h
diff options
authorNguyễn Thái Ngọc Duy <>2013-07-14 08:35:28 (GMT)
committerJunio C Hamano <>2013-07-15 17:56:06 (GMT)
commit87323bdace47c3d464a783f48b16617720e8eeee (patch)
tree8beed274243cecae03fcc0e3afa61be236865366 /pathspec.h
parente4d92cdcd9450af7ae4c40de2b7c5c27a1faa138 (diff)
add parse_pathspec() that converts cmdline args to struct pathspec
Currently to fill a struct pathspec, we do: const char **paths; paths = get_pathspec(prefix, argv); ... init_pathspec(&pathspec, paths); "paths" can only carry bare strings, which loses information from command line arguments such as pathspec magic or the prefix part's length for each argument. parse_pathspec() is introduced to combine the two calls into one. The plan is gradually replace all get_pathspec() and init_pathspec() with parse_pathspec(). get_pathspec() now becomes a thin wrapper of parse_pathspec(). parse_pathspec() allows the caller to reject the pathspec magics that it does not support. When a new pathspec magic is introduced, we can enable it per command after making sure that all underlying code has no problem with the new magic. "flags" parameter is currently unused. But it would allow callers to pass certain instructions to parse_pathspec, for example forcing literal pathspec when no magic is used. With the introduction of parse_pathspec, there are now two functions that can initialize struct pathspec: init_pathspec and parse_pathspec. Any semantic changes in struct pathspec must be reflected in both functions. init_pathspec() will be phased out in favor of parse_pathspec(). Signed-off-by: Nguyễn Thái Ngọc Duy <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'pathspec.h')
1 files changed, 11 insertions, 0 deletions
diff --git a/pathspec.h b/pathspec.h
index a621676..937ec91 100644
--- a/pathspec.h
+++ b/pathspec.h
@@ -1,6 +1,10 @@
#ifndef PATHSPEC_H
#define PATHSPEC_H
+/* Pathspec magic */
+#define PATHSPEC_FROMTOP (1<<0)
#define PATHSPEC_ONESTAR 1 /* the pathspec pattern sastisfies GFNM_ONESTAR */
struct pathspec {
@@ -8,9 +12,11 @@ struct pathspec {
int nr;
unsigned int has_wildcard:1;
unsigned int recursive:1;
+ unsigned magic;
int max_depth;
struct pathspec_item {
const char *match;
+ unsigned magic;
int len;
int nowildcard_len;
int flags;
@@ -18,6 +24,11 @@ struct pathspec {
extern int init_pathspec(struct pathspec *, const char **);
+extern void parse_pathspec(struct pathspec *pathspec,
+ unsigned magic_mask,
+ unsigned flags,
+ const char *prefix,
+ const char **args);
extern void copy_pathspec(struct pathspec *dst, const struct pathspec *src);
extern void free_pathspec(struct pathspec *);