Skip to content

Commit e810e06

Browse files
bmwillgitster
authored andcommitted
attr: tighten const correctness with git_attr and match_attr
Signed-off-by: Brandon Williams <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 60a1272 commit e810e06

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

attr.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ static void report_invalid_attr(const char *name, size_t len,
220220
* dictionary. If no entry is found, create a new attribute and store it in
221221
* the dictionary.
222222
*/
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)
224224
{
225225
struct git_attr *a;
226226

@@ -244,14 +244,14 @@ static struct git_attr *git_attr_internal(const char *name, int namelen)
244244
return a;
245245
}
246246

247-
struct git_attr *git_attr(const char *name)
247+
const struct git_attr *git_attr(const char *name)
248248
{
249249
return git_attr_internal(name, strlen(name));
250250
}
251251

252252
/* What does a matched pattern decide? */
253253
struct attr_state {
254-
struct git_attr *attr;
254+
const struct git_attr *attr;
255255
const char *setto;
256256
};
257257

@@ -278,7 +278,7 @@ struct pattern {
278278
struct match_attr {
279279
union {
280280
struct pattern pat;
281-
struct git_attr *attr;
281+
const struct git_attr *attr;
282282
} u;
283283
char is_macro;
284284
unsigned num_attr;
@@ -898,7 +898,7 @@ static int fill_one(const char *what, struct all_attrs_item *all_attrs,
898898
int i;
899899

900900
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;
902902
const char **n = &(all_attrs[attr->attr_nr].value);
903903
const char *v = a->state[i].setto;
904904

@@ -922,7 +922,7 @@ static int fill(const char *path, int pathlen, int basename_offset,
922922
const char *base = stk->origin ? stk->origin : "";
923923

924924
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];
926926
if (a->is_macro)
927927
continue;
928928
if (path_matches(path, pathlen, basename_offset,

attr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct all_attrs_item;
1111
* Given a string, return the gitattribute object that
1212
* corresponds to it.
1313
*/
14-
struct git_attr *git_attr(const char *);
14+
const struct git_attr *git_attr(const char *);
1515

1616
/* Internal use */
1717
extern const char git_attr__true[];

builtin/check-attr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
166166
check = attr_check_alloc();
167167
if (!all_attrs) {
168168
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+
170171
if (!a)
171172
return error("%s: not a valid attribute name",
172173
argv[i]);

0 commit comments

Comments
 (0)