attr: convert git_check_attrs() callers to use the new API
The remaining callers are all simple "I have N attributes I am interested in. I'll ask about them with various paths one by one". After this step, no caller to git_check_attrs() remains. After removing it, we can extend "struct attr_check" struct with data that can be used in optimizing the query for the specific N attributes it contains. 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
2aef63d31c338a764099e925d35fe2a9c71348a8
6 files changed
+45
-86
archive.c
+6
-18
@@ -87,19 +87,6 @@ void *sha1_file_to_archive(const struct archiver_args *args,
87
return buffer;
88
}
89
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;
94
-
95
- if (!attr_export_ignore) {
96
- attr_export_ignore = git_attr("export-ignore");
97
- attr_export_subst = git_attr("export-subst");
98
- }
99
- check[0].attr = attr_export_ignore;
100
- check[1].attr = attr_export_subst;
101
-}
102
-
90
struct directory {
91
struct directory *up;
92
struct object_id oid;
@@ -120,10 +107,10 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
107
void *context)
108
{
109
static struct strbuf path = STRBUF_INIT;
110
+ static struct attr_check *check;
111
struct archiver_context *c = context;
112
struct archiver_args *args = c->args;
113
write_archive_entry_fn_t write_entry = c->write_entry;
126
- struct attr_check_item check[2];
114
const char *path_without_prefix;
115
int err;
116
@@ -137,11 +124,12 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
124
strbuf_addch(&path, '/');
125
path_without_prefix = path.buf + args->baselen;
126
140
- setup_archive_check(check);
141
- if (!git_check_attrs(path_without_prefix, ARRAY_SIZE(check), check)) {
142
- if (ATTR_TRUE(check[0].value))
127
+ if (!check)
128
+ check = attr_check_initl("export-ignore", "export-subst", NULL);
129
+ if (!git_check_attr(path_without_prefix, check)) {
130
+ if (ATTR_TRUE(check->items[0].value))
131
return 0;
144
- args->convert = ATTR_TRUE(check[1].value);
132
+ args->convert = ATTR_TRUE(check->items[1].value);
133
}
134
135
if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
builtin/pack-objects.c
+5
-14
@@ -894,24 +894,15 @@ static void write_pack_file(void)
894
written, nr_result);
895
}
896
897
-static void setup_delta_attr_check(struct attr_check_item *check)
898
-{
899
- static struct git_attr *attr_delta;
900
-
901
- if (!attr_delta)
902
- attr_delta = git_attr("delta");
903
-
904
- check[0].attr = attr_delta;
905
-}
906
-
897
static int no_try_delta(const char *path)
898
{
909
- struct attr_check_item check[1];
899
+ static struct attr_check *check;
900
911
- setup_delta_attr_check(check);
912
- if (git_check_attrs(path, ARRAY_SIZE(check), check))
901
+ if (!check)
902
+ check = attr_check_initl("delta", NULL);
903
+ if (git_check_attr(path, check))
904
return 0;
914
- if (ATTR_FALSE(check->value))
905
+ if (ATTR_FALSE(check->items[0].value))
906
return 1;
907
return 0;
908
}
convert.c
+6
-11
@@ -1085,24 +1085,19 @@ struct conv_attrs {
1085
int ident;
1086
};
1087
1088
-static const char *conv_attr_name[] = {
1089
- "crlf", "ident", "filter", "eol", "text",
1090
-};
1091
-#define NUM_CONV_ATTRS ARRAY_SIZE(conv_attr_name)
1092
-
1088
static void convert_attrs(struct conv_attrs *ca, const char *path)
1089
{
1095
- int i;
1096
- static struct attr_check_item ccheck[NUM_CONV_ATTRS];
1090
+ static struct attr_check *check;
1091
1098
- if (!ccheck[0].attr) {
1099
- for (i = 0; i < NUM_CONV_ATTRS; i++)
1100
- ccheck[i].attr = git_attr(conv_attr_name[i]);
1092
+ if (!check) {
1093
+ check = attr_check_initl("crlf", "ident", "filter",
1094
+ "eol", "text", NULL);
1095
user_convert_tail = &user_convert;
1096
git_config(read_convert_config, NULL);
1097
}
1098
1105
- if (!git_check_attrs(path, NUM_CONV_ATTRS, ccheck)) {
1099
+ if (!git_check_attr(path, check)) {
1100
+ struct attr_check_item *ccheck = check->items;
1101
ca->crlf_action = git_path_check_crlf(ccheck + 4);
1102
if (ca->crlf_action == CRLF_UNDEFINED)
1103
ca->crlf_action = git_path_check_crlf(ccheck + 0);
ll-merge.c
+14
-19
@@ -336,15 +336,6 @@ 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 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_attrs(path, 2, check);
346
-}
347
-
339
static void normalize_file(mmfile_t *mm, const char *path)
340
{
341
struct strbuf strbuf = STRBUF_INIT;
@@ -362,7 +353,7 @@ int ll_merge(mmbuffer_t *result_buf,
353
mmfile_t *theirs, const char *their_label,
354
const struct ll_merge_options *opts)
355
{
365
- static struct attr_check_item check[2];
356
+ static struct attr_check *check;
357
static const struct ll_merge_options default_opts;
358
const char *ll_driver_name = NULL;
359
int marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
@@ -376,10 +367,14 @@ int ll_merge(mmbuffer_t *result_buf,
367
normalize_file(ours, path);
368
normalize_file(theirs, path);
369
}
379
- if (!git_path_check_merge(path, check)) {
380
- ll_driver_name = check[0].value;
381
- if (check[1].value) {
382
- marker_size = atoi(check[1].value);
370
+
371
+ if (!check)
372
+ check = attr_check_initl("merge", "conflict-marker-size", NULL);
373
+
374
+ if (!git_check_attr(path, check)) {
375
+ ll_driver_name = check->items[0].value;
376
+ if (check->items[1].value) {
377
+ marker_size = atoi(check->items[1].value);
378
if (marker_size <= 0)
379
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
380
}
@@ -398,13 +393,13 @@ int ll_merge(mmbuffer_t *result_buf,
393
394
int ll_merge_marker_size(const char *path)
395
{
401
- static struct attr_check_item check;
396
+ static struct attr_check *check;
397
int marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
398
404
- if (!check.attr)
405
- check.attr = git_attr("conflict-marker-size");
406
- if (!git_check_attrs(path, 1, &check) && check.value) {
407
- marker_size = atoi(check.value);
399
+ if (!check)
400
+ check = attr_check_initl("conflict-marker-size", NULL);
401
+ if (!git_check_attr(path, check) && check->items[0].value) {
402
+ marker_size = atoi(check->items[0].value);
403
if (marker_size <= 0)
404
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
405
}
userdiff.c
+8
-11
@@ -262,25 +262,22 @@ struct userdiff_driver *userdiff_find_by_name(const char *name) {
262
263
struct userdiff_driver *userdiff_find_by_path(const char *path)
264
{
265
- static struct git_attr *attr;
266
- struct attr_check_item check;
267
-
268
- if (!attr)
269
- attr = git_attr("diff");
270
- check.attr = attr;
265
+ static struct attr_check *check;
266
267
+ if (!check)
268
+ check = attr_check_initl("diff", NULL);
269
if (!path)
270
return NULL;
274
- if (git_check_attrs(path, 1, &check))
271
+ if (git_check_attr(path, check))
272
return NULL;
273
277
- if (ATTR_TRUE(check.value))
274
+ if (ATTR_TRUE(check->items[0].value))
275
return &driver_true;
279
- if (ATTR_FALSE(check.value))
276
+ if (ATTR_FALSE(check->items[0].value))
277
return &driver_false;
281
- if (ATTR_UNSET(check.value))
278
+ if (ATTR_UNSET(check->items[0].value))
279
return NULL;
283
- return userdiff_find_by_name(check.value);
280
+ return userdiff_find_by_name(check->items[0].value);
281
}
282
283
struct userdiff_driver *userdiff_get_textconv(struct userdiff_driver *driver)
ws.c
+6
-13
@@ -71,24 +71,17 @@ unsigned parse_whitespace_rule(const char *string)
71
return rule;
72
}
73
74
-static void setup_whitespace_attr_check(struct attr_check_item *check)
75
-{
76
- static struct git_attr *attr_whitespace;
77
-
78
- if (!attr_whitespace)
79
- attr_whitespace = git_attr("whitespace");
80
- check[0].attr = attr_whitespace;
81
-}
82
-
74
unsigned whitespace_rule(const char *pathname)
75
{
85
- struct attr_check_item attr_whitespace_rule;
76
+ static struct attr_check *attr_whitespace_rule;
77
+
78
+ if (!attr_whitespace_rule)
79
+ attr_whitespace_rule = attr_check_initl("whitespace", NULL);
80
87
- setup_whitespace_attr_check(&attr_whitespace_rule);
88
- if (!git_check_attrs(pathname, 1, &attr_whitespace_rule)) {
81
+ if (!git_check_attr(pathname, attr_whitespace_rule)) {
82
const char *value;
83
91
- value = attr_whitespace_rule.value;
84
+ value = attr_whitespace_rule->items[0].value;
85
if (ATTR_TRUE(value)) {
86
/* true (whitespace) */
87
unsigned all_rule = ws_tab_width(whitespace_rule_cfg);