convert.c: correct attr_action()

df747b81 (convert.c: refactor crlf_action, 2016-02-10) introduced a bug to "git ls-files --eol". The "text" attribute was shown as "text eol=lf" or "text eol=crlf", depending on core.autocrlf or core.eol. Correct this and add test cases in t0027. Signed-off-by: Torsten Bögershausen <tboegi@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Torsten Bögershausen committed Feb 23, 2016 at 18:07 UTC 817a0c7968c1d7e0f574b6d07451445832f781aa
2 files changed +35 -16
convert.c
+9 -9
@@ -708,7 +708,7 @@ static enum crlf_action git_path_check_crlf(struct git_attr_check *check)
708 const char *value = check->value;
709
710 if (ATTR_TRUE(value))
711 - return text_eol_is_crlf() ? CRLF_TEXT_CRLF : CRLF_TEXT_INPUT;
711 + return CRLF_TEXT;
712 else if (ATTR_FALSE(value))
713 return CRLF_BINARY;
714 else if (ATTR_UNSET(value))
@@ -778,20 +778,20 @@ static void convert_attrs(struct conv_attrs *ca, const char *path)
778 }
779
780 if (!git_check_attr(path, NUM_CONV_ATTRS, ccheck)) {
781 - enum eol eol_attr;
781 ca->crlf_action = git_path_check_crlf(ccheck + 4);
782 if (ca->crlf_action == CRLF_UNDEFINED)
783 ca->crlf_action = git_path_check_crlf(ccheck + 0);
784 ca->attr_action = ca->crlf_action;
785 ca->ident = git_path_check_ident(ccheck + 1);
786 ca->drv = git_path_check_convert(ccheck + 2);
788 - if (ca->crlf_action == CRLF_BINARY)
789 - return;
790 - eol_attr = git_path_check_eol(ccheck + 3);
791 - if (eol_attr == EOL_LF)
792 - ca->crlf_action = CRLF_TEXT_INPUT;
793 - else if (eol_attr == EOL_CRLF)
794 - ca->crlf_action = CRLF_TEXT_CRLF;
787 + if (ca->crlf_action != CRLF_BINARY) {
788 + enum eol eol_attr = git_path_check_eol(ccheck + 3);
789 + if (eol_attr == EOL_LF)
790 + ca->crlf_action = CRLF_TEXT_INPUT;
791 + else if (eol_attr == EOL_CRLF)
792 + ca->crlf_action = CRLF_TEXT_CRLF;
793 + }
794 + ca->attr_action = ca->crlf_action;
795 } else {
796 ca->drv = NULL;
797 ca->crlf_action = CRLF_UNDEFINED;
t/t0027-auto-crlf.sh
+26 -7
@@ -159,6 +159,25 @@ stats_ascii () {
159
160 }
161
162 +
163 +# contruct the attr/ returned by git ls-files --eol
164 +# Take none (=empty), one or two args
165 +attr_ascii () {
166 + case $1,$2 in
167 + -text,*) echo "-text" ;;
168 + text,) echo "text" ;;
169 + text,lf) echo "text eol=lf" ;;
170 + text,crlf) echo "text eol=crlf" ;;
171 + auto,) echo "text=auto" ;;
172 + auto,lf) echo "text=auto eol=lf" ;;
173 + auto,crlf) echo "text=auto eol=crlf" ;;
174 + lf,) echo "text eol=lf" ;;
175 + crlf,) echo "text eol=crlf" ;;
176 + ,) echo "" ;;
177 + *) echo invalid_attr "$1,$2" ;;
178 + esac
179 +}
180 +
181 check_files_in_repo () {
182 crlf=$1
183 attr=$2
@@ -228,15 +247,15 @@ checkout_files () {
247 test_expect_success "ls-files --eol attr=$attr $ident $aeol core.autocrlf=$crlf core.eol=$ceol" '
248 test_when_finished "rm expect actual" &&
249 sort <<-EOF >expect &&
231 - i/crlf w/$(stats_ascii $crlfname) crlf_false_attr__CRLF.txt
232 - i/mixed w/$(stats_ascii $lfmixcrlf) crlf_false_attr__CRLF_mix_LF.txt
233 - i/lf w/$(stats_ascii $lfname) crlf_false_attr__LF.txt
234 - i/-text w/$(stats_ascii $lfmixcr) crlf_false_attr__LF_mix_CR.txt
235 - i/-text w/$(stats_ascii $crlfnul) crlf_false_attr__CRLF_nul.txt
236 - i/-text w/$(stats_ascii $crlfnul) crlf_false_attr__LF_nul.txt
250 + i/crlf w/$(stats_ascii $crlfname) attr/$(attr_ascii $attr $aeol) crlf_false_attr__CRLF.txt
251 + i/mixed w/$(stats_ascii $lfmixcrlf) attr/$(attr_ascii $attr $aeol) crlf_false_attr__CRLF_mix_LF.txt
252 + i/lf w/$(stats_ascii $lfname) attr/$(attr_ascii $attr $aeol) crlf_false_attr__LF.txt
253 + i/-text w/$(stats_ascii $lfmixcr) attr/$(attr_ascii $attr $aeol) crlf_false_attr__LF_mix_CR.txt
254 + i/-text w/$(stats_ascii $crlfnul) attr/$(attr_ascii $attr $aeol) crlf_false_attr__CRLF_nul.txt
255 + i/-text w/$(stats_ascii $crlfnul) attr/$(attr_ascii $attr $aeol) crlf_false_attr__LF_nul.txt
256 EOF
257 git ls-files --eol crlf_false_attr__* |
239 - sed -e "s!attr/[^ ]*!!g" -e "s/ / /g" -e "s/ */ /g" |
258 + sed -e "s/ / /g" -e "s/ */ /g" |
259 sort >actual &&
260 test_cmp expect actual
261 '