blob: 442d464db6271da48a4ef133127c7d3a18c186cf [file] [log] [blame]
Junio C Hamanod0bfd022007-04-12 01:07:32 -07001#ifndef ATTR_H
2#define ATTR_H
3
4/* An attribute is a pointer to this opaque structure */
5struct git_attr;
6
Brandon Williamsdc81cf32017-01-27 18:02:05 -08007/* opaque structures used internally for attribute collection */
Brandon Williams685b2922017-01-27 18:02:02 -08008struct all_attrs_item;
Brandon Williamsdc81cf32017-01-27 18:02:05 -08009struct attr_stack;
Brandon Williams685b2922017-01-27 18:02:02 -080010
Junio C Hamanoa5e92ab2007-04-18 16:16:37 -070011/*
12 * Given a string, return the gitattribute object that
13 * corresponds to it.
14 */
Brandon Williamse810e062017-01-27 18:02:04 -080015const struct git_attr *git_attr(const char *);
Junio C Hamanod0bfd022007-04-12 01:07:32 -070016
Junio C Hamano515106f2007-04-16 21:33:31 -070017/* Internal use */
Junio C Hamanoa5e92ab2007-04-18 16:16:37 -070018extern const char git_attr__true[];
19extern const char git_attr__false[];
Junio C Hamano515106f2007-04-16 21:33:31 -070020
21/* For public to check git_attr_check results */
Junio C Hamanoa5e92ab2007-04-18 16:16:37 -070022#define ATTR_TRUE(v) ((v) == git_attr__true)
23#define ATTR_FALSE(v) ((v) == git_attr__false)
24#define ATTR_UNSET(v) ((v) == NULL)
Junio C Hamano515106f2007-04-16 21:33:31 -070025
Junio C Hamanoa5e92ab2007-04-18 16:16:37 -070026/*
Junio C Hamano7bd18052017-01-27 18:01:54 -080027 * Send one or more git_attr_check to git_check_attrs(), and
Junio C Hamanoa5e92ab2007-04-18 16:16:37 -070028 * each 'value' member tells what its value is.
29 * Unset one is returned as NULL.
30 */
Junio C Hamano7bd18052017-01-27 18:01:54 -080031struct attr_check_item {
Junio C Hamanoec4d77a2017-01-27 18:01:48 -080032 const struct git_attr *attr;
Junio C Hamanoa5e92ab2007-04-18 16:16:37 -070033 const char *value;
Junio C Hamanod0bfd022007-04-12 01:07:32 -070034};
35
Junio C Hamano37293762017-01-30 10:05:20 -080036struct attr_check {
37 int nr;
38 int alloc;
39 struct attr_check_item *items;
Brandon Williams685b2922017-01-27 18:02:02 -080040 int all_attrs_nr;
41 struct all_attrs_item *all_attrs;
Brandon Williamsdc81cf32017-01-27 18:02:05 -080042 struct attr_stack *stack;
Junio C Hamano37293762017-01-30 10:05:20 -080043};
44
45extern struct attr_check *attr_check_alloc(void);
46extern struct attr_check *attr_check_initl(const char *, ...);
Brandon Williamsb0db7042017-03-13 11:23:21 -070047extern struct attr_check *attr_check_dup(const struct attr_check *check);
Junio C Hamano37293762017-01-30 10:05:20 -080048
49extern struct attr_check_item *attr_check_append(struct attr_check *check,
50 const struct git_attr *attr);
51
52extern void attr_check_reset(struct attr_check *check);
53extern void attr_check_clear(struct attr_check *check);
54extern void attr_check_free(struct attr_check *check);
55
Michael Haggerty352404a2011-08-04 06:36:17 +020056/*
57 * Return the name of the attribute represented by the argument. The
58 * return value is a pointer to a null-delimited string that is part
59 * of the internal data structure; it should not be modified or freed.
60 */
Junio C Hamanoec4d77a2017-01-27 18:01:48 -080061extern const char *git_attr_name(const struct git_attr *);
Michael Haggerty352404a2011-08-04 06:36:17 +020062
Junio C Hamano37293762017-01-30 10:05:20 -080063extern int git_check_attr(const char *path, struct attr_check *check);
Junio C Hamanod0bfd022007-04-12 01:07:32 -070064
Michael Haggertyee548df2011-08-04 06:36:23 +020065/*
Junio C Hamano7f864112017-01-30 10:06:08 -080066 * Retrieve all attributes that apply to the specified path.
67 * check holds the attributes and their values.
Michael Haggertyee548df2011-08-04 06:36:23 +020068 */
Junio C Hamano7f864112017-01-30 10:06:08 -080069extern void git_all_attrs(const char *path, struct attr_check *check);
Michael Haggertyee548df2011-08-04 06:36:23 +020070
Junio C Hamano06f33c12009-03-13 21:24:08 -070071enum git_attr_direction {
72 GIT_ATTR_CHECKIN,
Nguyễn Thái Ngọc Duy4191e802009-04-18 00:17:58 +020073 GIT_ATTR_CHECKOUT,
Gary V. Vaughan4b055482010-05-14 09:31:35 +000074 GIT_ATTR_INDEX
Junio C Hamano06f33c12009-03-13 21:24:08 -070075};
Brandon Williamsf0dd0422017-01-27 18:02:07 -080076void git_attr_set_direction(enum git_attr_direction new_direction,
77 struct index_state *istate);
Junio C Hamano06f33c12009-03-13 21:24:08 -070078
Brandon Williams1a600b72017-01-27 18:02:01 -080079extern void attr_start(void);
80
Junio C Hamanod0bfd022007-04-12 01:07:32 -070081#endif /* ATTR_H */