]> git.proxmox.com Git - libgit2.git/blame - src/attr_file.h
Minor tree cache speedups
[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)
33
34#define GIT_ATTR_FNMATCH__INCOMING \
35 (GIT_ATTR_FNMATCH_ALLOWSPACE | \
36 GIT_ATTR_FNMATCH_ALLOWNEG | GIT_ATTR_FNMATCH_ALLOWMACRO)
ee1f0b1a 37
0c9eacf3
VM
38extern const char *git_attr__true;
39extern const char *git_attr__false;
40extern const char *git_attr__unset;
41
ee1f0b1a
RB
42typedef struct {
43 char *pattern;
44 size_t length;
73b51450 45 unsigned int flags;
ee1f0b1a
RB
46} git_attr_fnmatch;
47
df743c7d
RB
48typedef struct {
49 git_attr_fnmatch match;
50 git_vector assigns; /* vector of <git_attr_assignment*> */
51} git_attr_rule;
52
ee1f0b1a 53typedef struct {
73b51450 54 git_refcount unused;
ee1f0b1a 55 const char *name;
0cb16fe9 56 uint32_t name_hash;
ee1f0b1a
RB
57} git_attr_name;
58
59typedef struct {
df743c7d 60 git_refcount rc; /* for macros */
ee1f0b1a 61 char *name;
0cb16fe9
L
62 uint32_t name_hash;
63 const char *value;
ee1f0b1a
RB
64} git_attr_assignment;
65
66typedef struct {
40ed4990 67 git_refcount rc;
f917481e 68 char *key; /* cache "source#path" this was loaded from */
df743c7d 69 git_vector rules; /* vector of <rule*> or <fnmatch*> */
19fa2bc1
RB
70 git_pool *pool;
71 bool pool_is_allocated;
dc13f1f7
RB
72 union {
73 git_oid oid;
c1f61af6 74 git_futils_filestamp stamp;
dc13f1f7 75 } cache_data;
ee1f0b1a
RB
76} git_attr_file;
77
78typedef struct {
52032ae5
RB
79 git_buf full;
80 char *path;
81 char *basename;
82 int is_dir;
ee1f0b1a
RB
83} git_attr_path;
84
f917481e
RB
85typedef enum {
86 GIT_ATTR_FILE_FROM_FILE = 0,
87 GIT_ATTR_FILE_FROM_INDEX = 1
88} git_attr_file_source;
89
ee1f0b1a
RB
90/*
91 * git_attr_file API
92 */
93
f917481e
RB
94extern int git_attr_file__new(
95 git_attr_file **attrs_ptr, git_attr_file_source src, const char *path, git_pool *pool);
96
97extern int git_attr_file__new_and_load(
98 git_attr_file **attrs_ptr, const char *path);
99
a51cd8e6
RB
100extern void git_attr_file__free(git_attr_file *file);
101
2a99df69
RB
102extern void git_attr_file__clear_rules(git_attr_file *file);
103
f917481e 104extern int git_attr_file__parse_buffer(
ec40b7f9 105 git_repository *repo, void *parsedata, const char *buf, git_attr_file *file);
ee1f0b1a
RB
106
107extern int git_attr_file__lookup_one(
108 git_attr_file *file,
109 const git_attr_path *path,
110 const char *attr,
111 const char **value);
112
113/* loop over rules in file from bottom to top */
114#define git_attr_file__foreach_matching_rule(file, path, iter, rule) \
115 git_vector_rforeach(&(file)->rules, (iter), (rule)) \
ab43ad2f 116 if (git_attr_rule__match((rule), (path)))
ee1f0b1a 117
19fa2bc1 118extern uint32_t git_attr_file__name_hash(const char *name);
ee1f0b1a
RB
119
120
121/*
122 * other utilities
123 */
124
4ba64794 125extern int git_attr_fnmatch__parse(
df743c7d 126 git_attr_fnmatch *spec,
19fa2bc1 127 git_pool *pool,
a51cd8e6 128 const char *source,
df743c7d
RB
129 const char **base);
130
ab43ad2f 131extern bool git_attr_fnmatch__match(
df743c7d
RB
132 git_attr_fnmatch *rule,
133 const git_attr_path *path);
134
73b51450
RB
135extern void git_attr_rule__free(git_attr_rule *rule);
136
ab43ad2f 137extern bool git_attr_rule__match(
ee1f0b1a
RB
138 git_attr_rule *rule,
139 const git_attr_path *path);
140
141extern git_attr_assignment *git_attr_rule__lookup_assignment(
142 git_attr_rule *rule, const char *name);
143
144extern int git_attr_path__init(
adc9bdb3 145 git_attr_path *info, const char *path, const char *base);
ee1f0b1a 146
d58336dd
RB
147extern void git_attr_path__free(git_attr_path *info);
148
73b51450
RB
149extern int git_attr_assignment__parse(
150 git_repository *repo, /* needed to expand macros */
19fa2bc1 151 git_pool *pool,
73b51450
RB
152 git_vector *assigns,
153 const char **scan);
154
ee1f0b1a 155#endif