Skip to content

Commit 2aef63d

Browse files
committed
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 <[email protected]> Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Brandon Williams <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7f86411 commit 2aef63d

File tree

6 files changed

+45
-86
lines changed

6 files changed

+45
-86
lines changed

archive.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,6 @@ void *sha1_file_to_archive(const struct archiver_args *args,
8787
return buffer;
8888
}
8989

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-
10390
struct directory {
10491
struct directory *up;
10592
struct object_id oid;
@@ -120,10 +107,10 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
120107
void *context)
121108
{
122109
static struct strbuf path = STRBUF_INIT;
110+
static struct attr_check *check;
123111
struct archiver_context *c = context;
124112
struct archiver_args *args = c->args;
125113
write_archive_entry_fn_t write_entry = c->write_entry;
126-
struct attr_check_item check[2];
127114
const char *path_without_prefix;
128115
int err;
129116

@@ -137,11 +124,12 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
137124
strbuf_addch(&path, '/');
138125
path_without_prefix = path.buf + args->baselen;
139126

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))
143131
return 0;
144-
args->convert = ATTR_TRUE(check[1].value);
132+
args->convert = ATTR_TRUE(check->items[1].value);
145133
}
146134

147135
if (S_ISDIR(mode) || S_ISGITLINK(mode)) {

builtin/pack-objects.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -894,24 +894,15 @@ static void write_pack_file(void)
894894
written, nr_result);
895895
}
896896

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-
907897
static int no_try_delta(const char *path)
908898
{
909-
struct attr_check_item check[1];
899+
static struct attr_check *check;
910900

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))
913904
return 0;
914-
if (ATTR_FALSE(check->value))
905+
if (ATTR_FALSE(check->items[0].value))
915906
return 1;
916907
return 0;
917908
}

convert.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,24 +1085,19 @@ struct conv_attrs {
10851085
int ident;
10861086
};
10871087

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-
10931088
static void convert_attrs(struct conv_attrs *ca, const char *path)
10941089
{
1095-
int i;
1096-
static struct attr_check_item ccheck[NUM_CONV_ATTRS];
1090+
static struct attr_check *check;
10971091

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);
11011095
user_convert_tail = &user_convert;
11021096
git_config(read_convert_config, NULL);
11031097
}
11041098

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;
11061101
ca->crlf_action = git_path_check_crlf(ccheck + 4);
11071102
if (ca->crlf_action == CRLF_UNDEFINED)
11081103
ca->crlf_action = git_path_check_crlf(ccheck + 0);

ll-merge.c

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,6 @@ static const struct ll_merge_driver *find_ll_merge_driver(const char *merge_attr
336336
return &ll_merge_drv[LL_TEXT_MERGE];
337337
}
338338

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-
348339
static void normalize_file(mmfile_t *mm, const char *path)
349340
{
350341
struct strbuf strbuf = STRBUF_INIT;
@@ -362,7 +353,7 @@ int ll_merge(mmbuffer_t *result_buf,
362353
mmfile_t *theirs, const char *their_label,
363354
const struct ll_merge_options *opts)
364355
{
365-
static struct attr_check_item check[2];
356+
static struct attr_check *check;
366357
static const struct ll_merge_options default_opts;
367358
const char *ll_driver_name = NULL;
368359
int marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
@@ -376,10 +367,14 @@ int ll_merge(mmbuffer_t *result_buf,
376367
normalize_file(ours, path);
377368
normalize_file(theirs, path);
378369
}
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);
383378
if (marker_size <= 0)
384379
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
385380
}
@@ -398,13 +393,13 @@ int ll_merge(mmbuffer_t *result_buf,
398393

399394
int ll_merge_marker_size(const char *path)
400395
{
401-
static struct attr_check_item check;
396+
static struct attr_check *check;
402397
int marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
403398

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);
408403
if (marker_size <= 0)
409404
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
410405
}

userdiff.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -262,25 +262,22 @@ struct userdiff_driver *userdiff_find_by_name(const char *name) {
262262

263263
struct userdiff_driver *userdiff_find_by_path(const char *path)
264264
{
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;
271266

267+
if (!check)
268+
check = attr_check_initl("diff", NULL);
272269
if (!path)
273270
return NULL;
274-
if (git_check_attrs(path, 1, &check))
271+
if (git_check_attr(path, check))
275272
return NULL;
276273

277-
if (ATTR_TRUE(check.value))
274+
if (ATTR_TRUE(check->items[0].value))
278275
return &driver_true;
279-
if (ATTR_FALSE(check.value))
276+
if (ATTR_FALSE(check->items[0].value))
280277
return &driver_false;
281-
if (ATTR_UNSET(check.value))
278+
if (ATTR_UNSET(check->items[0].value))
282279
return NULL;
283-
return userdiff_find_by_name(check.value);
280+
return userdiff_find_by_name(check->items[0].value);
284281
}
285282

286283
struct userdiff_driver *userdiff_get_textconv(struct userdiff_driver *driver)

ws.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,17 @@ unsigned parse_whitespace_rule(const char *string)
7171
return rule;
7272
}
7373

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-
8374
unsigned whitespace_rule(const char *pathname)
8475
{
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);
8680

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)) {
8982
const char *value;
9083

91-
value = attr_whitespace_rule.value;
84+
value = attr_whitespace_rule->items[0].value;
9285
if (ATTR_TRUE(value)) {
9386
/* true (whitespace) */
9487
unsigned all_rule = ws_tab_width(whitespace_rule_cfg);

0 commit comments

Comments
 (0)