Code

attribute macro support
[git.git] / builtin-check-attr.c
1 #include "builtin.h"
2 #include "attr.h"
3 #include "quote.h"
5 static const char check_attr_usage[] =
6 "git-check-attr attr... [--] pathname...";
8 int cmd_check_attr(int argc, const char **argv, const char *prefix)
9 {
10         struct git_attr_check *check;
11         int cnt, i, doubledash;
13         doubledash = -1;
14         for (i = 1; doubledash < 0 && i < argc; i++) {
15                 if (!strcmp(argv[i], "--"))
16                         doubledash = i;
17         }
19         /* If there is no double dash, we handle only one attribute */
20         if (doubledash < 0) {
21                 cnt = 1;
22                 doubledash = 1;
23         } else
24                 cnt = doubledash - 1;
25         doubledash++;
27         if (cnt <= 0 || argc < doubledash)
28                 usage(check_attr_usage);
29         check = xcalloc(cnt, sizeof(*check));
30         for (i = 0; i < cnt; i++) {
31                 const char *name;
32                 name = argv[i + 1];
33                 check[i].attr = git_attr(name, strlen(name));
34         }
36         for (i = doubledash; i < argc; i++) {
37                 int j;
38                 if (git_checkattr(argv[i], cnt, check))
39                         die("git_checkattr died");
40                 for (j = 0; j < cnt; j++) {
41                         write_name_quoted("", 0, argv[i], 1, stdout);
42                         printf(": %s: %s\n", argv[j+1],
43                                (check[j].isset < 0) ? "unspecified" :
44                                (check[j].isset == 0) ? "unset" :
45                                "set");
46                 }
47         }
48         return 0;
49 }