@matheusbsbs / matheus-bagliano / commits / 41038c5e15
Fork 0

check-attr: add an internal check_attr() function

This step is preparation to introducing --stdin-paths option. I have also added maybe_flush_or_die() at the end of main() to ensure that we exit with the zero code only when we flushed the output successfully. Signed-off-by: Dmitry Potapov <dpotapov@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Dmitry Potapov committed Oct 7, 2008 at 04:14 UTC 41038c5e1534a6abef21ec4cfc216d13d0ac2fb5
1 file changed +24 -18
builtin-check-attr.c
+24 -18
@@ -6,6 +6,27 @@
6 static const char check_attr_usage[] =
7 "git check-attr attr... [--] pathname...";
8
9 +static void check_attr(int cnt, struct git_attr_check *check,
10 + const char** name, const char *file)
11 +{
12 + int j;
13 + if (git_checkattr(file, cnt, check))
14 + die("git_checkattr died");
15 + for (j = 0; j < cnt; j++) {
16 + const char *value = check[j].value;
17 +
18 + if (ATTR_TRUE(value))
19 + value = "set";
20 + else if (ATTR_FALSE(value))
21 + value = "unset";
22 + else if (ATTR_UNSET(value))
23 + value = "unspecified";
24 +
25 + quote_c_style(file, NULL, stdout, 0);
26 + printf(": %s: %s\n", name[j], value);
27 + }
28 +}
29 +
30 int cmd_check_attr(int argc, const char **argv, const char *prefix)
31 {
32 struct git_attr_check *check;
@@ -42,23 +63,8 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
63 check[i].attr = a;
64 }
65
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;
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 -
59 - quote_c_style(argv[i], NULL, stdout, 0);
60 - printf(": %s: %s\n", argv[j+1], value);
61 - }
62 - }
66 + for (i = doubledash; i < argc; i++)
67 + check_attr(cnt, check, argv+1, argv[i]);
68 + maybe_flush_or_die(stdout, "attribute to stdout");
69 return 0;
70 }