]> git.proxmox.com Git - libgit2.git/blame - src/attr_file.h
Add dependency on ca-certificates and libpcre3-dev
[libgit2.git] / src / attr_file.h
CommitLineData
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"
d58336dd 16#include "buffer.h"
0c9c969a 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 \
0c9c969a 37 (GIT_ATTR_FNMATCH_ALLOWSPACE | GIT_ATTR_FNMATCH_ALLOWNEG | GIT_ATTR_FNMATCH_ALLOWMACRO)
ee1f0b1a 38
823c0e9c 39typedef enum {
9f779aac
ET
40 GIT_ATTR_FILE__IN_MEMORY = 0,
41 GIT_ATTR_FILE__FROM_FILE = 1,
42 GIT_ATTR_FILE__FROM_INDEX = 2,
0c9c969a 43 GIT_ATTR_FILE__FROM_HEAD = 3,
823c0e9c 44
0c9c969a 45 GIT_ATTR_FILE_NUM_SOURCES = 4
823c0e9c
RB
46} git_attr_file_source;
47
0c9eacf3
VM
48extern const char *git_attr__true;
49extern const char *git_attr__false;
50extern const char *git_attr__unset;
51
ee1f0b1a
RB
52typedef 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 60typedef 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 65typedef struct {
73b51450 66 git_refcount unused;
ee1f0b1a 67 const char *name;
0cb16fe9 68 uint32_t name_hash;
ee1f0b1a
RB
69} git_attr_name;
70
71typedef 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
78typedef struct git_attr_file_entry git_attr_file_entry;
79
80typedef 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;
9f779aac
ET
87 unsigned int nonexistent:1;
88 int session_key;
dc13f1f7
RB
89 union {
90 git_oid oid;
c1f61af6 91 git_futils_filestamp stamp;
dc13f1f7 92 } cache_data;
823c0e9c
RB
93} git_attr_file;
94
95struct 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];
7d490872 99};
ee1f0b1a
RB
100
101typedef struct {
52032ae5
RB
102 git_buf full;
103 char *path;
104 char *basename;
105 int is_dir;
ee1f0b1a
RB
106} git_attr_path;
107
9f779aac
ET
108/* A git_attr_session can provide an "instance" of reading, to prevent cache
109 * invalidation during a single operation instance (like checkout).
110 */
111
112typedef struct {
113 int key;
d4b1b767
ET
114 unsigned int init_setup:1,
115 init_sysdir:1;
116 git_buf sysdir;
f58cc280 117 git_buf tmp;
9f779aac
ET
118} git_attr_session;
119
120extern int git_attr_session__init(git_attr_session *attr_session, git_repository *repo);
121extern void git_attr_session__free(git_attr_session *session);
122
123extern int git_attr_get_many_with_session(
124 const char **values_out,
125 git_repository *repo,
126 git_attr_session *attr_session,
127 uint32_t flags,
128 const char *path,
129 size_t num_attr,
130 const char **names);
131
132typedef int (*git_attr_file_parser)(
133 git_repository *repo,
134 git_attr_file *file,
0c9c969a
UG
135 const char *data,
136 bool allow_macros);
9f779aac 137
ee1f0b1a
RB
138/*
139 * git_attr_file API
140 */
141
7d490872
RB
142int git_attr_file__new(
143 git_attr_file **out,
823c0e9c
RB
144 git_attr_file_entry *entry,
145 git_attr_file_source source);
7d490872
RB
146
147void git_attr_file__free(git_attr_file *file);
148
149int git_attr_file__load(
150 git_attr_file **out,
151 git_repository *repo,
9f779aac 152 git_attr_session *attr_session,
823c0e9c
RB
153 git_attr_file_entry *ce,
154 git_attr_file_source source,
0c9c969a
UG
155 git_attr_file_parser parser,
156 bool allow_macros);
f917481e 157
7d490872 158int git_attr_file__load_standalone(
823c0e9c 159 git_attr_file **out, const char *path);
f917481e 160
7d490872 161int git_attr_file__out_of_date(
9f779aac 162 git_repository *repo, git_attr_session *session, git_attr_file *file);
a51cd8e6 163
7d490872 164int git_attr_file__parse_buffer(
0c9c969a 165 git_repository *repo, git_attr_file *attrs, const char *data, bool allow_macros);
2a99df69 166
e6e8530a
RB
167int git_attr_file__clear_rules(
168 git_attr_file *file, bool need_lock);
ee1f0b1a 169
7d490872 170int git_attr_file__lookup_one(
ee1f0b1a 171 git_attr_file *file,
f554611a 172 git_attr_path *path,
ee1f0b1a
RB
173 const char *attr,
174 const char **value);
175
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)) \
ab43ad2f 179 if (git_attr_rule__match((rule), (path)))
ee1f0b1a 180
7d490872 181uint32_t git_attr_file__name_hash(const char *name);
ee1f0b1a
RB
182
183
184/*
185 * other utilities
186 */
187
4ba64794 188extern int git_attr_fnmatch__parse(
df743c7d 189 git_attr_fnmatch *spec,
19fa2bc1 190 git_pool *pool,
a51cd8e6 191 const char *source,
df743c7d
RB
192 const char **base);
193
ab43ad2f 194extern bool git_attr_fnmatch__match(
df743c7d 195 git_attr_fnmatch *rule,
f554611a 196 git_attr_path *path);
df743c7d 197
73b51450
RB
198extern void git_attr_rule__free(git_attr_rule *rule);
199
ab43ad2f 200extern bool git_attr_rule__match(
ee1f0b1a 201 git_attr_rule *rule,
f554611a 202 git_attr_path *path);
ee1f0b1a
RB
203
204extern git_attr_assignment *git_attr_rule__lookup_assignment(
205 git_attr_rule *rule, const char *name);
206
4c09e19a
W
207typedef enum { GIT_DIR_FLAG_TRUE = 1, GIT_DIR_FLAG_FALSE = 0, GIT_DIR_FLAG_UNKNOWN = -1 } git_dir_flag;
208
ee1f0b1a 209extern int git_attr_path__init(
4c09e19a 210 git_attr_path *info, const char *path, const char *base, git_dir_flag is_dir);
ee1f0b1a 211
d58336dd
RB
212extern void git_attr_path__free(git_attr_path *info);
213
73b51450
RB
214extern int git_attr_assignment__parse(
215 git_repository *repo, /* needed to expand macros */
19fa2bc1 216 git_pool *pool,
73b51450
RB
217 git_vector *assigns,
218 const char **scan);
219
ee1f0b1a 220#endif