24
OPT_END()
25
};
26
27
-static void output_attr(int cnt, struct attr_check_item *check,
28
- const char *file)
27
+static void output_attr(struct attr_check *check, const char *file)
28
{
29
int j;
30
+ int cnt = check->nr;
31
+
32
for (j = 0; j < cnt; j++) {
32
- const char *value = check[j].value;
33
+ const char *value = check->items[j].value;
34
35
if (ATTR_TRUE(value))
36
value = "set";
43
printf("%s%c" /* path */
44
"%s%c" /* attrname */
45
"%s%c" /* attrvalue */,
45
- file, 0, git_attr_name(check[j].attr), 0, value, 0);
46
+ file, 0,
47
+ git_attr_name(check->items[j].attr), 0, value, 0);
48
} else {
49
quote_c_style(file, NULL, stdout, 0);
48
- printf(": %s: %s\n", git_attr_name(check[j].attr), value);
50
+ printf(": %s: %s\n",
51
+ git_attr_name(check->items[j].attr), value);
52
}
50
-
53
}
54
}
55
56
static void check_attr(const char *prefix,
55
- int cnt, struct attr_check_item *check,
57
+ struct attr_check *check,
58
+ int collect_all,
59
const char *file)
60
{
61
char *full_path =
62
prefix_path(prefix, prefix ? strlen(prefix) : 0, file);
60
- if (check != NULL) {
61
- if (git_check_attrs(full_path, cnt, check))
62
- die("git_check_attrs died");
63
- output_attr(cnt, check, file);
63
+
64
+ if (collect_all) {
65
+ git_all_attrs(full_path, check);
66
} else {
65
- if (git_all_attrs(full_path, &cnt, &check))
66
- die("git_all_attrs died");
67
- output_attr(cnt, check, file);
68
- free(check);
67
+ if (git_check_attr(full_path, check))
68
+ die("git_check_attr died");
69
}
70
+ output_attr(check, file);
71
+
72
free(full_path);
73
}
74
75
static void check_attr_stdin_paths(const char *prefix,
74
- int cnt, struct attr_check_item *check)
76
+ struct attr_check *check,
77
+ int collect_all)
78
{
79
struct strbuf buf = STRBUF_INIT;
80
struct strbuf unquoted = STRBUF_INIT;
88
die("line is badly quoted");
89
strbuf_swap(&buf, &unquoted);
90
}
88
- check_attr(prefix, cnt, check, buf.buf);
91
+ check_attr(prefix, check, collect_all, buf.buf);
92
maybe_flush_or_die(stdout, "attribute to stdout");
93
}
94
strbuf_release(&buf);
103
104
int cmd_check_attr(int argc, const char **argv, const char *prefix)
105
{
103
- struct attr_check_item *check;
106
+ struct attr_check *check;
107
int cnt, i, doubledash, filei;
108
109
if (!is_bare_repository())
163
error_with_usage("No file specified");
164
}
165
163
- if (all_attrs) {
164
- check = NULL;
165
- } else {
166
- check = xcalloc(cnt, sizeof(*check));
166
+ check = attr_check_alloc();
167
+ if (!all_attrs) {
168
for (i = 0; i < cnt; i++) {
168
- const char *name;
169
- struct git_attr *a;
170
- name = argv[i];
171
- a = git_attr(name);
169
+ struct git_attr *a = git_attr(argv[i]);
170
if (!a)
171
return error("%s: not a valid attribute name",
174
- name);
175
- check[i].attr = a;
172
+ argv[i]);
173
+ attr_check_append(check, a);
174
}
175
}
176
177
if (stdin_paths)
180
- check_attr_stdin_paths(prefix, cnt, check);
178
+ check_attr_stdin_paths(prefix, check, all_attrs);
179
else {
180
for (i = filei; i < argc; i++)
183
- check_attr(prefix, cnt, check, argv[i]);
181
+ check_attr(prefix, check, all_attrs, argv[i]);
182
maybe_flush_or_die(stdout, "attribute to stdout");
183
}
184
+
185
+ attr_check_free(check);
186
return 0;
187
}