Skip to content

Commit

Permalink
git-apply: fix whitespace stripping
Browse files Browse the repository at this point in the history
The algorithm isn't right here: it accumulates any set of 8 spaces into
tabs even if they're separated by tabs, so

	<four spaces><tab><four spaces><tab>

is converted to

	<tab><tab><tab>

when it should be just

	<tab><tab>

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 <bfields@citi.umich.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
J. Bruce Fields authored and Junio C Hamano committed Sep 17, 2007
1 parent ece7b74 commit d7416ec
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions builtin-apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d7416ec

Please sign in to comment.