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