attr: rename function and struct related to checking attributes
The traditional API to check attributes is to prepare an N-element array of "struct git_attr_check" and pass N and the array to the function "git_check_attr()" as arguments. In preparation to revamp the API to pass a single structure, in which these N elements are held, rename the type used for these individual array elements to "struct attr_check_item" and rename the function to "git_check_attrs()". Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jan 27, 2017 at 18:01 UTC
7bd18054d249d1f9aebad38d74ba6c53f8e6ecb3
9 files changed
+42
-41
archive.c
+3
-3
@@ -87,7 +87,7 @@ void *sha1_file_to_archive(const struct archiver_args *args,
87
return buffer;
88
}
89
90
-static void setup_archive_check(struct git_attr_check *check)
90
+static void setup_archive_check(struct attr_check_item *check)
91
{
92
static struct git_attr *attr_export_ignore;
93
static struct git_attr *attr_export_subst;
@@ -123,7 +123,7 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
123
struct archiver_context *c = context;
124
struct archiver_args *args = c->args;
125
write_archive_entry_fn_t write_entry = c->write_entry;
126
- struct git_attr_check check[2];
126
+ struct attr_check_item check[2];
127
const char *path_without_prefix;
128
int err;
129
@@ -138,7 +138,7 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
138
path_without_prefix = path.buf + args->baselen;
139
140
setup_archive_check(check);
141
- if (!git_check_attr(path_without_prefix, ARRAY_SIZE(check), check)) {
141
+ if (!git_check_attrs(path_without_prefix, ARRAY_SIZE(check), check)) {
142
if (ATTR_TRUE(check[0].value))
143
return 0;
144
args->convert = ATTR_TRUE(check[1].value);
attr.c
+6
-6
@@ -56,7 +56,7 @@ static struct git_attr *(git_attr_hash[HASHSIZE]);
56
static int cannot_trust_maybe_real;
57
58
/* NEEDSWORK: This will become per git_attr_check */
59
-static struct git_attr_check *check_all_attr;
59
+static struct attr_check_item *check_all_attr;
60
61
const char *git_attr_name(const struct git_attr *attr)
62
{
@@ -713,7 +713,7 @@ static int macroexpand_one(int attr_nr, int rem);
713
714
static int fill_one(const char *what, struct match_attr *a, int rem)
715
{
716
- struct git_attr_check *check = check_all_attr;
716
+ struct attr_check_item *check = check_all_attr;
717
int i;
718
719
for (i = a->num_attr - 1; 0 < rem && 0 <= i; i--) {
@@ -778,7 +778,7 @@ static int macroexpand_one(int nr, int rem)
778
* collected. Otherwise all attributes are collected.
779
*/
780
static void collect_some_attrs(const char *path, int num,
781
- struct git_attr_check *check)
781
+ struct attr_check_item *check)
782
783
{
784
struct attr_stack *stk;
@@ -806,7 +806,7 @@ static void collect_some_attrs(const char *path, int num,
806
rem = 0;
807
for (i = 0; i < num; i++) {
808
if (!check[i].attr->maybe_real) {
809
- struct git_attr_check *c;
809
+ struct attr_check_item *c;
810
c = check_all_attr + check[i].attr->attr_nr;
811
c->value = ATTR__UNSET;
812
rem++;
@@ -821,7 +821,7 @@ static void collect_some_attrs(const char *path, int num,
821
rem = fill(path, pathlen, basename_offset, stk, rem);
822
}
823
824
-int git_check_attr(const char *path, int num, struct git_attr_check *check)
824
+int git_check_attrs(const char *path, int num, struct attr_check_item *check)
825
{
826
int i;
827
@@ -837,7 +837,7 @@ int git_check_attr(const char *path, int num, struct git_attr_check *check)
837
return 0;
838
}
839
840
-int git_all_attrs(const char *path, int *num, struct git_attr_check **check)
840
+int git_all_attrs(const char *path, int *num, struct attr_check_item **check)
841
{
842
int i, count, j;
843
attr.h
+4
-4
@@ -20,11 +20,11 @@ extern const char git_attr__false[];
20
#define ATTR_UNSET(v) ((v) == NULL)
21
22
/*
23
- * Send one or more git_attr_check to git_check_attr(), and
23
+ * Send one or more git_attr_check to git_check_attrs(), and
24
* each 'value' member tells what its value is.
25
* Unset one is returned as NULL.
26
*/
27
-struct git_attr_check {
27
+struct attr_check_item {
28
const struct git_attr *attr;
29
const char *value;
30
};
@@ -36,7 +36,7 @@ struct git_attr_check {
36
*/
37
extern const char *git_attr_name(const struct git_attr *);
38
39
-int git_check_attr(const char *path, int, struct git_attr_check *);
39
+int git_check_attrs(const char *path, int, struct attr_check_item *);
40
41
/*
42
* Retrieve all attributes that apply to the specified path. *num
@@ -45,7 +45,7 @@ int git_check_attr(const char *path, int, struct git_attr_check *);
45
* objects describing the attributes and their values. *check must be
46
* free()ed by the caller.
47
*/
48
-int git_all_attrs(const char *path, int *num, struct git_attr_check **check);
48
+int git_all_attrs(const char *path, int *num, struct attr_check_item **check);
49
50
enum git_attr_direction {
51
GIT_ATTR_CHECKIN,
builtin/check-attr.c
+10
-9
@@ -24,8 +24,8 @@ static const struct option check_attr_options[] = {
24
OPT_END()
25
};
26
27
-static void output_attr(int cnt, struct git_attr_check *check,
28
- const char *file)
27
+static void output_attr(int cnt, struct attr_check_item *check,
28
+ const char *file)
29
{
30
int j;
31
for (j = 0; j < cnt; j++) {
@@ -51,14 +51,15 @@ static void output_attr(int cnt, struct git_attr_check *check,
51
}
52
}
53
54
-static void check_attr(const char *prefix, int cnt,
55
- struct git_attr_check *check, const char *file)
54
+static void check_attr(const char *prefix,
55
+ int cnt, struct attr_check_item *check,
56
+ const char *file)
57
{
58
char *full_path =
59
prefix_path(prefix, prefix ? strlen(prefix) : 0, file);
60
if (check != NULL) {
60
- if (git_check_attr(full_path, cnt, check))
61
- die("git_check_attr died");
61
+ if (git_check_attrs(full_path, cnt, check))
62
+ die("git_check_attrs died");
63
output_attr(cnt, check, file);
64
} else {
65
if (git_all_attrs(full_path, &cnt, &check))
@@ -69,8 +70,8 @@ static void check_attr(const char *prefix, int cnt,
70
free(full_path);
71
}
72
72
-static void check_attr_stdin_paths(const char *prefix, int cnt,
73
- struct git_attr_check *check)
73
+static void check_attr_stdin_paths(const char *prefix,
74
+ int cnt, struct attr_check_item *check)
75
{
76
struct strbuf buf = STRBUF_INIT;
77
struct strbuf unquoted = STRBUF_INIT;
@@ -99,7 +100,7 @@ static NORETURN void error_with_usage(const char *msg)
100
101
int cmd_check_attr(int argc, const char **argv, const char *prefix)
102
{
102
- struct git_attr_check *check;
103
+ struct attr_check_item *check;
104
int cnt, i, doubledash, filei;
105
106
if (!is_bare_repository())
builtin/pack-objects.c
+3
-3
@@ -894,7 +894,7 @@ static void write_pack_file(void)
894
written, nr_result);
895
}
896
897
-static void setup_delta_attr_check(struct git_attr_check *check)
897
+static void setup_delta_attr_check(struct attr_check_item *check)
898
{
899
static struct git_attr *attr_delta;
900
@@ -906,10 +906,10 @@ static void setup_delta_attr_check(struct git_attr_check *check)
906
907
static int no_try_delta(const char *path)
908
{
909
- struct git_attr_check check[1];
909
+ struct attr_check_item check[1];
910
911
setup_delta_attr_check(check);
912
- if (git_check_attr(path, ARRAY_SIZE(check), check))
912
+ if (git_check_attrs(path, ARRAY_SIZE(check), check))
913
return 0;
914
if (ATTR_FALSE(check->value))
915
return 1;
convert.c
+6
-6
@@ -1028,7 +1028,7 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
1028
return 1;
1029
}
1030
1031
-static enum crlf_action git_path_check_crlf(struct git_attr_check *check)
1031
+static enum crlf_action git_path_check_crlf(struct attr_check_item *check)
1032
{
1033
const char *value = check->value;
1034
@@ -1045,7 +1045,7 @@ static enum crlf_action git_path_check_crlf(struct git_attr_check *check)
1045
return CRLF_UNDEFINED;
1046
}
1047
1048
-static enum eol git_path_check_eol(struct git_attr_check *check)
1048
+static enum eol git_path_check_eol(struct attr_check_item *check)
1049
{
1050
const char *value = check->value;
1051
@@ -1058,7 +1058,7 @@ static enum eol git_path_check_eol(struct git_attr_check *check)
1058
return EOL_UNSET;
1059
}
1060
1061
-static struct convert_driver *git_path_check_convert(struct git_attr_check *check)
1061
+static struct convert_driver *git_path_check_convert(struct attr_check_item *check)
1062
{
1063
const char *value = check->value;
1064
struct convert_driver *drv;
@@ -1071,7 +1071,7 @@ static struct convert_driver *git_path_check_convert(struct git_attr_check *chec
1071
return NULL;
1072
}
1073
1074
-static int git_path_check_ident(struct git_attr_check *check)
1074
+static int git_path_check_ident(struct attr_check_item *check)
1075
{
1076
const char *value = check->value;
1077
@@ -1093,7 +1093,7 @@ static const char *conv_attr_name[] = {
1093
static void convert_attrs(struct conv_attrs *ca, const char *path)
1094
{
1095
int i;
1096
- static struct git_attr_check ccheck[NUM_CONV_ATTRS];
1096
+ static struct attr_check_item ccheck[NUM_CONV_ATTRS];
1097
1098
if (!ccheck[0].attr) {
1099
for (i = 0; i < NUM_CONV_ATTRS; i++)
@@ -1102,7 +1102,7 @@ static void convert_attrs(struct conv_attrs *ca, const char *path)
1102
git_config(read_convert_config, NULL);
1103
}
1104
1105
- if (!git_check_attr(path, NUM_CONV_ATTRS, ccheck)) {
1105
+ if (!git_check_attrs(path, NUM_CONV_ATTRS, ccheck)) {
1106
ca->crlf_action = git_path_check_crlf(ccheck + 4);
1107
if (ca->crlf_action == CRLF_UNDEFINED)
1108
ca->crlf_action = git_path_check_crlf(ccheck + 0);
ll-merge.c
+5
-5
@@ -336,13 +336,13 @@ static const struct ll_merge_driver *find_ll_merge_driver(const char *merge_attr
336
return &ll_merge_drv[LL_TEXT_MERGE];
337
}
338
339
-static int git_path_check_merge(const char *path, struct git_attr_check check[2])
339
+static int git_path_check_merge(const char *path, struct attr_check_item check[2])
340
{
341
if (!check[0].attr) {
342
check[0].attr = git_attr("merge");
343
check[1].attr = git_attr("conflict-marker-size");
344
}
345
- return git_check_attr(path, 2, check);
345
+ return git_check_attrs(path, 2, check);
346
}
347
348
static void normalize_file(mmfile_t *mm, const char *path)
@@ -362,7 +362,7 @@ int ll_merge(mmbuffer_t *result_buf,
362
mmfile_t *theirs, const char *their_label,
363
const struct ll_merge_options *opts)
364
{
365
- static struct git_attr_check check[2];
365
+ static struct attr_check_item check[2];
366
static const struct ll_merge_options default_opts;
367
const char *ll_driver_name = NULL;
368
int marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
@@ -398,12 +398,12 @@ int ll_merge(mmbuffer_t *result_buf,
398
399
int ll_merge_marker_size(const char *path)
400
{
401
- static struct git_attr_check check;
401
+ static struct attr_check_item check;
402
int marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
403
404
if (!check.attr)
405
check.attr = git_attr("conflict-marker-size");
406
- if (!git_check_attr(path, 1, &check) && check.value) {
406
+ if (!git_check_attrs(path, 1, &check) && check.value) {
407
marker_size = atoi(check.value);
408
if (marker_size <= 0)
409
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
userdiff.c
+2
-2
@@ -263,7 +263,7 @@ struct userdiff_driver *userdiff_find_by_name(const char *name) {
263
struct userdiff_driver *userdiff_find_by_path(const char *path)
264
{
265
static struct git_attr *attr;
266
- struct git_attr_check check;
266
+ struct attr_check_item check;
267
268
if (!attr)
269
attr = git_attr("diff");
@@ -271,7 +271,7 @@ struct userdiff_driver *userdiff_find_by_path(const char *path)
271
272
if (!path)
273
return NULL;
274
- if (git_check_attr(path, 1, &check))
274
+ if (git_check_attrs(path, 1, &check))
275
return NULL;
276
277
if (ATTR_TRUE(check.value))
ws.c
+3
-3
@@ -71,7 +71,7 @@ unsigned parse_whitespace_rule(const char *string)
71
return rule;
72
}
73
74
-static void setup_whitespace_attr_check(struct git_attr_check *check)
74
+static void setup_whitespace_attr_check(struct attr_check_item *check)
75
{
76
static struct git_attr *attr_whitespace;
77
@@ -82,10 +82,10 @@ static void setup_whitespace_attr_check(struct git_attr_check *check)
82
83
unsigned whitespace_rule(const char *pathname)
84
{
85
- struct git_attr_check attr_whitespace_rule;
85
+ struct attr_check_item attr_whitespace_rule;
86
87
setup_whitespace_attr_check(&attr_whitespace_rule);
88
- if (!git_check_attr(pathname, 1, &attr_whitespace_rule)) {
88
+ if (!git_check_attrs(pathname, 1, &attr_whitespace_rule)) {
89
const char *value;
90
91
value = attr_whitespace_rule.value;