@matheusbsbs / matheus-bagliano / commits / d7416ecac8
Fork 0

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 <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>

J. Bruce Fields committed Sep 16, 2007 at 18:49 UTC d7416ecac8508367a8ac35ab74ef09b7707d0c4b
1 file changed +10 -3
builtin-apply.c
+10 -3
@@ -1642,15 +1642,22 @@ static int apply_line(char *output, const char *patch, int plen)
1642
1643 buf = output;
1644 if (need_fix_leading_space) {
1645 + int consecutive_spaces = 0;
1646 /* between patch[1..last_tab_in_indent] strip the
1647 * funny spaces, updating them to tab as needed.
1648 */
1649 for (i = 1; i < last_tab_in_indent; i++, plen--) {
1650 char ch = patch[i];
1650 - if (ch != ' ')
1651 + if (ch != ' ') {
1652 + consecutive_spaces = 0;
1653 *output++ = ch;
1652 - else if ((i % 8) == 0)
1653 - *output++ = '\t';
1654 + } else {
1655 + consecutive_spaces++;
1656 + if (consecutive_spaces == 8) {
1657 + *output++ = '\t';
1658 + consecutive_spaces = 0;
1659 + }
1660 + }
1661 }
1662 fixed = 1;
1663 i = last_tab_in_indent;