]> git.proxmox.com Git - libgit2.git/blame - src/attr_file.h
Doc fixes
[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"
73b51450 16
cfbc880d
RB
17#define GIT_ATTR_FILE ".gitattributes"
18#define GIT_ATTR_FILE_INREPO "info/attributes"
19#define GIT_ATTR_FILE_SYSTEM "gitattributes"
5540d947 20#define GIT_ATTR_FILE_XDG "attributes"
cfbc880d 21
73b51450
RB
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)
df743c7d 26#define GIT_ATTR_FNMATCH_IGNORE (1U << 4)
14a513e0 27#define GIT_ATTR_FNMATCH_HASWILD (1U << 5)
2a99df69 28#define GIT_ATTR_FNMATCH_ALLOWSPACE (1U << 6)
ec40b7f9 29#define GIT_ATTR_FNMATCH_ICASE (1U << 7)
0d32f39e 30#define GIT_ATTR_FNMATCH_MATCH_ALL (1U << 8)
4ba64794
RB
31#define GIT_ATTR_FNMATCH_ALLOWNEG (1U << 9)
32#define GIT_ATTR_FNMATCH_ALLOWMACRO (1U << 10)
916fcbd6 33#define GIT_ATTR_FNMATCH_LEADINGDIR (1U << 11)
ac16bd0a 34#define GIT_ATTR_FNMATCH_NOLEADINGDIR (1U << 12)
4ba64794
RB
35
36#define GIT_ATTR_FNMATCH__INCOMING \
ac16bd0a
RB
37 (GIT_ATTR_FNMATCH_ALLOWSPACE | GIT_ATTR_FNMATCH_ALLOWNEG | \
38 GIT_ATTR_FNMATCH_ALLOWMACRO | GIT_ATTR_FNMATCH_NOLEADINGDIR)
ee1f0b1a 39
823c0e9c
RB
40typedef enum {
41 GIT_ATTR_FILE__IN_MEMORY = 0,
42 GIT_ATTR_FILE__FROM_FILE = 1,
43 GIT_ATTR_FILE__FROM_INDEX = 2,
44
45 GIT_ATTR_FILE_NUM_SOURCES = 3
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;
73b51450 55 unsigned int flags;
ee1f0b1a
RB
56} git_attr_fnmatch;
57
823c0e9c 58typedef struct {
df743c7d
RB
59 git_attr_fnmatch match;
60 git_vector assigns; /* vector of <git_attr_assignment*> */
823c0e9c 61} git_attr_rule;
df743c7d 62
ee1f0b1a 63typedef struct {
73b51450 64 git_refcount unused;
ee1f0b1a 65 const char *name;
0cb16fe9 66 uint32_t name_hash;
ee1f0b1a
RB
67} git_attr_name;
68
69typedef struct {
df743c7d 70 git_refcount rc; /* for macros */
ee1f0b1a 71 char *name;
0cb16fe9
L
72 uint32_t name_hash;
73 const char *value;
ee1f0b1a
RB
74} git_attr_assignment;
75
823c0e9c
RB
76typedef struct git_attr_file_entry git_attr_file_entry;
77
78typedef struct {
40ed4990 79 git_refcount rc;
e6e8530a 80 git_mutex lock;
823c0e9c
RB
81 git_attr_file_entry *entry;
82 git_attr_file_source source;
7d490872
RB
83 git_vector rules; /* vector of <rule*> or <fnmatch*> */
84 git_pool pool;
dc13f1f7
RB
85 union {
86 git_oid oid;
c1f61af6 87 git_futils_filestamp stamp;
dc13f1f7 88 } cache_data;
823c0e9c
RB
89} git_attr_file;
90
91struct 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];
7d490872 95};
ee1f0b1a 96
823c0e9c
RB
97typedef int (*git_attr_file_parser)(
98 git_repository *repo,
99 git_attr_file *file,
100 const char *data);
101
ee1f0b1a 102typedef struct {
52032ae5
RB
103 git_buf full;
104 char *path;
105 char *basename;
106 int is_dir;
ee1f0b1a
RB
107} git_attr_path;
108
109/*
110 * git_attr_file API
111 */
112
7d490872
RB
113int git_attr_file__new(
114 git_attr_file **out,
823c0e9c
RB
115 git_attr_file_entry *entry,
116 git_attr_file_source source);
7d490872
RB
117
118void git_attr_file__free(git_attr_file *file);
119
120int git_attr_file__load(
121 git_attr_file **out,
122 git_repository *repo,
823c0e9c
RB
123 git_attr_file_entry *ce,
124 git_attr_file_source source,
125 git_attr_file_parser parser);
f917481e 126
7d490872 127int git_attr_file__load_standalone(
823c0e9c 128 git_attr_file **out, const char *path);
f917481e 129
7d490872
RB
130int git_attr_file__out_of_date(
131 git_repository *repo, git_attr_file *file);
a51cd8e6 132
7d490872 133int git_attr_file__parse_buffer(
823c0e9c 134 git_repository *repo, git_attr_file *attrs, const char *data);
2a99df69 135
e6e8530a
RB
136int git_attr_file__clear_rules(
137 git_attr_file *file, bool need_lock);
ee1f0b1a 138
7d490872 139int git_attr_file__lookup_one(
ee1f0b1a
RB
140 git_attr_file *file,
141 const git_attr_path *path,
142 const char *attr,
143 const char **value);
144
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)) \
ab43ad2f 148 if (git_attr_rule__match((rule), (path)))
ee1f0b1a 149
7d490872 150uint32_t git_attr_file__name_hash(const char *name);
ee1f0b1a
RB
151
152
153/*
154 * other utilities
155 */
156
4ba64794 157extern int git_attr_fnmatch__parse(
df743c7d 158 git_attr_fnmatch *spec,
19fa2bc1 159 git_pool *pool,
a51cd8e6 160 const char *source,
df743c7d
RB
161 const char **base);
162
ab43ad2f 163extern bool git_attr_fnmatch__match(
df743c7d
RB
164 git_attr_fnmatch *rule,
165 const git_attr_path *path);
166
73b51450
RB
167extern void git_attr_rule__free(git_attr_rule *rule);
168
ab43ad2f 169extern bool git_attr_rule__match(
ee1f0b1a
RB
170 git_attr_rule *rule,
171 const git_attr_path *path);
172
173extern git_attr_assignment *git_attr_rule__lookup_assignment(
174 git_attr_rule *rule, const char *name);
175
176extern int git_attr_path__init(
adc9bdb3 177 git_attr_path *info, const char *path, const char *base);
ee1f0b1a 178
d58336dd
RB
179extern void git_attr_path__free(git_attr_path *info);
180
73b51450
RB
181extern int git_attr_assignment__parse(
182 git_repository *repo, /* needed to expand macros */
19fa2bc1 183 git_pool *pool,
73b51450
RB
184 git_vector *assigns,
185 const char **scan);
186
ee1f0b1a 187#endif