7 #define PATHSPEC_FROMTOP (1<<0)
8 #define PATHSPEC_MAXDEPTH (1<<1)
9 #define PATHSPEC_LITERAL (1<<2)
10 #define PATHSPEC_GLOB (1<<3)
11 #define PATHSPEC_ICASE (1<<4)
12 #define PATHSPEC_EXCLUDE (1<<5)
13 #define PATHSPEC_ATTR (1<<6)
14 #define PATHSPEC_ALL_MAGIC \
23 #define PATHSPEC_ONESTAR 1 /* the pathspec pattern satisfies GFNM_ONESTAR */
26 * See glossary-context.txt for the syntax of pathspec.
27 * In memory, a pathspec set is represented by "struct pathspec" and is
28 * prepared by parse_pathspec().
32 unsigned int has_wildcard
:1;
33 unsigned int recursive
:1;
34 unsigned int recurse_submodules
:1;
37 struct pathspec_item
{
47 enum attr_match_mode
{
54 struct attr_check
*attr_check
;
58 #define GUARD_PATHSPEC(ps, mask) \
60 if ((ps)->magic & ~(mask)) \
61 die("BUG:%s:%d: unsupported magic %x", \
62 __FILE__, __LINE__, (ps)->magic & ~(mask)); \
65 /* parse_pathspec flags */
66 #define PATHSPEC_PREFER_CWD (1<<0) /* No args means match cwd */
67 #define PATHSPEC_PREFER_FULL (1<<1) /* No args means match everything */
68 #define PATHSPEC_MAXDEPTH_VALID (1<<2) /* max_depth field is valid */
69 /* die if a symlink is part of the given path's directory */
70 #define PATHSPEC_SYMLINK_LEADING_PATH (1<<3)
71 #define PATHSPEC_PREFIX_ORIGIN (1<<4)
72 #define PATHSPEC_KEEP_ORDER (1<<5)
74 * For the callers that just need pure paths from somewhere else, not
75 * from command line. Global --*-pathspecs options are ignored. No
76 * magic is parsed in each pathspec either. If PATHSPEC_LITERAL is
77 * allowed, then it will automatically set for every pathspec.
79 #define PATHSPEC_LITERAL_PATH (1<<6)
82 * Given command line arguments and a prefix, convert the input to
83 * pathspec. die() if any magic in magic_mask is used.
85 * Any arguments used are copied. It is safe for the caller to modify
86 * or free 'prefix' and 'args' after calling this function.
88 * - magic_mask specifies what features that are NOT supported by the following
89 * code. If a user attempts to use such a feature, parse_pathspec() can reject
92 * - flags specifies other things that the caller wants parse_pathspec to
95 * - prefix and args come from cmd_* functions
97 * parse_pathspec() helps catch unsupported features and reject them politely.
98 * At a lower level, different pathspec-related functions may not support the
99 * same set of features. Such pathspec-sensitive functions are guarded with
100 * GUARD_PATHSPEC(), which will die in an unfriendly way when an unsupported
101 * feature is requested.
103 * The command designers are supposed to make sure that GUARD_PATHSPEC() never
104 * dies. They have to make sure all unsupported features are caught by
105 * parse_pathspec(), not by GUARD_PATHSPEC. grepping GUARD_PATHSPEC() should
106 * give the designers all pathspec-sensitive codepaths and what features they
109 * A similar process is applied when a new pathspec magic is added. The designer
110 * lifts the GUARD_PATHSPEC restriction in the functions that support the new
111 * magic. At the same time (s)he has to make sure this new feature will be
112 * caught at parse_pathspec() in commands that cannot handle the new magic in
113 * some cases. grepping parse_pathspec() should help.
115 void parse_pathspec(struct pathspec
*pathspec
,
121 void copy_pathspec(struct pathspec
*dst
, const struct pathspec
*src
);
122 void clear_pathspec(struct pathspec
*);
124 static inline int ps_strncmp(const struct pathspec_item
*item
,
125 const char *s1
, const char *s2
, size_t n
)
127 if (item
->magic
& PATHSPEC_ICASE
)
128 return strncasecmp(s1
, s2
, n
);
130 return strncmp(s1
, s2
, n
);
133 static inline int ps_strcmp(const struct pathspec_item
*item
,
134 const char *s1
, const char *s2
)
136 if (item
->magic
& PATHSPEC_ICASE
)
137 return strcasecmp(s1
, s2
);
139 return strcmp(s1
, s2
);
142 void add_pathspec_matches_against_index(const struct pathspec
*pathspec
,
143 const struct index_state
*istate
,
145 char *find_pathspecs_matching_against_index(const struct pathspec
*pathspec
,
146 const struct index_state
*istate
);
147 int match_pathspec_attrs(const struct index_state
*istate
,
148 const char *name
, int namelen
,
149 const struct pathspec_item
*item
);
151 #endif /* PATHSPEC_H */