]> git.ipfire.org Git - thirdparty/git.git/blame - pathspec.h
tests: use shorter labels in chainlint.sed for AIX sed
[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
NTND
24
25struct pathspec {
64acde94
NTND
26 int nr;
27 unsigned int has_wildcard:1;
28 unsigned int recursive:1;
eef3df5a 29 unsigned int recurse_submodules:1;
87323bda 30 unsigned magic;
64acde94
NTND
31 int max_depth;
32 struct pathspec_item {
8aee769f
BW
33 char *match;
34 char *original;
87323bda 35 unsigned magic;
645a29c4 36 int len, prefix;
64acde94
NTND
37 int nowildcard_len;
38 int flags;
b0db7046
BW
39 int attr_match_nr;
40 struct attr_match {
41 char *value;
42 enum attr_match_mode {
43 MATCH_SET,
44 MATCH_UNSET,
45 MATCH_VALUE,
46 MATCH_UNSPECIFIED
47 } match_mode;
48 } *attr_match;
49 struct attr_check *attr_check;
64acde94
NTND
50 } *items;
51};
52
8f4f8f45
NTND
53#define GUARD_PATHSPEC(ps, mask) \
54 do { \
55 if ((ps)->magic & ~(mask)) \
56 die("BUG:%s:%d: unsupported magic %x", \
57 __FILE__, __LINE__, (ps)->magic & ~(mask)); \
58 } while (0)
59
fc12261f
NTND
60/* parse_pathspec flags */
61#define PATHSPEC_PREFER_CWD (1<<0) /* No args means match cwd */
62#define PATHSPEC_PREFER_FULL (1<<1) /* No args means match everything */
6330a171 63#define PATHSPEC_MAXDEPTH_VALID (1<<2) /* max_depth field is valid */
87450244 64/* die if a symlink is part of the given path's directory */
2249d4db
BW
65#define PATHSPEC_SYMLINK_LEADING_PATH (1<<3)
66#define PATHSPEC_PREFIX_ORIGIN (1<<4)
67#define PATHSPEC_KEEP_ORDER (1<<5)
4a2d5ae2
NTND
68/*
69 * For the callers that just need pure paths from somewhere else, not
70 * from command line. Global --*-pathspecs options are ignored. No
71 * magic is parsed in each pathspec either. If PATHSPEC_LITERAL is
72 * allowed, then it will automatically set for every pathspec.
73 */
2249d4db 74#define PATHSPEC_LITERAL_PATH (1<<6)
fc12261f 75
29c0e902
JN
76/*
77 * Given command line arguments and a prefix, convert the input to
78 * pathspec. die() if any magic in magic_mask is used.
79 *
80 * Any arguments used are copied. It is safe for the caller to modify
81 * or free 'prefix' and 'args' after calling this function.
82 */
87323bda
NTND
83extern void parse_pathspec(struct pathspec *pathspec,
84 unsigned magic_mask,
85 unsigned flags,
86 const char *prefix,
87 const char **args);
e4d92cdc 88extern void copy_pathspec(struct pathspec *dst, const struct pathspec *src);
ed6e8038 89extern void clear_pathspec(struct pathspec *);
64acde94 90
93d93537
NTND
91static inline int ps_strncmp(const struct pathspec_item *item,
92 const char *s1, const char *s2, size_t n)
93{
94 if (item->magic & PATHSPEC_ICASE)
95 return strncasecmp(s1, s2, n);
96 else
97 return strncmp(s1, s2, n);
98}
99
100static inline int ps_strcmp(const struct pathspec_item *item,
101 const char *s1, const char *s2)
102{
103 if (item->magic & PATHSPEC_ICASE)
104 return strcasecmp(s1, s2);
105 else
106 return strcmp(s1, s2);
107}
108
08de9151
BW
109extern void add_pathspec_matches_against_index(const struct pathspec *pathspec,
110 const struct index_state *istate,
111 char *seen);
112extern char *find_pathspecs_matching_against_index(const struct pathspec *pathspec,
113 const struct index_state *istate);
6f525e71
AS
114
115#endif /* PATHSPEC_H */