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