4 * Copyright (c) 2007 Junio C Hamano
10 static struct whitespace_rule
{
11 const char *rule_name
;
13 } whitespace_rule_names
[] = {
14 { "trailing-space", WS_TRAILING_SPACE
},
15 { "space-before-tab", WS_SPACE_BEFORE_TAB
},
16 { "indent-with-non-tab", WS_INDENT_WITH_NON_TAB
},
19 unsigned parse_whitespace_rule(const char *string
)
21 unsigned rule
= WS_DEFAULT_RULE
;
29 string
= string
+ strspn(string
, ", \t\n\r");
30 ep
= strchr(string
, ',');
43 for (i
= 0; i
< ARRAY_SIZE(whitespace_rule_names
); i
++) {
44 if (strncmp(whitespace_rule_names
[i
].rule_name
,
48 rule
&= ~whitespace_rule_names
[i
].rule_bits
;
50 rule
|= whitespace_rule_names
[i
].rule_bits
;
58 static void setup_whitespace_attr_check(struct git_attr_check
*check
)
60 static struct git_attr
*attr_whitespace
;
63 attr_whitespace
= git_attr("whitespace", 10);
64 check
[0].attr
= attr_whitespace
;
67 unsigned whitespace_rule(const char *pathname
)
69 struct git_attr_check attr_whitespace_rule
;
71 setup_whitespace_attr_check(&attr_whitespace_rule
);
72 if (!git_checkattr(pathname
, 1, &attr_whitespace_rule
)) {
75 value
= attr_whitespace_rule
.value
;
76 if (ATTR_TRUE(value
)) {
77 /* true (whitespace) */
78 unsigned all_rule
= 0;
80 for (i
= 0; i
< ARRAY_SIZE(whitespace_rule_names
); i
++)
81 all_rule
|= whitespace_rule_names
[i
].rule_bits
;
83 } else if (ATTR_FALSE(value
)) {
84 /* false (-whitespace) */
86 } else if (ATTR_UNSET(value
)) {
87 /* reset to default (!whitespace) */
88 return whitespace_rule_cfg
;
91 return parse_whitespace_rule(value
);
94 return whitespace_rule_cfg
;