]> git.ipfire.org Git - thirdparty/git.git/blame_incremental - pathspec.h
Merge branch 'bb/unicode-12.1-reiwa'
[thirdparty/git.git] / pathspec.h
... / ...
CommitLineData
1#ifndef PATHSPEC_H
2#define PATHSPEC_H
3
4struct index_state;
5
6/* Pathspec magic */
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 \
15 (PATHSPEC_FROMTOP | \
16 PATHSPEC_MAXDEPTH | \
17 PATHSPEC_LITERAL | \
18 PATHSPEC_GLOB | \
19 PATHSPEC_ICASE | \
20 PATHSPEC_EXCLUDE | \
21 PATHSPEC_ATTR)
22
23#define PATHSPEC_ONESTAR 1 /* the pathspec pattern satisfies GFNM_ONESTAR */
24
25struct pathspec {
26 int nr;
27 unsigned int has_wildcard:1;
28 unsigned int recursive:1;
29 unsigned int recurse_submodules:1;
30 unsigned magic;
31 int max_depth;
32 struct pathspec_item {
33 char *match;
34 char *original;
35 unsigned magic;
36 int len, prefix;
37 int nowildcard_len;
38 int flags;
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;
50 } *items;
51};
52
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
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 */
63#define PATHSPEC_MAXDEPTH_VALID (1<<2) /* max_depth field is valid */
64/* die if a symlink is part of the given path's directory */
65#define PATHSPEC_SYMLINK_LEADING_PATH (1<<3)
66#define PATHSPEC_PREFIX_ORIGIN (1<<4)
67#define PATHSPEC_KEEP_ORDER (1<<5)
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 */
74#define PATHSPEC_LITERAL_PATH (1<<6)
75
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 */
83void parse_pathspec(struct pathspec *pathspec,
84 unsigned magic_mask,
85 unsigned flags,
86 const char *prefix,
87 const char **args);
88void copy_pathspec(struct pathspec *dst, const struct pathspec *src);
89void clear_pathspec(struct pathspec *);
90
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
109void add_pathspec_matches_against_index(const struct pathspec *pathspec,
110 const struct index_state *istate,
111 char *seen);
112char *find_pathspecs_matching_against_index(const struct pathspec *pathspec,
113 const struct index_state *istate);
114int match_pathspec_attrs(const struct index_state *istate,
115 const char *name, int namelen,
116 const struct pathspec_item *item);
117
118#endif /* PATHSPEC_H */