From: Junio C Hamano Date: Wed, 1 Dec 2010 22:42:00 +0000 (-0800) Subject: Merge branch 'js/maint-apply-tab-in-indent-fix' into HEAD X-Git-Tag: v1.7.4-rc0~52^2~1 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/dee40e5178bab78aaf655ee4323f3141acd17654?ds=inline;hp=-c Merge branch 'js/maint-apply-tab-in-indent-fix' into HEAD * js/maint-apply-tab-in-indent-fix: apply --whitespace=fix: fix tab-in-indent --- dee40e5178bab78aaf655ee4323f3141acd17654 diff --combined t/t4124-apply-ws-rule.sh index 61bfc569c3,aea052346e..40e5842997 --- a/t/t4124-apply-ws-rule.sh +++ b/t/t4124-apply-ws-rule.sh @@@ -44,7 -44,7 +44,7 @@@ test_fix () apply_patch --whitespace=fix || return 1 # find touched lines - diff file target | sed -n -e "s/^> //p" >fixed + $DIFF file target | sed -n -e "s/^> //p" >fixed # the changed lines are all expeced to change fixed_cnt=$(wc -l .gitattributes && apply_patch --whitespace=error-all && - diff file target + test_cmp file target ' + test_expect_success 'spaces inserted by tab-in-indent' ' + + git config core.whitespace -trailing,-space,-indent,tab && + rm -f .gitattributes && + test_fix % && + sed -e "s/_/ /g" -e "s/>/ /" <<-\EOF >expect && + An_SP in an ordinary line>and a HT. + ________A HT (%). + ________A SP and a HT (@%). + _________A SP, a HT and a SP (@%). + _______Seven SP. + ________Eight SP (#). + ________Seven SP and a HT (@%). + ________________Eight SP and a HT (@#%). + _________Seven SP, a HT and a SP (@%). + _________________Eight SP, a HT and a SP (@#%). + _______________Fifteen SP (#). + ________________Fifteen SP and a HT (@#%). + ________________Sixteen SP (#). + ________________________Sixteen SP and a HT (@#%). + _____a__Five SP, a non WS, two SP. + A line with a (!) trailing SP_ + A line with a (!) trailing HT> + EOF + test_cmp expect target + + ' + for t in - '' do case "$t" in '') tt='!' ;; *) tt= ;; esac @@@ -176,8 -204,9 +204,8 @@@ test_expect_success 'trailing whitespac ' test_expect_success 'blank at EOF with --whitespace=fix (1)' ' - : these can fail depending on what we did before - git config --unset core.whitespace - rm -f .gitattributes + test_might_fail git config --unset core.whitespace && + rm -f .gitattributes && { echo a; echo b; echo c; } >one && git add one && @@@ -329,18 -358,6 +357,18 @@@ test_expect_success 'two missing blank test_cmp one expect ' +test_expect_success 'missing blank line at end, insert before end, --whitespace=fix' ' + { echo a; echo; } >one && + git add one && + { echo b; echo a; echo; } >one && + cp one expect && + git diff -- one >patch && + echo a >one && + test_must_fail git apply patch && + git apply --whitespace=fix patch && + test_cmp one expect +' + test_expect_success 'shrink file with tons of missing blanks at end of file' ' { echo a; echo b; echo c; } >one && cp one no-blank-lines && @@@ -367,7 -384,7 +395,7 @@@ test_expect_success 'missing blanks at git diff -- one >patch && echo a >one && - test_must_fail git apply patch + test_must_fail git apply patch && test_must_fail git apply --whitespace=fix patch && test_must_fail git apply --ignore-space-change --whitespace=fix patch ' @@@ -418,7 -435,7 +446,7 @@@ test_expect_success 'same, but with CR- printf "b\r\n" >>one && printf "c\r\n" >>one && cp one save-one && - printf " \r\n" >>one + printf " \r\n" >>one && git add one && printf "d\r\n" >>one && cp one expect && @@@ -435,7 -452,7 +463,7 @@@ test_expect_success 'same, but with CR- printf "b\r\n" >>one && printf "c\r\n" >>one && cp one save-one && - printf " \r\n" >>one + printf " \r\n" >>one && git add one && cp one expect && printf "d\r\n" >>one && diff --combined ws.c index 7302f8f5a2,b282e8c100..e3504360da --- a/ws.c +++ b/ws.c @@@ -174,11 -174,8 +174,11 @@@ static unsigned ws_check_emit_1(const c } } + if (trailing_whitespace == -1) + trailing_whitespace = len; + /* Check indentation */ - for (i = 0; i < len; i++) { + for (i = 0; i < trailing_whitespace; i++) { if (line[i] == ' ') continue; if (line[i] != '\t') @@@ -221,6 -218,8 +221,6 @@@ * Now the rest of the line starts at "written". * The non-highlighted part ends at "trailing_whitespace". */ - if (trailing_whitespace == -1) - trailing_whitespace = len; /* Emit non-highlighted (middle) segment. */ if (trailing_whitespace - written > 0) { @@@ -363,12 -362,13 +363,13 @@@ void ws_fix_copy(struct strbuf *dst, co 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) % 8); else strbuf_addch(dst, src[i]); }