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