@@ -16,18 +16,23 @@ Data Structure
16
16
of no interest to the calling programs. The name of the
17
17
attribute can be retrieved by calling `git_attr_name()`.
18
18
19
- `struct git_attr_check `::
19
+ `struct attr_check_item `::
20
20
21
- This structure represents a set of attributes to check in a call
22
- to `git_check_attr()` function, and receives the results.
21
+ This structure represents one attribute and its value.
22
+
23
+ `struct attr_check`::
24
+
25
+ This structure represents a collection of `attr_check_item`.
26
+ It is passed to `git_check_attr()` function, specifying the
27
+ attributes to check, and receives their values.
23
28
24
29
25
30
Attribute Values
26
31
----------------
27
32
28
33
An attribute for a path can be in one of four states: Set, Unset,
29
34
Unspecified or set to a string, and `.value` member of `struct
30
- git_attr_check ` records it. There are three macros to check these:
35
+ attr_check_item ` records it. There are three macros to check these:
31
36
32
37
`ATTR_TRUE()`::
33
38
@@ -48,49 +53,51 @@ value of the attribute for the path.
48
53
Querying Specific Attributes
49
54
----------------------------
50
55
51
- * Prepare an array of `struct git_attr_check` to define the list of
52
- attributes you would want to check. To populate this array, you would
53
- need to define necessary attributes by calling `git_attr()` function.
56
+ * Prepare `struct attr_check` using attr_check_initl()
57
+ function, enumerating the names of attributes whose values you are
58
+ interested in, terminated with a NULL pointer. Alternatively, an
59
+ empty `struct attr_check` can be prepared by calling
60
+ `attr_check_alloc()` function and then attributes you want to
61
+ ask about can be added to it with `attr_check_append()`
62
+ function.
54
63
55
64
* Call `git_check_attr()` to check the attributes for the path.
56
65
57
- * Inspect `git_attr_check ` structure to see how each of the attribute in
58
- the array is defined for the path.
66
+ * Inspect `attr_check ` structure to see how each of the
67
+ attribute in the array is defined for the path.
59
68
60
69
61
70
Example
62
71
-------
63
72
64
- To see how attributes "crlf" and "indent " are set for different paths.
73
+ To see how attributes "crlf" and "ident " are set for different paths.
65
74
66
- . Prepare an array of `struct git_attr_check` with two elements (because
67
- we are checking two attributes). Initialize their `attr` member with
68
- pointers to `struct git_attr` obtained by calling `git_attr()`:
75
+ . Prepare a `struct attr_check` with two elements (because
76
+ we are checking two attributes):
69
77
70
78
------------
71
- static struct git_attr_check check[2] ;
79
+ static struct attr_check * check;
72
80
static void setup_check(void)
73
81
{
74
- if (check[0].attr )
82
+ if (check)
75
83
return; /* already done */
76
- check[0].attr = git_attr("crlf");
77
- check[1].attr = git_attr("ident");
84
+ check = attr_check_initl("crlf", "ident", NULL);
78
85
}
79
86
------------
80
87
81
- . Call `git_check_attr()` with the prepared array of `struct git_attr_check `:
88
+ . Call `git_check_attr()` with the prepared `struct attr_check `:
82
89
83
90
------------
84
91
const char *path;
85
92
86
93
setup_check();
87
- git_check_attr(path, ARRAY_SIZE(check), check);
94
+ git_check_attr(path, check);
88
95
------------
89
96
90
- . Act on `.value` member of the result, left in `check[]`:
97
+ . Act on `.value` member of the result, left in `check->items []`:
91
98
92
99
------------
93
- const char *value = check[0].value;
100
+ const char *value = check->items [0].value;
94
101
95
102
if (ATTR_TRUE(value)) {
96
103
The attribute is Set, by listing only the name of the
@@ -109,20 +116,39 @@ static void setup_check(void)
109
116
}
110
117
------------
111
118
119
+ To see how attributes in argv[] are set for different paths, only
120
+ the first step in the above would be different.
121
+
122
+ ------------
123
+ static struct attr_check *check;
124
+ static void setup_check(const char **argv)
125
+ {
126
+ check = attr_check_alloc();
127
+ while (*argv) {
128
+ struct git_attr *attr = git_attr(*argv);
129
+ attr_check_append(check, attr);
130
+ argv++;
131
+ }
132
+ }
133
+ ------------
134
+
112
135
113
136
Querying All Attributes
114
137
-----------------------
115
138
116
139
To get the values of all attributes associated with a file:
117
140
118
- * Call `git_all_attrs()`, which returns an array of `git_attr_check`
119
- structures.
141
+ * Prepare an empty `attr_check` structure by calling
142
+ `attr_check_alloc()`.
143
+
144
+ * Call `git_all_attrs()`, which populates the `attr_check`
145
+ with the attributes attached to the path.
120
146
121
- * Iterate over the `git_attr_check ` array to examine the attribute
122
- names and values. The name of the attribute described by a
123
- `git_attr_check ` object can be retrieved via
124
- `git_attr_name(check[i].attr)`. (Please note that no items will be
125
- returned for unset attributes, so `ATTR_UNSET()` will return false
126
- for all returned `git_array_check ` objects.)
147
+ * Iterate over the `attr_check.items[] ` array to examine
148
+ the attribute names and values. The name of the attribute
149
+ described by a `attr_check.items[] ` object can be retrieved via
150
+ `git_attr_name(check->items [i].attr)`. (Please note that no items
151
+ will be returned for unset attributes, so `ATTR_UNSET()` will return
152
+ false for all returned `attr_check.items[] ` objects.)
127
153
128
- * Free the `git_array_check` array .
154
+ * Free the `attr_check` struct by calling `attr_check_free()` .
0 commit comments