]>
Commit | Line | Data |
---|---|---|
ee1f0b1a | 1 | /* |
359fc2d2 | 2 | * Copyright (C) the libgit2 contributors. All rights reserved. |
ee1f0b1a RB |
3 | * |
4 | * This file is part of libgit2, distributed under the GNU GPL v2 with | |
5 | * a Linking Exception. For full terms see the included COPYING file. | |
6 | */ | |
7 | #ifndef INCLUDE_attr_file_h__ | |
8 | #define INCLUDE_attr_file_h__ | |
9 | ||
eae0bfdc PP |
10 | #include "common.h" |
11 | ||
55cbd05b | 12 | #include "git2/oid.h" |
ee1f0b1a RB |
13 | #include "git2/attr.h" |
14 | #include "vector.h" | |
19fa2bc1 | 15 | #include "pool.h" |
e579e0f7 | 16 | #include "str.h" |
22a2d3d5 | 17 | #include "futils.h" |
73b51450 | 18 | |
cfbc880d | 19 | #define GIT_ATTR_FILE ".gitattributes" |
c5f3da96 | 20 | #define GIT_ATTR_FILE_INREPO "attributes" |
cfbc880d | 21 | #define GIT_ATTR_FILE_SYSTEM "gitattributes" |
5540d947 | 22 | #define GIT_ATTR_FILE_XDG "attributes" |
cfbc880d | 23 | |
73b51450 RB |
24 | #define GIT_ATTR_FNMATCH_NEGATIVE (1U << 0) |
25 | #define GIT_ATTR_FNMATCH_DIRECTORY (1U << 1) | |
26 | #define GIT_ATTR_FNMATCH_FULLPATH (1U << 2) | |
27 | #define GIT_ATTR_FNMATCH_MACRO (1U << 3) | |
df743c7d | 28 | #define GIT_ATTR_FNMATCH_IGNORE (1U << 4) |
14a513e0 | 29 | #define GIT_ATTR_FNMATCH_HASWILD (1U << 5) |
2a99df69 | 30 | #define GIT_ATTR_FNMATCH_ALLOWSPACE (1U << 6) |
ec40b7f9 | 31 | #define GIT_ATTR_FNMATCH_ICASE (1U << 7) |
0d32f39e | 32 | #define GIT_ATTR_FNMATCH_MATCH_ALL (1U << 8) |
4ba64794 RB |
33 | #define GIT_ATTR_FNMATCH_ALLOWNEG (1U << 9) |
34 | #define GIT_ATTR_FNMATCH_ALLOWMACRO (1U << 10) | |
35 | ||
36 | #define GIT_ATTR_FNMATCH__INCOMING \ | |
22a2d3d5 | 37 | (GIT_ATTR_FNMATCH_ALLOWSPACE | GIT_ATTR_FNMATCH_ALLOWNEG | GIT_ATTR_FNMATCH_ALLOWMACRO) |
ee1f0b1a | 38 | |
823c0e9c | 39 | typedef enum { |
c25aa7cd PP |
40 | GIT_ATTR_FILE_SOURCE_MEMORY = 0, |
41 | GIT_ATTR_FILE_SOURCE_FILE = 1, | |
42 | GIT_ATTR_FILE_SOURCE_INDEX = 2, | |
43 | GIT_ATTR_FILE_SOURCE_HEAD = 3, | |
44 | GIT_ATTR_FILE_SOURCE_COMMIT = 4, | |
823c0e9c | 45 | |
c25aa7cd PP |
46 | GIT_ATTR_FILE_NUM_SOURCES = 5 |
47 | } git_attr_file_source_t; | |
48 | ||
49 | typedef struct { | |
50 | /* The source location for the attribute file. */ | |
51 | git_attr_file_source_t type; | |
52 | ||
53 | /* | |
54 | * The filename of the attribute file to read (relative to the | |
55 | * given base path). | |
56 | */ | |
57 | const char *base; | |
58 | const char *filename; | |
59 | ||
60 | /* | |
61 | * The commit ID when the given source type is a commit (or NULL | |
62 | * for the repository's HEAD commit.) | |
63 | */ | |
64 | git_oid *commit_id; | |
823c0e9c RB |
65 | } git_attr_file_source; |
66 | ||
0c9eacf3 VM |
67 | extern const char *git_attr__true; |
68 | extern const char *git_attr__false; | |
69 | extern const char *git_attr__unset; | |
70 | ||
ee1f0b1a RB |
71 | typedef struct { |
72 | char *pattern; | |
73 | size_t length; | |
6069042f CMN |
74 | char *containing_dir; |
75 | size_t containing_dir_length; | |
73b51450 | 76 | unsigned int flags; |
ee1f0b1a RB |
77 | } git_attr_fnmatch; |
78 | ||
823c0e9c | 79 | typedef struct { |
df743c7d RB |
80 | git_attr_fnmatch match; |
81 | git_vector assigns; /* vector of <git_attr_assignment*> */ | |
823c0e9c | 82 | } git_attr_rule; |
df743c7d | 83 | |
ee1f0b1a | 84 | typedef struct { |
73b51450 | 85 | git_refcount unused; |
ee1f0b1a | 86 | const char *name; |
0cb16fe9 | 87 | uint32_t name_hash; |
ee1f0b1a RB |
88 | } git_attr_name; |
89 | ||
90 | typedef struct { | |
df743c7d | 91 | git_refcount rc; /* for macros */ |
ee1f0b1a | 92 | char *name; |
0cb16fe9 L |
93 | uint32_t name_hash; |
94 | const char *value; | |
ee1f0b1a RB |
95 | } git_attr_assignment; |
96 | ||
823c0e9c RB |
97 | typedef struct git_attr_file_entry git_attr_file_entry; |
98 | ||
99 | typedef struct { | |
40ed4990 | 100 | git_refcount rc; |
e6e8530a | 101 | git_mutex lock; |
823c0e9c RB |
102 | git_attr_file_entry *entry; |
103 | git_attr_file_source source; | |
7d490872 RB |
104 | git_vector rules; /* vector of <rule*> or <fnmatch*> */ |
105 | git_pool pool; | |
9f779aac ET |
106 | unsigned int nonexistent:1; |
107 | int session_key; | |
dc13f1f7 RB |
108 | union { |
109 | git_oid oid; | |
c1f61af6 | 110 | git_futils_filestamp stamp; |
dc13f1f7 | 111 | } cache_data; |
823c0e9c RB |
112 | } git_attr_file; |
113 | ||
114 | struct git_attr_file_entry { | |
115 | git_attr_file *file[GIT_ATTR_FILE_NUM_SOURCES]; | |
116 | const char *path; /* points into fullpath */ | |
117 | char fullpath[GIT_FLEX_ARRAY]; | |
7d490872 | 118 | }; |
ee1f0b1a RB |
119 | |
120 | typedef struct { | |
e579e0f7 | 121 | git_str full; |
52032ae5 RB |
122 | char *path; |
123 | char *basename; | |
124 | int is_dir; | |
ee1f0b1a RB |
125 | } git_attr_path; |
126 | ||
9f779aac ET |
127 | /* A git_attr_session can provide an "instance" of reading, to prevent cache |
128 | * invalidation during a single operation instance (like checkout). | |
129 | */ | |
130 | ||
131 | typedef struct { | |
132 | int key; | |
d4b1b767 ET |
133 | unsigned int init_setup:1, |
134 | init_sysdir:1; | |
e579e0f7 MB |
135 | git_str sysdir; |
136 | git_str tmp; | |
9f779aac ET |
137 | } git_attr_session; |
138 | ||
139 | extern int git_attr_session__init(git_attr_session *attr_session, git_repository *repo); | |
140 | extern void git_attr_session__free(git_attr_session *session); | |
141 | ||
142 | extern int git_attr_get_many_with_session( | |
143 | const char **values_out, | |
144 | git_repository *repo, | |
145 | git_attr_session *attr_session, | |
c25aa7cd | 146 | git_attr_options *opts, |
9f779aac ET |
147 | const char *path, |
148 | size_t num_attr, | |
149 | const char **names); | |
150 | ||
151 | typedef int (*git_attr_file_parser)( | |
152 | git_repository *repo, | |
153 | git_attr_file *file, | |
22a2d3d5 UG |
154 | const char *data, |
155 | bool allow_macros); | |
9f779aac | 156 | |
ee1f0b1a RB |
157 | /* |
158 | * git_attr_file API | |
159 | */ | |
160 | ||
7d490872 RB |
161 | int git_attr_file__new( |
162 | git_attr_file **out, | |
823c0e9c | 163 | git_attr_file_entry *entry, |
c25aa7cd | 164 | git_attr_file_source *source); |
7d490872 RB |
165 | |
166 | void git_attr_file__free(git_attr_file *file); | |
167 | ||
168 | int git_attr_file__load( | |
169 | git_attr_file **out, | |
170 | git_repository *repo, | |
9f779aac | 171 | git_attr_session *attr_session, |
823c0e9c | 172 | git_attr_file_entry *ce, |
c25aa7cd | 173 | git_attr_file_source *source, |
22a2d3d5 UG |
174 | git_attr_file_parser parser, |
175 | bool allow_macros); | |
f917481e | 176 | |
7d490872 | 177 | int git_attr_file__load_standalone( |
823c0e9c | 178 | git_attr_file **out, const char *path); |
f917481e | 179 | |
7d490872 | 180 | int git_attr_file__out_of_date( |
c25aa7cd | 181 | git_repository *repo, git_attr_session *session, git_attr_file *file, git_attr_file_source *source); |
a51cd8e6 | 182 | |
7d490872 | 183 | int git_attr_file__parse_buffer( |
22a2d3d5 | 184 | git_repository *repo, git_attr_file *attrs, const char *data, bool allow_macros); |
2a99df69 | 185 | |
e6e8530a RB |
186 | int git_attr_file__clear_rules( |
187 | git_attr_file *file, bool need_lock); | |
ee1f0b1a | 188 | |
7d490872 | 189 | int git_attr_file__lookup_one( |
ee1f0b1a | 190 | git_attr_file *file, |
f554611a | 191 | git_attr_path *path, |
ee1f0b1a RB |
192 | const char *attr, |
193 | const char **value); | |
194 | ||
195 | /* loop over rules in file from bottom to top */ | |
196 | #define git_attr_file__foreach_matching_rule(file, path, iter, rule) \ | |
197 | git_vector_rforeach(&(file)->rules, (iter), (rule)) \ | |
ab43ad2f | 198 | if (git_attr_rule__match((rule), (path))) |
ee1f0b1a | 199 | |
7d490872 | 200 | uint32_t git_attr_file__name_hash(const char *name); |
ee1f0b1a RB |
201 | |
202 | ||
203 | /* | |
204 | * other utilities | |
205 | */ | |
206 | ||
4ba64794 | 207 | extern int git_attr_fnmatch__parse( |
df743c7d | 208 | git_attr_fnmatch *spec, |
19fa2bc1 | 209 | git_pool *pool, |
a51cd8e6 | 210 | const char *source, |
df743c7d RB |
211 | const char **base); |
212 | ||
ab43ad2f | 213 | extern bool git_attr_fnmatch__match( |
df743c7d | 214 | git_attr_fnmatch *rule, |
f554611a | 215 | git_attr_path *path); |
df743c7d | 216 | |
73b51450 RB |
217 | extern void git_attr_rule__free(git_attr_rule *rule); |
218 | ||
ab43ad2f | 219 | extern bool git_attr_rule__match( |
ee1f0b1a | 220 | git_attr_rule *rule, |
f554611a | 221 | git_attr_path *path); |
ee1f0b1a RB |
222 | |
223 | extern git_attr_assignment *git_attr_rule__lookup_assignment( | |
224 | git_attr_rule *rule, const char *name); | |
225 | ||
4c09e19a W |
226 | typedef enum { GIT_DIR_FLAG_TRUE = 1, GIT_DIR_FLAG_FALSE = 0, GIT_DIR_FLAG_UNKNOWN = -1 } git_dir_flag; |
227 | ||
ee1f0b1a | 228 | extern int git_attr_path__init( |
c25aa7cd PP |
229 | git_attr_path *out, |
230 | const char *path, | |
231 | const char *base, | |
232 | git_dir_flag is_dir); | |
d58336dd RB |
233 | extern void git_attr_path__free(git_attr_path *info); |
234 | ||
73b51450 RB |
235 | extern int git_attr_assignment__parse( |
236 | git_repository *repo, /* needed to expand macros */ | |
19fa2bc1 | 237 | git_pool *pool, |
73b51450 RB |
238 | git_vector *assigns, |
239 | const char **scan); | |
240 | ||
ee1f0b1a | 241 | #endif |