Skip to content

Commit db396cd

Browse files
matheustavaresgitster
authored andcommitted
parallel-checkout: add tests related to .gitattributes
Add tests to confirm that `struct conv_attrs` data is correctly passed from the main process to the workers, and that they properly smudge files before writing to the working tree. Also check that non-parallel-eligible entries, such as regular files that require external filters, are correctly smudge and written when parallel-checkout is enabled. Note: to avoid repeating code, some helper functions are extracted from t0028 into a common lib file. Original-patch-by: Jeff Hostetler <[email protected]> Signed-off-by: Jeff Hostetler <[email protected]> Signed-off-by: Matheus Tavares <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 625e380 commit db396cd

File tree

3 files changed

+200
-24
lines changed

3 files changed

+200
-24
lines changed

t/lib-encoding.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Encoding helpers used by t0028 and t2082
2+
3+
test_lazy_prereq NO_UTF16_BOM '
4+
test $(printf abc | iconv -f UTF-8 -t UTF-16 | wc -c) = 6
5+
'
6+
7+
test_lazy_prereq NO_UTF32_BOM '
8+
test $(printf abc | iconv -f UTF-8 -t UTF-32 | wc -c) = 12
9+
'
10+
11+
write_utf16 () {
12+
if test_have_prereq NO_UTF16_BOM
13+
then
14+
printf '\376\377'
15+
fi &&
16+
iconv -f UTF-8 -t UTF-16
17+
}
18+
19+
write_utf32 () {
20+
if test_have_prereq NO_UTF32_BOM
21+
then
22+
printf '\0\0\376\377'
23+
fi &&
24+
iconv -f UTF-8 -t UTF-32
25+
}

t/t0028-working-tree-encoding.sh

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,10 @@
33
test_description='working-tree-encoding conversion via gitattributes'
44

55
. ./test-lib.sh
6+
. "$TEST_DIRECTORY/lib-encoding.sh"
67

78
GIT_TRACE_WORKING_TREE_ENCODING=1 && export GIT_TRACE_WORKING_TREE_ENCODING
89

9-
test_lazy_prereq NO_UTF16_BOM '
10-
test $(printf abc | iconv -f UTF-8 -t UTF-16 | wc -c) = 6
11-
'
12-
13-
test_lazy_prereq NO_UTF32_BOM '
14-
test $(printf abc | iconv -f UTF-8 -t UTF-32 | wc -c) = 12
15-
'
16-
17-
write_utf16 () {
18-
if test_have_prereq NO_UTF16_BOM
19-
then
20-
printf '\376\377'
21-
fi &&
22-
iconv -f UTF-8 -t UTF-16
23-
}
24-
25-
write_utf32 () {
26-
if test_have_prereq NO_UTF32_BOM
27-
then
28-
printf '\0\0\376\377'
29-
fi &&
30-
iconv -f UTF-8 -t UTF-32
31-
}
32-
3310
test_expect_success 'setup test files' '
3411
git config core.eol lf &&
3512
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
#!/bin/sh
2+
3+
test_description='parallel-checkout: attributes
4+
5+
Verify that parallel-checkout correctly creates files that require
6+
conversions, as specified in .gitattributes. The main point here is
7+
to check that the conv_attr data is correctly sent to the workers
8+
and that it contains sufficient information to smudge files
9+
properly (without access to the index or attribute stack).
10+
'
11+
12+
TEST_NO_CREATE_REPO=1
13+
. ./test-lib.sh
14+
. "$TEST_DIRECTORY/lib-parallel-checkout.sh"
15+
. "$TEST_DIRECTORY/lib-encoding.sh"
16+
17+
test_expect_success 'parallel-checkout with ident' '
18+
git init ident &&
19+
(
20+
cd ident &&
21+
echo "A ident" >.gitattributes &&
22+
echo "\$Id\$" >A &&
23+
echo "\$Id\$" >B &&
24+
git add -A &&
25+
git commit -m id &&
26+
27+
rm A B &&
28+
git_pc 2 0 2 reset --hard &&
29+
hexsz=$(test_oid hexsz) &&
30+
grep -E "\\\$Id: [0-9a-f]{$hexsz} \\\$" A &&
31+
grep "\\\$Id\\\$" B
32+
)
33+
'
34+
35+
test_expect_success 'parallel-checkout with re-encoding' '
36+
git init encoding &&
37+
(
38+
cd encoding &&
39+
echo text >utf8-text &&
40+
cat utf8-text | write_utf16 >utf16-text &&
41+
42+
echo "A working-tree-encoding=UTF-16" >.gitattributes &&
43+
cp utf16-text A &&
44+
cp utf16-text B &&
45+
git add A B .gitattributes &&
46+
git commit -m encoding &&
47+
48+
# Check that A (and only A) is stored in UTF-8
49+
git cat-file -p :A >A.internal &&
50+
test_cmp_bin utf8-text A.internal &&
51+
git cat-file -p :B >B.internal &&
52+
test_cmp_bin utf16-text B.internal &&
53+
54+
# Check that A is re-encoded during checkout
55+
rm A B &&
56+
git_pc 2 0 2 checkout A B &&
57+
test_cmp_bin utf16-text A
58+
)
59+
'
60+
61+
test_expect_success 'parallel-checkout with eol conversions' '
62+
git init eol &&
63+
(
64+
cd eol &&
65+
git config core.autocrlf false &&
66+
printf "multi\r\nline\r\ntext" >crlf-text &&
67+
printf "multi\nline\ntext" >lf-text &&
68+
69+
echo "A text eol=crlf" >.gitattributes &&
70+
echo "B -text" >>.gitattributes &&
71+
cp crlf-text A &&
72+
cp crlf-text B &&
73+
git add A B .gitattributes &&
74+
git commit -m eol &&
75+
76+
# Check that A (and only A) is stored with LF format
77+
git cat-file -p :A >A.internal &&
78+
test_cmp_bin lf-text A.internal &&
79+
git cat-file -p :B >B.internal &&
80+
test_cmp_bin crlf-text B.internal &&
81+
82+
# Check that A is converted to CRLF during checkout
83+
rm A B &&
84+
git_pc 2 0 2 checkout A B &&
85+
test_cmp_bin crlf-text A
86+
)
87+
'
88+
89+
test_cmp_str()
90+
{
91+
echo "$1" >tmp &&
92+
test_cmp tmp "$2"
93+
}
94+
95+
# Entries that require an external filter are not eligible for parallel
96+
# checkout. Check that both the parallel-eligible and non-eligible entries are
97+
# properly writen in a single checkout process.
98+
#
99+
test_expect_success 'parallel-checkout and external filter' '
100+
git init filter &&
101+
(
102+
cd filter &&
103+
git config filter.x2y.clean "tr x y" &&
104+
git config filter.x2y.smudge "tr y x" &&
105+
git config filter.x2y.required true &&
106+
107+
echo "A filter=x2y" >.gitattributes &&
108+
echo x >A &&
109+
echo x >B &&
110+
echo x >C &&
111+
git add -A &&
112+
git commit -m filter &&
113+
114+
# Check that A (and only A) was cleaned
115+
git cat-file -p :A >A.internal &&
116+
test_cmp_str y A.internal &&
117+
git cat-file -p :B >B.internal &&
118+
test_cmp_str x B.internal &&
119+
git cat-file -p :C >C.internal &&
120+
test_cmp_str x C.internal &&
121+
122+
rm A B C *.internal &&
123+
git_pc 2 0 2 checkout A B C &&
124+
test_cmp_str x A &&
125+
test_cmp_str x B &&
126+
test_cmp_str x C
127+
)
128+
'
129+
130+
# The delayed queue is independent from the parallel queue, and they should be
131+
# able to work together in the same checkout process.
132+
#
133+
test_expect_success PERL 'parallel-checkout and delayed checkout' '
134+
write_script rot13-filter.pl "$PERL_PATH" \
135+
<"$TEST_DIRECTORY"/t0021/rot13-filter.pl &&
136+
test_config_global filter.delay.process \
137+
"\"$(pwd)/rot13-filter.pl\" \"$(pwd)/delayed.log\" clean smudge delay" &&
138+
test_config_global filter.delay.required true &&
139+
140+
echo "a b c" >delay-content &&
141+
echo "n o p" >delay-rot13-content &&
142+
143+
git init delayed &&
144+
(
145+
cd delayed &&
146+
echo "*.a filter=delay" >.gitattributes &&
147+
cp ../delay-content test-delay10.a &&
148+
cp ../delay-content test-delay11.a &&
149+
echo parallel >parallel1.b &&
150+
echo parallel >parallel2.b &&
151+
git add -A &&
152+
git commit -m delayed &&
153+
154+
# Check that the stored data was cleaned
155+
git cat-file -p :test-delay10.a > delay10.internal &&
156+
test_cmp delay10.internal ../delay-rot13-content &&
157+
git cat-file -p :test-delay11.a > delay11.internal &&
158+
test_cmp delay11.internal ../delay-rot13-content &&
159+
rm *.internal &&
160+
161+
rm *.a *.b
162+
) &&
163+
164+
git_pc 2 0 2 -C delayed checkout -f &&
165+
verify_checkout delayed &&
166+
167+
# Check that the *.a files got to the delay queue and were filtered
168+
grep "smudge test-delay10.a .* \[DELAYED\]" delayed.log &&
169+
grep "smudge test-delay11.a .* \[DELAYED\]" delayed.log &&
170+
test_cmp delayed/test-delay10.a delay-content &&
171+
test_cmp delayed/test-delay11.a delay-content
172+
'
173+
174+
test_done

0 commit comments

Comments
 (0)