4 gitattributes mechanism gives a uniform way to associate various
5 attributes to set of paths.
13 An attribute is an opaque object that is identified by its name.
14 Pass the name and its length to `git_attr()` function to obtain
15 the object of this type. The internal representation of this
16 structure is of no interest to the calling programs.
18 `struct git_attr_check`::
20 This structure represents a set of attributes to check in a call
21 to `git_checkattr()` function, and receives the results.
27 * Prepare an array of `struct git_attr_check` to define the list of
28 attributes you would want to check. To populate this array, you would
29 need to define necessary attributes by calling `git_attr()` function.
31 * Call git_checkattr() to check the attributes for the path.
33 * Inspect `git_attr_check` structure to see how each of the attribute in
34 the array is defined for the path.
40 An attribute for a path can be in one of four states: Set, Unset,
41 Unspecified or set to a string, and `.value` member of `struct
42 git_attr_check` records it. There are three macros to check these:
46 Returns true if the attribute is Set for the path.
50 Returns true if the attribute is Unset for the path.
54 Returns true if the attribute is Unspecified for the path.
56 If none of the above returns true, `.value` member points at a string
57 value of the attribute for the path.
63 To see how attributes "crlf" and "indent" are set for different paths.
65 . Prepare an array of `struct git_attr_check` with two elements (because
66 we are checking two attributes). Initialize their `attr` member with
67 pointers to `struct git_attr` obtained by calling `git_attr()`:
70 static struct git_attr_check check[2];
71 static void setup_check(void)
74 return; /* already done */
75 check[0].attr = git_attr("crlf", 4);
76 check[1].attr = git_attr("ident", 5);
80 . Call `git_checkattr()` with the prepared array of `struct git_attr_check`:
86 git_checkattr(path, ARRAY_SIZE(check), check);
89 . Act on `.value` member of the result, left in `check[]`:
92 const char *value = check[0].value;
94 if (ATTR_TRUE(value)) {
95 The attribute is Set, by listing only the name of the
96 attribute in the gitattributes file for the path.
97 } else if (ATTR_FALSE(value)) {
98 The attribute is Unset, by listing the name of the
99 attribute prefixed with a dash - for the path.
100 } else if (ATTR_UNSET(value)) {
101 The attribute is not set nor unset for the path.
102 } else if (!strcmp(value, "input")) {
103 If none of ATTR_TRUE(), ATTR_FALSE(), or ATTR_UNSET() is
104 true, the value is a string set in the gitattributes
105 file for the path by saying "attr=value".
106 } else if (... other check using value as string ...) {