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