Skip to content

Commit 817a0c7

Browse files
tboegigitster
authored andcommitted
convert.c: correct attr_action()
df747b8 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6e336a5 commit 817a0c7

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

convert.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ static enum crlf_action git_path_check_crlf(struct git_attr_check *check)
708708
const char *value = check->value;
709709

710710
if (ATTR_TRUE(value))
711-
return text_eol_is_crlf() ? CRLF_TEXT_CRLF : CRLF_TEXT_INPUT;
711+
return CRLF_TEXT;
712712
else if (ATTR_FALSE(value))
713713
return CRLF_BINARY;
714714
else if (ATTR_UNSET(value))
@@ -778,20 +778,20 @@ static void convert_attrs(struct conv_attrs *ca, const char *path)
778778
}
779779

780780
if (!git_check_attr(path, NUM_CONV_ATTRS, ccheck)) {
781-
enum eol eol_attr;
782781
ca->crlf_action = git_path_check_crlf(ccheck + 4);
783782
if (ca->crlf_action == CRLF_UNDEFINED)
784783
ca->crlf_action = git_path_check_crlf(ccheck + 0);
785784
ca->attr_action = ca->crlf_action;
786785
ca->ident = git_path_check_ident(ccheck + 1);
787786
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;
795795
} else {
796796
ca->drv = NULL;
797797
ca->crlf_action = CRLF_UNDEFINED;

t/t0027-auto-crlf.sh

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,25 @@ stats_ascii () {
159159

160160
}
161161

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+
162181
check_files_in_repo () {
163182
crlf=$1
164183
attr=$2
@@ -228,15 +247,15 @@ checkout_files () {
228247
test_expect_success "ls-files --eol attr=$attr $ident $aeol core.autocrlf=$crlf core.eol=$ceol" '
229248
test_when_finished "rm expect actual" &&
230249
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
237256
EOF
238257
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" |
240259
sort >actual &&
241260
test_cmp expect actual
242261
'

0 commit comments

Comments
 (0)