]> git.ipfire.org Git - thirdparty/git.git/blame - builtin-check-attr.c
Reuse fixup_pack_header_footer in index-pack
[thirdparty/git.git] / builtin-check-attr.c
CommitLineData
d0bfd026
JH
1#include "builtin.h"
2#include "attr.h"
3#include "quote.h"
4
5static const char check_attr_usage[] =
6"git-check-attr attr... [--] pathname...";
7
8int cmd_check_attr(int argc, const char **argv, const char *prefix)
9{
10 struct git_attr_check *check;
11 int cnt, i, doubledash;
12
13 doubledash = -1;
14 for (i = 1; doubledash < 0 && i < argc; i++) {
15 if (!strcmp(argv[i], "--"))
16 doubledash = i;
17 }
18
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++;
26
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;
e4aee10a 32 struct git_attr *a;
d0bfd026 33 name = argv[i + 1];
e4aee10a
JH
34 a = git_attr(name, strlen(name));
35 if (!a)
36 return error("%s: not a valid attribute name", name);
37 check[i].attr = a;
d0bfd026
JH
38 }
39
40 for (i = doubledash; i < argc; i++) {
41 int j;
42 if (git_checkattr(argv[i], cnt, check))
43 die("git_checkattr died");
44 for (j = 0; j < cnt; j++) {
a5e92abd 45 const char *value = check[j].value;
515106fa
JH
46
47 if (ATTR_TRUE(value))
48 value = "set";
49 else if (ATTR_FALSE(value))
50 value = "unset";
51 else if (ATTR_UNSET(value))
52 value = "unspecified";
53
d0bfd026 54 write_name_quoted("", 0, argv[i], 1, stdout);
a5e92abd 55 printf(": %s: %s\n", argv[j+1], value);
d0bfd026
JH
56 }
57 }
58 return 0;
59}