]> git.ipfire.org Git - thirdparty/git.git/blame - pathspec.h
docs: address typos in Git v2.45 changelog
[thirdparty/git.git] / pathspec.h
CommitLineData
6f525e71
AS
1#ifndef PATHSPEC_H
2#define PATHSPEC_H
3
ef3ca954
EN
4struct index_state;
5
87323bda
NTND
6/* Pathspec magic */
7#define PATHSPEC_FROMTOP (1<<0)
6330a171 8#define PATHSPEC_MAXDEPTH (1<<1)
5c6933d2 9#define PATHSPEC_LITERAL (1<<2)
bd30c2e4 10#define PATHSPEC_GLOB (1<<3)
93d93537 11#define PATHSPEC_ICASE (1<<4)
ef79b1f8 12#define PATHSPEC_EXCLUDE (1<<5)
b0db7046 13#define PATHSPEC_ATTR (1<<6)
6330a171
NTND
14#define PATHSPEC_ALL_MAGIC \
15 (PATHSPEC_FROMTOP | \
5c6933d2 16 PATHSPEC_MAXDEPTH | \
bd30c2e4 17 PATHSPEC_LITERAL | \
93d93537 18 PATHSPEC_GLOB | \
ef79b1f8 19 PATHSPEC_ICASE | \
b0db7046
BW
20 PATHSPEC_EXCLUDE | \
21 PATHSPEC_ATTR)
87323bda 22
fadf96ab 23#define PATHSPEC_ONESTAR 1 /* the pathspec pattern satisfies GFNM_ONESTAR */
64acde94 24
19ef3ddd
HW
25/**
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().
29 */
64acde94 30struct pathspec {
64acde94
NTND
31 int nr;
32 unsigned int has_wildcard:1;
33 unsigned int recursive:1;
eef3df5a 34 unsigned int recurse_submodules:1;
87323bda 35 unsigned magic;
64acde94
NTND
36 int max_depth;
37 struct pathspec_item {
8aee769f
BW
38 char *match;
39 char *original;
87323bda 40 unsigned magic;
645a29c4 41 int len, prefix;
64acde94
NTND
42 int nowildcard_len;
43 int flags;
b0db7046
BW
44 int attr_match_nr;
45 struct attr_match {
46 char *value;
47 enum attr_match_mode {
48 MATCH_SET,
49 MATCH_UNSET,
50 MATCH_VALUE,
51 MATCH_UNSPECIFIED
52 } match_mode;
53 } *attr_match;
54 struct attr_check *attr_check;
64acde94
NTND
55 } *items;
56};
57
8f4f8f45
NTND
58#define GUARD_PATHSPEC(ps, mask) \
59 do { \
60 if ((ps)->magic & ~(mask)) \
a78537a0 61 BUG("unsupported magic %x", (ps)->magic & ~(mask)); \
8f4f8f45
NTND
62 } while (0)
63
fc12261f
NTND
64/* parse_pathspec flags */
65#define PATHSPEC_PREFER_CWD (1<<0) /* No args means match cwd */
66#define PATHSPEC_PREFER_FULL (1<<1) /* No args means match everything */
6330a171 67#define PATHSPEC_MAXDEPTH_VALID (1<<2) /* max_depth field is valid */
87450244 68/* die if a symlink is part of the given path's directory */
2249d4db
BW
69#define PATHSPEC_SYMLINK_LEADING_PATH (1<<3)
70#define PATHSPEC_PREFIX_ORIGIN (1<<4)
71#define PATHSPEC_KEEP_ORDER (1<<5)
4a2d5ae2
NTND
72/*
73 * For the callers that just need pure paths from somewhere else, not
74 * from command line. Global --*-pathspecs options are ignored. No
75 * magic is parsed in each pathspec either. If PATHSPEC_LITERAL is
76 * allowed, then it will automatically set for every pathspec.
77 */
2249d4db 78#define PATHSPEC_LITERAL_PATH (1<<6)
fc12261f 79
19ef3ddd 80/**
29c0e902
JN
81 * Given command line arguments and a prefix, convert the input to
82 * pathspec. die() if any magic in magic_mask is used.
83 *
84 * Any arguments used are copied. It is safe for the caller to modify
85 * or free 'prefix' and 'args' after calling this function.
19ef3ddd
HW
86 *
87 * - magic_mask specifies what features that are NOT supported by the following
88 * code. If a user attempts to use such a feature, parse_pathspec() can reject
89 * it early.
90 *
91 * - flags specifies other things that the caller wants parse_pathspec to
92 * perform.
93 *
94 * - prefix and args come from cmd_* functions
95 *
96 * parse_pathspec() helps catch unsupported features and reject them politely.
97 * At a lower level, different pathspec-related functions may not support the
98 * same set of features. Such pathspec-sensitive functions are guarded with
99 * GUARD_PATHSPEC(), which will die in an unfriendly way when an unsupported
100 * feature is requested.
101 *
102 * The command designers are supposed to make sure that GUARD_PATHSPEC() never
103 * dies. They have to make sure all unsupported features are caught by
104 * parse_pathspec(), not by GUARD_PATHSPEC. grepping GUARD_PATHSPEC() should
105 * give the designers all pathspec-sensitive codepaths and what features they
106 * support.
107 *
108 * A similar process is applied when a new pathspec magic is added. The designer
109 * lifts the GUARD_PATHSPEC restriction in the functions that support the new
0e20b229 110 * magic while at the same time making sure this new feature will be
19ef3ddd
HW
111 * caught at parse_pathspec() in commands that cannot handle the new magic in
112 * some cases. grepping parse_pathspec() should help.
29c0e902 113 */
93e23798
NTND
114void parse_pathspec(struct pathspec *pathspec,
115 unsigned magic_mask,
116 unsigned flags,
117 const char *prefix,
118 const char **args);
24e4750c
AM
119/*
120 * Same as parse_pathspec() but uses file as input.
121 * When 'file' is exactly "-" it uses 'stdin' instead.
122 */
123void parse_pathspec_file(struct pathspec *pathspec,
124 unsigned magic_mask,
125 unsigned flags,
126 const char *prefix,
127 const char *file,
128 int nul_term_line);
19ef3ddd 129
93e23798
NTND
130void copy_pathspec(struct pathspec *dst, const struct pathspec *src);
131void clear_pathspec(struct pathspec *);
64acde94 132
8e32caaa
JK
133/*
134 * Add a human-readable string to "out" representing the PATHSPEC_* flags set
135 * in "magic". The result is suitable for error messages, but not for
136 * parsing as pathspec magic itself (you get 'icase' with quotes, not
137 * :(icase)).
138 */
139void pathspec_magic_names(unsigned magic, struct strbuf *out);
140
93d93537
NTND
141static inline int ps_strncmp(const struct pathspec_item *item,
142 const char *s1, const char *s2, size_t n)
143{
144 if (item->magic & PATHSPEC_ICASE)
145 return strncasecmp(s1, s2, n);
146 else
147 return strncmp(s1, s2, n);
148}
149
150static inline int ps_strcmp(const struct pathspec_item *item,
151 const char *s1, const char *s2)
152{
153 if (item->magic & PATHSPEC_ICASE)
154 return strcasecmp(s1, s2);
155 else
156 return strcmp(s1, s2);
157}
158
719630eb
MT
159enum ps_skip_worktree_action {
160 PS_HEED_SKIP_WORKTREE = 0,
161 PS_IGNORE_SKIP_WORKTREE = 1
162};
93e23798 163void add_pathspec_matches_against_index(const struct pathspec *pathspec,
847a9e5d 164 struct index_state *istate,
719630eb
MT
165 char *seen,
166 enum ps_skip_worktree_action sw_action);
93e23798 167char *find_pathspecs_matching_against_index(const struct pathspec *pathspec,
fe069dce 168 struct index_state *istate,
719630eb 169 enum ps_skip_worktree_action sw_action);
a20f7047
MT
170char *find_pathspecs_matching_skip_worktree(const struct pathspec *pathspec);
171static inline int matches_skip_worktree(const struct pathspec *pathspec,
172 int item, char **seen_ptr)
173{
174 if (!*seen_ptr)
175 *seen_ptr = find_pathspecs_matching_skip_worktree(pathspec);
176 return (*seen_ptr)[item];
177}
847a9e5d 178int match_pathspec_attrs(struct index_state *istate,
22af33be
NTND
179 const char *name, int namelen,
180 const struct pathspec_item *item);
6f525e71 181
ac48adf4
EN
182int match_pathspec(struct index_state *istate,
183 const struct pathspec *pathspec,
184 const char *name, int namelen,
185 int prefix, char *seen, int is_dir);
186
b29ad383
SY
187/*
188 * Determine whether a pathspec will match only entire index entries (non-sparse
189 * files and/or entire sparse directories). If the pathspec has the potential to
190 * match partial contents of a sparse directory, return 1 to indicate the index
191 * should be expanded to match the appropriate index entries.
192 *
193 * For the sake of simplicity, always return 1 if using a more complex "magic"
194 * pathspec.
195 */
196int pathspec_needs_expanded_index(struct index_state *istate,
197 const struct pathspec *pathspec);
198
6f525e71 199#endif /* PATHSPEC_H */