X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=ws.c;h=b498d7599d5ac09c2688ee829b29aa36a866ac9c;hb=d3f2475c01d9e90dbadacbe2c35854f6d11e6409;hp=7302f8f5a2cd450771aefcba0a385a90121ba0cf;hpb=eb4e67288bb9d66fb46092fa30d72c4bdded0c2a;p=git.git diff --git a/ws.c b/ws.c index 7302f8f5a..b498d7599 100644 --- a/ws.c +++ b/ws.c @@ -56,6 +56,16 @@ unsigned parse_whitespace_rule(const char *string) rule |= whitespace_rule_names[i].rule_bits; break; } + if (strncmp(string, "tabwidth=", 9) == 0) { + unsigned tabwidth = atoi(string + 9); + if (0 < tabwidth && tabwidth < 0100) { + rule &= ~WS_TAB_WIDTH_MASK; + rule |= tabwidth; + } + else + warning("tabwidth %.*s out of range", + (int)(len - 9), string + 9); + } string = ep; } @@ -78,13 +88,13 @@ unsigned whitespace_rule(const char *pathname) struct git_attr_check attr_whitespace_rule; setup_whitespace_attr_check(&attr_whitespace_rule); - if (!git_checkattr(pathname, 1, &attr_whitespace_rule)) { + if (!git_check_attr(pathname, 1, &attr_whitespace_rule)) { const char *value; value = attr_whitespace_rule.value; if (ATTR_TRUE(value)) { /* true (whitespace) */ - unsigned all_rule = 0; + unsigned all_rule = ws_tab_width(whitespace_rule_cfg); int i; for (i = 0; i < ARRAY_SIZE(whitespace_rule_names); i++) if (!whitespace_rule_names[i].loosens_error && @@ -93,7 +103,7 @@ unsigned whitespace_rule(const char *pathname) return all_rule; } else if (ATTR_FALSE(value)) { /* false (-whitespace) */ - return 0; + return ws_tab_width(whitespace_rule_cfg); } else if (ATTR_UNSET(value)) { /* reset to default (!whitespace) */ return whitespace_rule_cfg; @@ -206,7 +216,7 @@ static unsigned ws_check_emit_1(const char *line, int len, unsigned ws_rule, } /* Check for indent using non-tab. */ - if ((ws_rule & WS_INDENT_WITH_NON_TAB) && i - written >= 8) { + if ((ws_rule & WS_INDENT_WITH_NON_TAB) && i - written >= ws_tab_width(ws_rule)) { result |= WS_INDENT_WITH_NON_TAB; if (stream) { fputs(ws, stream); @@ -320,7 +330,7 @@ void ws_fix_copy(struct strbuf *dst, const char *src, int len, unsigned ws_rule, } else if (ch == ' ') { last_space_in_indent = i; if ((ws_rule & WS_INDENT_WITH_NON_TAB) && - 8 <= i - last_tab_in_indent) + ws_tab_width(ws_rule) <= i - last_tab_in_indent) need_fix_leading_space = 1; } else break; @@ -350,7 +360,7 @@ void ws_fix_copy(struct strbuf *dst, const char *src, int len, unsigned ws_rule, strbuf_addch(dst, ch); } else { consecutive_spaces++; - if (consecutive_spaces == 8) { + if (consecutive_spaces == ws_tab_width(ws_rule)) { strbuf_addch(dst, '\t'); consecutive_spaces = 0; } @@ -363,12 +373,13 @@ void ws_fix_copy(struct strbuf *dst, const char *src, int len, unsigned ws_rule, fixed = 1; } else if ((ws_rule & WS_TAB_IN_INDENT) && last_tab_in_indent >= 0) { /* Expand tabs into spaces */ + int start = dst->len; int last = last_tab_in_indent + 1; for (i = 0; i < last; i++) { if (src[i] == '\t') do { strbuf_addch(dst, ' '); - } while (dst->len % 8); + } while ((dst->len - start) % ws_tab_width(ws_rule)); else strbuf_addch(dst, src[i]); }