]>
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 | ||
55cbd05b | 10 | #include "git2/oid.h" |
ee1f0b1a RB |
11 | #include "git2/attr.h" |
12 | #include "vector.h" | |
19fa2bc1 | 13 | #include "pool.h" |
d58336dd | 14 | #include "buffer.h" |
744cc03e | 15 | #include "fileops.h" |
73b51450 | 16 | |
cfbc880d RB |
17 | #define GIT_ATTR_FILE ".gitattributes" |
18 | #define GIT_ATTR_FILE_INREPO "info/attributes" | |
19 | #define GIT_ATTR_FILE_SYSTEM "gitattributes" | |
5540d947 | 20 | #define GIT_ATTR_FILE_XDG "attributes" |
cfbc880d | 21 | |
73b51450 RB |
22 | #define GIT_ATTR_FNMATCH_NEGATIVE (1U << 0) |
23 | #define GIT_ATTR_FNMATCH_DIRECTORY (1U << 1) | |
24 | #define GIT_ATTR_FNMATCH_FULLPATH (1U << 2) | |
25 | #define GIT_ATTR_FNMATCH_MACRO (1U << 3) | |
df743c7d | 26 | #define GIT_ATTR_FNMATCH_IGNORE (1U << 4) |
14a513e0 | 27 | #define GIT_ATTR_FNMATCH_HASWILD (1U << 5) |
2a99df69 | 28 | #define GIT_ATTR_FNMATCH_ALLOWSPACE (1U << 6) |
ec40b7f9 | 29 | #define GIT_ATTR_FNMATCH_ICASE (1U << 7) |
0d32f39e | 30 | #define GIT_ATTR_FNMATCH_MATCH_ALL (1U << 8) |
4ba64794 RB |
31 | #define GIT_ATTR_FNMATCH_ALLOWNEG (1U << 9) |
32 | #define GIT_ATTR_FNMATCH_ALLOWMACRO (1U << 10) | |
916fcbd6 | 33 | #define GIT_ATTR_FNMATCH_LEADINGDIR (1U << 11) |
ac16bd0a | 34 | #define GIT_ATTR_FNMATCH_NOLEADINGDIR (1U << 12) |
4ba64794 RB |
35 | |
36 | #define GIT_ATTR_FNMATCH__INCOMING \ | |
ac16bd0a RB |
37 | (GIT_ATTR_FNMATCH_ALLOWSPACE | GIT_ATTR_FNMATCH_ALLOWNEG | \ |
38 | GIT_ATTR_FNMATCH_ALLOWMACRO | GIT_ATTR_FNMATCH_NOLEADINGDIR) | |
ee1f0b1a | 39 | |
823c0e9c RB |
40 | typedef enum { |
41 | GIT_ATTR_FILE__IN_MEMORY = 0, | |
42 | GIT_ATTR_FILE__FROM_FILE = 1, | |
43 | GIT_ATTR_FILE__FROM_INDEX = 2, | |
44 | ||
45 | GIT_ATTR_FILE_NUM_SOURCES = 3 | |
46 | } git_attr_file_source; | |
47 | ||
0c9eacf3 VM |
48 | extern const char *git_attr__true; |
49 | extern const char *git_attr__false; | |
50 | extern const char *git_attr__unset; | |
51 | ||
ee1f0b1a RB |
52 | typedef struct { |
53 | char *pattern; | |
54 | size_t length; | |
6069042f CMN |
55 | char *containing_dir; |
56 | size_t containing_dir_length; | |
73b51450 | 57 | unsigned int flags; |
ee1f0b1a RB |
58 | } git_attr_fnmatch; |
59 | ||
823c0e9c | 60 | typedef struct { |
df743c7d RB |
61 | git_attr_fnmatch match; |
62 | git_vector assigns; /* vector of <git_attr_assignment*> */ | |
823c0e9c | 63 | } git_attr_rule; |
df743c7d | 64 | |
ee1f0b1a | 65 | typedef struct { |
73b51450 | 66 | git_refcount unused; |
ee1f0b1a | 67 | const char *name; |
0cb16fe9 | 68 | uint32_t name_hash; |
ee1f0b1a RB |
69 | } git_attr_name; |
70 | ||
71 | typedef struct { | |
df743c7d | 72 | git_refcount rc; /* for macros */ |
ee1f0b1a | 73 | char *name; |
0cb16fe9 L |
74 | uint32_t name_hash; |
75 | const char *value; | |
ee1f0b1a RB |
76 | } git_attr_assignment; |
77 | ||
823c0e9c RB |
78 | typedef struct git_attr_file_entry git_attr_file_entry; |
79 | ||
80 | typedef struct { | |
40ed4990 | 81 | git_refcount rc; |
e6e8530a | 82 | git_mutex lock; |
823c0e9c RB |
83 | git_attr_file_entry *entry; |
84 | git_attr_file_source source; | |
7d490872 RB |
85 | git_vector rules; /* vector of <rule*> or <fnmatch*> */ |
86 | git_pool pool; | |
dc13f1f7 RB |
87 | union { |
88 | git_oid oid; | |
c1f61af6 | 89 | git_futils_filestamp stamp; |
dc13f1f7 | 90 | } cache_data; |
823c0e9c RB |
91 | } git_attr_file; |
92 | ||
93 | struct git_attr_file_entry { | |
94 | git_attr_file *file[GIT_ATTR_FILE_NUM_SOURCES]; | |
95 | const char *path; /* points into fullpath */ | |
96 | char fullpath[GIT_FLEX_ARRAY]; | |
7d490872 | 97 | }; |
ee1f0b1a | 98 | |
823c0e9c RB |
99 | typedef int (*git_attr_file_parser)( |
100 | git_repository *repo, | |
101 | git_attr_file *file, | |
102 | const char *data); | |
103 | ||
ee1f0b1a | 104 | typedef struct { |
52032ae5 RB |
105 | git_buf full; |
106 | char *path; | |
107 | char *basename; | |
108 | int is_dir; | |
ee1f0b1a RB |
109 | } git_attr_path; |
110 | ||
111 | /* | |
112 | * git_attr_file API | |
113 | */ | |
114 | ||
7d490872 RB |
115 | int git_attr_file__new( |
116 | git_attr_file **out, | |
823c0e9c RB |
117 | git_attr_file_entry *entry, |
118 | git_attr_file_source source); | |
7d490872 RB |
119 | |
120 | void git_attr_file__free(git_attr_file *file); | |
121 | ||
122 | int git_attr_file__load( | |
123 | git_attr_file **out, | |
124 | git_repository *repo, | |
823c0e9c RB |
125 | git_attr_file_entry *ce, |
126 | git_attr_file_source source, | |
127 | git_attr_file_parser parser); | |
f917481e | 128 | |
7d490872 | 129 | int git_attr_file__load_standalone( |
823c0e9c | 130 | git_attr_file **out, const char *path); |
f917481e | 131 | |
7d490872 RB |
132 | int git_attr_file__out_of_date( |
133 | git_repository *repo, git_attr_file *file); | |
a51cd8e6 | 134 | |
7d490872 | 135 | int git_attr_file__parse_buffer( |
823c0e9c | 136 | git_repository *repo, git_attr_file *attrs, const char *data); |
2a99df69 | 137 | |
e6e8530a RB |
138 | int git_attr_file__clear_rules( |
139 | git_attr_file *file, bool need_lock); | |
ee1f0b1a | 140 | |
7d490872 | 141 | int git_attr_file__lookup_one( |
ee1f0b1a | 142 | git_attr_file *file, |
f554611a | 143 | git_attr_path *path, |
ee1f0b1a RB |
144 | const char *attr, |
145 | const char **value); | |
146 | ||
147 | /* loop over rules in file from bottom to top */ | |
148 | #define git_attr_file__foreach_matching_rule(file, path, iter, rule) \ | |
149 | git_vector_rforeach(&(file)->rules, (iter), (rule)) \ | |
ab43ad2f | 150 | if (git_attr_rule__match((rule), (path))) |
ee1f0b1a | 151 | |
7d490872 | 152 | uint32_t git_attr_file__name_hash(const char *name); |
ee1f0b1a RB |
153 | |
154 | ||
155 | /* | |
156 | * other utilities | |
157 | */ | |
158 | ||
4ba64794 | 159 | extern int git_attr_fnmatch__parse( |
df743c7d | 160 | git_attr_fnmatch *spec, |
19fa2bc1 | 161 | git_pool *pool, |
a51cd8e6 | 162 | const char *source, |
df743c7d RB |
163 | const char **base); |
164 | ||
ab43ad2f | 165 | extern bool git_attr_fnmatch__match( |
df743c7d | 166 | git_attr_fnmatch *rule, |
f554611a | 167 | git_attr_path *path); |
df743c7d | 168 | |
73b51450 RB |
169 | extern void git_attr_rule__free(git_attr_rule *rule); |
170 | ||
ab43ad2f | 171 | extern bool git_attr_rule__match( |
ee1f0b1a | 172 | git_attr_rule *rule, |
f554611a | 173 | git_attr_path *path); |
ee1f0b1a RB |
174 | |
175 | extern git_attr_assignment *git_attr_rule__lookup_assignment( | |
176 | git_attr_rule *rule, const char *name); | |
177 | ||
178 | extern int git_attr_path__init( | |
adc9bdb3 | 179 | git_attr_path *info, const char *path, const char *base); |
ee1f0b1a | 180 | |
d58336dd RB |
181 | extern void git_attr_path__free(git_attr_path *info); |
182 | ||
73b51450 RB |
183 | extern int git_attr_assignment__parse( |
184 | git_repository *repo, /* needed to expand macros */ | |
19fa2bc1 | 185 | git_pool *pool, |
73b51450 RB |
186 | git_vector *assigns, |
187 | const char **scan); | |
188 | ||
ee1f0b1a | 189 | #endif |