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