pack-objects: proper pack time stamping with --max-pack-size
[git/trast.git] / builtin-check-attr.c
blob6afdfa10a166a97c1115b1430221262228622c5c
1 #include "builtin.h"
2 #include "cache.h"
3 #include "attr.h"
4 #include "quote.h"
6 static const char check_attr_usage[] =
7 "git-check-attr attr... [--] pathname...";
9 int cmd_check_attr(int argc, const char **argv, const char *prefix)
11 struct git_attr_check *check;
12 int cnt, i, doubledash;
14 if (read_cache() < 0) {
15 die("invalid cache");
18 doubledash = -1;
19 for (i = 1; doubledash < 0 && i < argc; i++) {
20 if (!strcmp(argv[i], "--"))
21 doubledash = i;
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++;
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;
37 struct git_attr *a;
38 name = argv[i + 1];
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;
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++) {
50 const char *value = check[j].value;
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";
59 quote_c_style(argv[i], NULL, stdout, 0);
60 printf(": %s: %s\n", argv[j+1], value);
63 return 0;