]> git.proxmox.com Git - libgit2.git/blob - src/attr_file.h
Merge remote-tracking branch 'arrbee/tree-walk-fixes' into development
[libgit2.git] / src / attr_file.h
1 /*
2 * Copyright (C) 2009-2012 the libgit2 contributors
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
10 #include "git2/attr.h"
11 #include "vector.h"
12 #include "pool.h"
13 #include "buffer.h"
14
15 #define GIT_ATTR_FILE ".gitattributes"
16 #define GIT_ATTR_FILE_INREPO "info/attributes"
17 #define GIT_ATTR_FILE_SYSTEM "gitattributes"
18
19 #define GIT_ATTR_FNMATCH_NEGATIVE (1U << 0)
20 #define GIT_ATTR_FNMATCH_DIRECTORY (1U << 1)
21 #define GIT_ATTR_FNMATCH_FULLPATH (1U << 2)
22 #define GIT_ATTR_FNMATCH_MACRO (1U << 3)
23 #define GIT_ATTR_FNMATCH_IGNORE (1U << 4)
24 #define GIT_ATTR_FNMATCH_HASWILD (1U << 5)
25 #define GIT_ATTR_FNMATCH_ALLOWSPACE (1U << 6)
26
27 extern const char *git_attr__true;
28 extern const char *git_attr__false;
29 extern const char *git_attr__unset;
30
31 typedef struct {
32 char *pattern;
33 size_t length;
34 unsigned int flags;
35 } git_attr_fnmatch;
36
37 typedef struct {
38 git_attr_fnmatch match;
39 git_vector assigns; /* vector of <git_attr_assignment*> */
40 } git_attr_rule;
41
42 typedef struct {
43 git_refcount unused;
44 const char *name;
45 uint32_t name_hash;
46 } git_attr_name;
47
48 typedef struct {
49 git_refcount rc; /* for macros */
50 char *name;
51 uint32_t name_hash;
52 const char *value;
53 } git_attr_assignment;
54
55 typedef struct {
56 git_time_t seconds;
57 git_off_t size;
58 unsigned int ino;
59 } git_attr_file_stat_sig;
60
61 typedef struct {
62 char *key; /* cache "source#path" this was loaded from */
63 git_vector rules; /* vector of <rule*> or <fnmatch*> */
64 git_pool *pool;
65 bool pool_is_allocated;
66 union {
67 git_oid oid;
68 git_attr_file_stat_sig st;
69 } cache_data;
70 } git_attr_file;
71
72 typedef struct {
73 git_buf full;
74 const char *path;
75 const char *basename;
76 int is_dir;
77 } git_attr_path;
78
79 typedef enum {
80 GIT_ATTR_FILE_FROM_FILE = 0,
81 GIT_ATTR_FILE_FROM_INDEX = 1
82 } git_attr_file_source;
83
84 /*
85 * git_attr_file API
86 */
87
88 extern int git_attr_file__new(
89 git_attr_file **attrs_ptr, git_attr_file_source src, const char *path, git_pool *pool);
90
91 extern int git_attr_file__new_and_load(
92 git_attr_file **attrs_ptr, const char *path);
93
94 extern void git_attr_file__free(git_attr_file *file);
95
96 extern void git_attr_file__clear_rules(git_attr_file *file);
97
98 extern int git_attr_file__parse_buffer(
99 git_repository *repo, const char *buf, git_attr_file *file);
100
101 extern int git_attr_file__lookup_one(
102 git_attr_file *file,
103 const git_attr_path *path,
104 const char *attr,
105 const char **value);
106
107 /* loop over rules in file from bottom to top */
108 #define git_attr_file__foreach_matching_rule(file, path, iter, rule) \
109 git_vector_rforeach(&(file)->rules, (iter), (rule)) \
110 if (git_attr_rule__match((rule), (path)))
111
112 extern uint32_t git_attr_file__name_hash(const char *name);
113
114
115 /*
116 * other utilities
117 */
118
119 extern int git_attr_fnmatch__parse(
120 git_attr_fnmatch *spec,
121 git_pool *pool,
122 const char *source,
123 const char **base);
124
125 extern bool git_attr_fnmatch__match(
126 git_attr_fnmatch *rule,
127 const git_attr_path *path);
128
129 extern void git_attr_rule__free(git_attr_rule *rule);
130
131 extern bool git_attr_rule__match(
132 git_attr_rule *rule,
133 const git_attr_path *path);
134
135 extern git_attr_assignment *git_attr_rule__lookup_assignment(
136 git_attr_rule *rule, const char *name);
137
138 extern int git_attr_path__init(
139 git_attr_path *info, const char *path, const char *base);
140
141 extern void git_attr_path__free(git_attr_path *info);
142
143 extern int git_attr_assignment__parse(
144 git_repository *repo, /* needed to expand macros */
145 git_pool *pool,
146 git_vector *assigns,
147 const char **scan);
148
149 #endif