From: J. Bruce Fields Date: Sun, 16 Sep 2007 22:49:00 +0000 (-0400) Subject: git-apply: fix whitespace stripping X-Git-Tag: v1.5.3.2~13 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=d7416ecac8508367a8ac35ab74ef09b7707d0c4b;p=git.git git-apply: fix whitespace stripping The algorithm isn't right here: it accumulates any set of 8 spaces into tabs even if they're separated by tabs, so is converted to when it should be just So teach git-apply that a tab hides any group of less than 8 previous spaces in a row. Signed-off-by: J. Bruce Fields Signed-off-by: Junio C Hamano --- diff --git a/builtin-apply.c b/builtin-apply.c index f4ecf03ed..5ad371424 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -1642,15 +1642,22 @@ static int apply_line(char *output, const char *patch, int plen) buf = output; if (need_fix_leading_space) { + int 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--) { char ch = patch[i]; - if (ch != ' ') + if (ch != ' ') { + consecutive_spaces = 0; *output++ = ch; - else if ((i % 8) == 0) - *output++ = '\t'; + } else { + consecutive_spaces++; + if (consecutive_spaces == 8) { + *output++ = '\t'; + consecutive_spaces = 0; + } + } } fixed = 1; i = last_tab_in_indent;