Complain if we find 8 spaces or more in a row as part of the initial whitespace on a line, and (with --whitespace=stripspace) replace such by a tab. Well, linux's checkpatch.pl complains about this sort of thing. Signed-off-by: J. Bruce Fields <bfields@xxxxxxxxxxxxxx> --- builtin-apply.c | 34 +++++++++++++++++++++++++++------- 1 files changed, 27 insertions(+), 7 deletions(-) diff --git a/builtin-apply.c b/builtin-apply.c index 70359c1..fb63089 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -918,6 +918,7 @@ static void check_whitespace(const char *line, int len) { const char *err = "Adds trailing whitespace"; int seen_space = 0; + int consecutive_spaces = 0; int i; /* @@ -944,6 +945,18 @@ static void check_whitespace(const char *line, int len) else break; } + + err = "Initial indent contains eight or more spaces in a row"; + for (i = 1; i < len; i++) { + if (line[i] == ' ') + consecutive_spaces++; + else if (line[i] == '\t') + consecutive_spaces = 0; + else + break; + if (consecutive_spaces == 8) + goto error; + } return; error: @@ -1607,9 +1620,10 @@ static int apply_line(char *output, const char *patch, int plen) int i; int add_nl_to_tail = 0; int fixed = 0; - int last_tab_in_indent = -1; + int after_indent = -1; int last_space_in_indent = -1; int need_fix_leading_space = 0; + int consecutive_spaces = 0; char *buf; if ((new_whitespace != strip_whitespace) || !whitespace_error || @@ -1630,23 +1644,27 @@ static int apply_line(char *output, const char *patch, int plen) for (i = 1; i < plen; i++) { char ch = patch[i]; if (ch == '\t') { - last_tab_in_indent = i; + consecutive_spaces = 0; if (0 <= last_space_in_indent) need_fix_leading_space = 1; } - else if (ch == ' ') + else if (ch == ' ') { + consecutive_spaces++; last_space_in_indent = i; - else + } else break; + if (consecutive_spaces == 8) + need_fix_leading_space = 1; } + after_indent=i; buf = output; if (need_fix_leading_space) { - int consecutive_spaces = 0; + consecutive_spaces = 0; /* between patch[1..last_tab_in_indent] strip the * funny spaces, updating them to tab as needed. */ - for (i = 1; i < last_tab_in_indent; i++, plen--) { + for (i = 1; i < after_indent; i++, plen--) { char ch = patch[i]; if (ch != ' ') { consecutive_spaces = 0; @@ -1660,7 +1678,9 @@ static int apply_line(char *output, const char *patch, int plen) } } fixed = 1; - i = last_tab_in_indent; + i = after_indent; + i -= consecutive_spaces; + plen += consecutive_spaces; } else i = 1; -- 1.5.3.1.42.gfe5df - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html