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__
11 #include "git2/attr.h"
17 #define GIT_ATTR_FILE ".gitattributes"
18 #define GIT_ATTR_FILE_INREPO "info/attributes"
19 #define GIT_ATTR_FILE_SYSTEM "gitattributes"
20 #define GIT_ATTR_FILE_XDG "attributes"
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)
26 #define GIT_ATTR_FNMATCH_IGNORE (1U << 4)
27 #define GIT_ATTR_FNMATCH_HASWILD (1U << 5)
28 #define GIT_ATTR_FNMATCH_ALLOWSPACE (1U << 6)
29 #define GIT_ATTR_FNMATCH_ICASE (1U << 7)
30 #define GIT_ATTR_FNMATCH_MATCH_ALL (1U << 8)
31 #define GIT_ATTR_FNMATCH_ALLOWNEG (1U << 9)
32 #define GIT_ATTR_FNMATCH_ALLOWMACRO (1U << 10)
33 #define GIT_ATTR_FNMATCH_LEADINGDIR (1U << 11)
34 #define GIT_ATTR_FNMATCH_NOLEADINGDIR (1U << 12)
36 #define GIT_ATTR_FNMATCH__INCOMING \
37 (GIT_ATTR_FNMATCH_ALLOWSPACE | GIT_ATTR_FNMATCH_ALLOWNEG | \
38 GIT_ATTR_FNMATCH_ALLOWMACRO | GIT_ATTR_FNMATCH_NOLEADINGDIR)
41 GIT_ATTR_FILE__IN_MEMORY
= 0,
42 GIT_ATTR_FILE__FROM_FILE
= 1,
43 GIT_ATTR_FILE__FROM_INDEX
= 2,
45 GIT_ATTR_FILE_NUM_SOURCES
= 3
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
;
59 git_attr_fnmatch match
;
60 git_vector assigns
; /* vector of <git_attr_assignment*> */
70 git_refcount rc
; /* for macros */
74 } git_attr_assignment
;
76 typedef struct git_attr_file_entry git_attr_file_entry
;
81 git_attr_file_entry
*entry
;
82 git_attr_file_source source
;
83 git_vector rules
; /* vector of <rule*> or <fnmatch*> */
87 git_futils_filestamp stamp
;
91 struct git_attr_file_entry
{
92 git_attr_file
*file
[GIT_ATTR_FILE_NUM_SOURCES
];
93 const char *path
; /* points into fullpath */
94 char fullpath
[GIT_FLEX_ARRAY
];
97 typedef int (*git_attr_file_parser
)(
113 int git_attr_file__new(
115 git_attr_file_entry
*entry
,
116 git_attr_file_source source
);
118 void git_attr_file__free(git_attr_file
*file
);
120 int git_attr_file__load(
122 git_repository
*repo
,
123 git_attr_file_entry
*ce
,
124 git_attr_file_source source
,
125 git_attr_file_parser parser
);
127 int git_attr_file__load_standalone(
128 git_attr_file
**out
, const char *path
);
130 int git_attr_file__out_of_date(
131 git_repository
*repo
, git_attr_file
*file
);
133 int git_attr_file__parse_buffer(
134 git_repository
*repo
, git_attr_file
*attrs
, const char *data
);
136 int git_attr_file__clear_rules(
137 git_attr_file
*file
, bool need_lock
);
139 int git_attr_file__lookup_one(
145 /* loop over rules in file from bottom to top */
146 #define git_attr_file__foreach_matching_rule(file, path, iter, rule) \
147 git_vector_rforeach(&(file)->rules, (iter), (rule)) \
148 if (git_attr_rule__match((rule), (path)))
150 uint32_t git_attr_file__name_hash(const char *name
);
157 extern int git_attr_fnmatch__parse(
158 git_attr_fnmatch
*spec
,
163 extern bool git_attr_fnmatch__match(
164 git_attr_fnmatch
*rule
,
165 git_attr_path
*path
);
167 extern void git_attr_rule__free(git_attr_rule
*rule
);
169 extern bool git_attr_rule__match(
171 git_attr_path
*path
);
173 extern git_attr_assignment
*git_attr_rule__lookup_assignment(
174 git_attr_rule
*rule
, const char *name
);
176 extern int git_attr_path__init(
177 git_attr_path
*info
, const char *path
, const char *base
);
179 extern void git_attr_path__free(git_attr_path
*info
);
181 extern int git_attr_assignment__parse(
182 git_repository
*repo
, /* needed to expand macros */