attr: tighten const correctness with git_attr and match_attr
Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brandon Williams committed
Jan 27, 2017 at 18:02 UTC
e810e0635767afbc9b304d5256fbdb26b59644fa
3 files changed
+9
-8
attr.c
+6
-6
@@ -220,7 +220,7 @@ static void report_invalid_attr(const char *name, size_t len,
220
* dictionary. If no entry is found, create a new attribute and store it in
221
* the dictionary.
222
*/
223
-static struct git_attr *git_attr_internal(const char *name, int namelen)
223
+static const struct git_attr *git_attr_internal(const char *name, int namelen)
224
{
225
struct git_attr *a;
226
@@ -244,14 +244,14 @@ static struct git_attr *git_attr_internal(const char *name, int namelen)
244
return a;
245
}
246
247
-struct git_attr *git_attr(const char *name)
247
+const struct git_attr *git_attr(const char *name)
248
{
249
return git_attr_internal(name, strlen(name));
250
}
251
252
/* What does a matched pattern decide? */
253
struct attr_state {
254
- struct git_attr *attr;
254
+ const struct git_attr *attr;
255
const char *setto;
256
};
257
@@ -278,7 +278,7 @@ struct pattern {
278
struct match_attr {
279
union {
280
struct pattern pat;
281
- struct git_attr *attr;
281
+ const struct git_attr *attr;
282
} u;
283
char is_macro;
284
unsigned num_attr;
@@ -898,7 +898,7 @@ static int fill_one(const char *what, struct all_attrs_item *all_attrs,
898
int i;
899
900
for (i = a->num_attr - 1; rem > 0 && i >= 0; i--) {
901
- struct git_attr *attr = a->state[i].attr;
901
+ const struct git_attr *attr = a->state[i].attr;
902
const char **n = &(all_attrs[attr->attr_nr].value);
903
const char *v = a->state[i].setto;
904
@@ -922,7 +922,7 @@ static int fill(const char *path, int pathlen, int basename_offset,
922
const char *base = stk->origin ? stk->origin : "";
923
924
for (i = stk->num_matches - 1; 0 < rem && 0 <= i; i--) {
925
- struct match_attr *a = stk->attrs[i];
925
+ const struct match_attr *a = stk->attrs[i];
926
if (a->is_macro)
927
continue;
928
if (path_matches(path, pathlen, basename_offset,
attr.h
+1
-1
@@ -11,7 +11,7 @@ struct all_attrs_item;
11
* Given a string, return the gitattribute object that
12
* corresponds to it.
13
*/
14
-struct git_attr *git_attr(const char *);
14
+const struct git_attr *git_attr(const char *);
15
16
/* Internal use */
17
extern const char git_attr__true[];
builtin/check-attr.c
+2
-1
@@ -166,7 +166,8 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
166
check = attr_check_alloc();
167
if (!all_attrs) {
168
for (i = 0; i < cnt; i++) {
169
- struct git_attr *a = git_attr(argv[i]);
169
+ const struct git_attr *a = git_attr(argv[i]);
170
+
171
if (!a)
172
return error("%s: not a valid attribute name",
173
argv[i]);