]>
Commit | Line | Data |
---|---|---|
d0bfd026 | 1 | #include "builtin.h" |
6b06d518 | 2 | #include "cache.h" |
d0bfd026 JH |
3 | #include "attr.h" |
4 | #include "quote.h" | |
5 | ||
6 | static const char check_attr_usage[] = | |
1b1dd23f | 7 | "git check-attr attr... [--] pathname..."; |
d0bfd026 JH |
8 | |
9 | int cmd_check_attr(int argc, const char **argv, const char *prefix) | |
10 | { | |
11 | struct git_attr_check *check; | |
12 | int cnt, i, doubledash; | |
13 | ||
6b06d518 BD |
14 | if (read_cache() < 0) { |
15 | die("invalid cache"); | |
16 | } | |
17 | ||
d0bfd026 JH |
18 | doubledash = -1; |
19 | for (i = 1; doubledash < 0 && i < argc; i++) { | |
20 | if (!strcmp(argv[i], "--")) | |
21 | doubledash = i; | |
22 | } | |
23 | ||
24 | /* If there is no double dash, we handle only one attribute */ | |
25 | if (doubledash < 0) { | |
26 | cnt = 1; | |
27 | doubledash = 1; | |
28 | } else | |
29 | cnt = doubledash - 1; | |
30 | doubledash++; | |
31 | ||
32 | if (cnt <= 0 || argc < doubledash) | |
33 | usage(check_attr_usage); | |
34 | check = xcalloc(cnt, sizeof(*check)); | |
35 | for (i = 0; i < cnt; i++) { | |
36 | const char *name; | |
e4aee10a | 37 | struct git_attr *a; |
d0bfd026 | 38 | name = argv[i + 1]; |
e4aee10a JH |
39 | a = git_attr(name, strlen(name)); |
40 | if (!a) | |
41 | return error("%s: not a valid attribute name", name); | |
42 | check[i].attr = a; | |
d0bfd026 JH |
43 | } |
44 | ||
45 | for (i = doubledash; i < argc; i++) { | |
46 | int j; | |
47 | if (git_checkattr(argv[i], cnt, check)) | |
48 | die("git_checkattr died"); | |
49 | for (j = 0; j < cnt; j++) { | |
a5e92abd | 50 | const char *value = check[j].value; |
515106fa JH |
51 | |
52 | if (ATTR_TRUE(value)) | |
53 | value = "set"; | |
54 | else if (ATTR_FALSE(value)) | |
55 | value = "unset"; | |
56 | else if (ATTR_UNSET(value)) | |
57 | value = "unspecified"; | |
58 | ||
663af342 | 59 | quote_c_style(argv[i], NULL, stdout, 0); |
a5e92abd | 60 | printf(": %s: %s\n", argv[j+1], value); |
d0bfd026 JH |
61 | } |
62 | } | |
63 | return 0; | |
64 | } |