2 * Copyright (C) 2009-2012 the libgit2 contributors
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"
21 #define GIT_ATTR_FNMATCH_NEGATIVE (1U << 0)
22 #define GIT_ATTR_FNMATCH_DIRECTORY (1U << 1)
23 #define GIT_ATTR_FNMATCH_FULLPATH (1U << 2)
24 #define GIT_ATTR_FNMATCH_MACRO (1U << 3)
25 #define GIT_ATTR_FNMATCH_IGNORE (1U << 4)
26 #define GIT_ATTR_FNMATCH_HASWILD (1U << 5)
27 #define GIT_ATTR_FNMATCH_ALLOWSPACE (1U << 6)
28 #define GIT_ATTR_FNMATCH_ICASE (1U << 7)
30 extern const char *git_attr__true
;
31 extern const char *git_attr__false
;
32 extern const char *git_attr__unset
;
41 git_attr_fnmatch match
;
42 git_vector assigns
; /* vector of <git_attr_assignment*> */
52 git_refcount rc
; /* for macros */
56 } git_attr_assignment
;
59 char *key
; /* cache "source#path" this was loaded from */
60 git_vector rules
; /* vector of <rule*> or <fnmatch*> */
62 bool pool_is_allocated
;
65 git_futils_filestamp stamp
;
77 GIT_ATTR_FILE_FROM_FILE
= 0,
78 GIT_ATTR_FILE_FROM_INDEX
= 1
79 } git_attr_file_source
;
85 extern int git_attr_file__new(
86 git_attr_file
**attrs_ptr
, git_attr_file_source src
, const char *path
, git_pool
*pool
);
88 extern int git_attr_file__new_and_load(
89 git_attr_file
**attrs_ptr
, const char *path
);
91 extern void git_attr_file__free(git_attr_file
*file
);
93 extern void git_attr_file__clear_rules(git_attr_file
*file
);
95 extern int git_attr_file__parse_buffer(
96 git_repository
*repo
, void *parsedata
, const char *buf
, git_attr_file
*file
);
98 extern int git_attr_file__lookup_one(
100 const git_attr_path
*path
,
104 /* loop over rules in file from bottom to top */
105 #define git_attr_file__foreach_matching_rule(file, path, iter, rule) \
106 git_vector_rforeach(&(file)->rules, (iter), (rule)) \
107 if (git_attr_rule__match((rule), (path)))
109 extern uint32_t git_attr_file__name_hash(const char *name
);
116 extern int git_attr_fnmatch__parse(
117 git_attr_fnmatch
*spec
,
122 extern bool git_attr_fnmatch__match(
123 git_attr_fnmatch
*rule
,
124 const git_attr_path
*path
);
126 extern void git_attr_rule__free(git_attr_rule
*rule
);
128 extern bool git_attr_rule__match(
130 const git_attr_path
*path
);
132 extern git_attr_assignment
*git_attr_rule__lookup_assignment(
133 git_attr_rule
*rule
, const char *name
);
135 extern int git_attr_path__init(
136 git_attr_path
*info
, const char *path
, const char *base
);
138 extern void git_attr_path__free(git_attr_path
*info
);
140 extern int git_attr_assignment__parse(
141 git_repository
*repo
, /* needed to expand macros */