2 * Copyright (C) the libgit2 contributors. All rights reserved.
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.
7 #ifndef INCLUDE_attr_file_h__
8 #define INCLUDE_attr_file_h__
13 #include "git2/attr.h"
19 #define GIT_ATTR_FILE ".gitattributes"
20 #define GIT_ATTR_FILE_INREPO "attributes"
21 #define GIT_ATTR_FILE_SYSTEM "gitattributes"
22 #define GIT_ATTR_FILE_XDG "attributes"
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)
28 #define GIT_ATTR_FNMATCH_IGNORE (1U << 4)
29 #define GIT_ATTR_FNMATCH_HASWILD (1U << 5)
30 #define GIT_ATTR_FNMATCH_ALLOWSPACE (1U << 6)
31 #define GIT_ATTR_FNMATCH_ICASE (1U << 7)
32 #define GIT_ATTR_FNMATCH_MATCH_ALL (1U << 8)
33 #define GIT_ATTR_FNMATCH_ALLOWNEG (1U << 9)
34 #define GIT_ATTR_FNMATCH_ALLOWMACRO (1U << 10)
36 #define GIT_ATTR_FNMATCH__INCOMING \
37 (GIT_ATTR_FNMATCH_ALLOWSPACE | GIT_ATTR_FNMATCH_ALLOWNEG | GIT_ATTR_FNMATCH_ALLOWMACRO)
40 GIT_ATTR_FILE__IN_MEMORY
= 0,
41 GIT_ATTR_FILE__FROM_FILE
= 1,
42 GIT_ATTR_FILE__FROM_INDEX
= 2,
43 GIT_ATTR_FILE__FROM_HEAD
= 3,
45 GIT_ATTR_FILE_NUM_SOURCES
= 4
46 } git_attr_file_source
;
48 extern const char *git_attr__true
;
49 extern const char *git_attr__false
;
50 extern const char *git_attr__unset
;
56 size_t containing_dir_length
;
61 git_attr_fnmatch match
;
62 git_vector assigns
; /* vector of <git_attr_assignment*> */
72 git_refcount rc
; /* for macros */
76 } git_attr_assignment
;
78 typedef struct git_attr_file_entry git_attr_file_entry
;
83 git_attr_file_entry
*entry
;
84 git_attr_file_source source
;
85 git_vector rules
; /* vector of <rule*> or <fnmatch*> */
87 unsigned int nonexistent
:1;
91 git_futils_filestamp stamp
;
95 struct git_attr_file_entry
{
96 git_attr_file
*file
[GIT_ATTR_FILE_NUM_SOURCES
];
97 const char *path
; /* points into fullpath */
98 char fullpath
[GIT_FLEX_ARRAY
];
108 /* A git_attr_session can provide an "instance" of reading, to prevent cache
109 * invalidation during a single operation instance (like checkout).
114 unsigned int init_setup
:1,
120 extern int git_attr_session__init(git_attr_session
*attr_session
, git_repository
*repo
);
121 extern void git_attr_session__free(git_attr_session
*session
);
123 extern int git_attr_get_many_with_session(
124 const char **values_out
,
125 git_repository
*repo
,
126 git_attr_session
*attr_session
,
132 typedef int (*git_attr_file_parser
)(
133 git_repository
*repo
,
142 int git_attr_file__new(
144 git_attr_file_entry
*entry
,
145 git_attr_file_source source
);
147 void git_attr_file__free(git_attr_file
*file
);
149 int git_attr_file__load(
151 git_repository
*repo
,
152 git_attr_session
*attr_session
,
153 git_attr_file_entry
*ce
,
154 git_attr_file_source source
,
155 git_attr_file_parser parser
,
158 int git_attr_file__load_standalone(
159 git_attr_file
**out
, const char *path
);
161 int git_attr_file__out_of_date(
162 git_repository
*repo
, git_attr_session
*session
, git_attr_file
*file
);
164 int git_attr_file__parse_buffer(
165 git_repository
*repo
, git_attr_file
*attrs
, const char *data
, bool allow_macros
);
167 int git_attr_file__clear_rules(
168 git_attr_file
*file
, bool need_lock
);
170 int git_attr_file__lookup_one(
176 /* loop over rules in file from bottom to top */
177 #define git_attr_file__foreach_matching_rule(file, path, iter, rule) \
178 git_vector_rforeach(&(file)->rules, (iter), (rule)) \
179 if (git_attr_rule__match((rule), (path)))
181 uint32_t git_attr_file__name_hash(const char *name
);
188 extern int git_attr_fnmatch__parse(
189 git_attr_fnmatch
*spec
,
194 extern bool git_attr_fnmatch__match(
195 git_attr_fnmatch
*rule
,
196 git_attr_path
*path
);
198 extern void git_attr_rule__free(git_attr_rule
*rule
);
200 extern bool git_attr_rule__match(
202 git_attr_path
*path
);
204 extern git_attr_assignment
*git_attr_rule__lookup_assignment(
205 git_attr_rule
*rule
, const char *name
);
207 typedef enum { GIT_DIR_FLAG_TRUE
= 1, GIT_DIR_FLAG_FALSE
= 0, GIT_DIR_FLAG_UNKNOWN
= -1 } git_dir_flag
;
209 extern int git_attr_path__init(
210 git_attr_path
*info
, const char *path
, const char *base
, git_dir_flag is_dir
);
212 extern void git_attr_path__free(git_attr_path
*info
);
214 extern int git_attr_assignment__parse(
215 git_repository
*repo
, /* needed to expand macros */