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