]>
Commit | Line | Data |
---|---|---|
f7b5ff60 TK |
1 | #!/bin/sh |
2 | ||
3 | test_description='git p4 metadata encoding | |
4 | ||
5 | This test checks that the import process handles inconsistent text | |
6 | encoding in p4 metadata (author names, commit messages, etc) without | |
7 | failing, and produces maximally sane output in git.' | |
8 | ||
9 | . ./lib-git-p4.sh | |
10 | ||
11 | python_target_version='3' | |
12 | ||
13 | ############################### | |
14 | ## SECTION REPEATED IN t9835 ## | |
15 | ############################### | |
16 | ||
17 | # Please note: this test calls "git-p4.py" rather than "git-p4", because the | |
18 | # latter references a specific path so we can't easily force it to run under | |
19 | # the python version we need to. | |
20 | ||
21 | python_major_version=$(python -V 2>&1 | cut -c 8) | |
22 | python_target_binary=$(which python$python_target_version) | |
23 | if ! test "$python_major_version" = "$python_target_version" && test "$python_target_binary" | |
24 | then | |
25 | mkdir temp_python | |
26 | PATH="$(pwd)/temp_python:$PATH" && export PATH | |
27 | ln -s $python_target_binary temp_python/python | |
28 | fi | |
29 | ||
30 | python_major_version=$(python -V 2>&1 | cut -c 8) | |
31 | if ! test "$python_major_version" = "$python_target_version" | |
32 | then | |
33 | skip_all="skipping python$python_target_version-specific git p4 tests; python$python_target_version not available" | |
34 | test_done | |
35 | fi | |
36 | ||
37 | remove_user_cache () { | |
38 | rm "$HOME/.gitp4-usercache.txt" || true | |
39 | } | |
40 | ||
41 | test_expect_success 'start p4d' ' | |
42 | start_p4d | |
43 | ' | |
44 | ||
45 | test_expect_success 'init depot' ' | |
46 | ( | |
47 | cd "$cli" && | |
48 | ||
49 | p4_add_user "utf8_author" "ǣuthor" && | |
50 | P4USER=utf8_author && | |
51 | touch file1 && | |
52 | p4 add file1 && | |
53 | p4 submit -d "first CL has some utf-8 tǣxt" && | |
54 | ||
55 | p4_add_user "latin1_author" "$(echo æuthor | | |
56 | iconv -f utf8 -t latin1)" && | |
57 | P4USER=latin1_author && | |
58 | touch file2 && | |
59 | p4 add file2 && | |
60 | p4 submit -d "$(echo second CL has some latin-1 tæxt | | |
61 | iconv -f utf8 -t latin1)" && | |
62 | ||
63 | p4_add_user "cp1252_author" "$(echo æuthœr | | |
64 | iconv -f utf8 -t cp1252)" && | |
65 | P4USER=cp1252_author && | |
66 | touch file3 && | |
67 | p4 add file3 && | |
68 | p4 submit -d "$(echo third CL has sœme cp-1252 tæxt | | |
69 | iconv -f utf8 -t cp1252)" && | |
70 | ||
71 | p4_add_user "cp850_author" "$(echo Åuthor | | |
72 | iconv -f utf8 -t cp850)" && | |
73 | P4USER=cp850_author && | |
74 | touch file4 && | |
75 | p4 add file4 && | |
76 | p4 submit -d "$(echo fourth CL hÅs some cp850 text | | |
77 | iconv -f utf8 -t cp850)" | |
78 | ) | |
79 | ' | |
80 | ||
81 | test_expect_success 'clone non-utf8 repo with strict encoding' ' | |
82 | test_when_finished cleanup_git && | |
83 | test_when_finished remove_user_cache && | |
84 | test_must_fail git -c git-p4.metadataDecodingStrategy=strict p4.py clone --dest="$git" //depot@all 2>err && | |
85 | grep "Decoding perforce metadata failed!" err | |
86 | ' | |
87 | ||
88 | test_expect_success 'check utf-8 contents with passthrough strategy' ' | |
89 | test_when_finished cleanup_git && | |
90 | test_when_finished remove_user_cache && | |
91 | git -c git-p4.metadataDecodingStrategy=passthrough p4.py clone --dest="$git" //depot@all && | |
92 | ( | |
93 | cd "$git" && | |
94 | git log >actual && | |
95 | grep "some utf-8 tǣxt" actual && | |
96 | grep "ǣuthor" actual | |
97 | ) | |
98 | ' | |
99 | ||
100 | test_expect_success 'check latin-1 contents corrupted in git with passthrough strategy' ' | |
101 | test_when_finished cleanup_git && | |
102 | test_when_finished remove_user_cache && | |
103 | git -c git-p4.metadataDecodingStrategy=passthrough p4.py clone --dest="$git" //depot@all && | |
104 | ( | |
105 | cd "$git" && | |
106 | git log >actual && | |
107 | badly_encoded_in_git=$(echo "some latin-1 tæxt" | iconv -f utf8 -t latin1) && | |
108 | grep "$badly_encoded_in_git" actual && | |
109 | bad_author_in_git="$(echo æuthor | iconv -f utf8 -t latin1)" && | |
110 | grep "$bad_author_in_git" actual | |
111 | ) | |
112 | ' | |
113 | ||
114 | test_expect_success 'check utf-8 contents with fallback strategy' ' | |
115 | test_when_finished cleanup_git && | |
116 | test_when_finished remove_user_cache && | |
117 | git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all && | |
118 | ( | |
119 | cd "$git" && | |
120 | git log >actual && | |
121 | grep "some utf-8 tǣxt" actual && | |
122 | grep "ǣuthor" actual | |
123 | ) | |
124 | ' | |
125 | ||
126 | test_expect_success 'check latin-1 contents with fallback strategy' ' | |
127 | test_when_finished cleanup_git && | |
128 | test_when_finished remove_user_cache && | |
129 | git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all && | |
130 | ( | |
131 | cd "$git" && | |
132 | git log >actual && | |
133 | grep "some latin-1 tæxt" actual && | |
134 | grep "æuthor" actual | |
135 | ) | |
136 | ' | |
137 | ||
138 | test_expect_success 'check cp-1252 contents with fallback strategy' ' | |
139 | test_when_finished cleanup_git && | |
140 | test_when_finished remove_user_cache && | |
141 | git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all && | |
142 | ( | |
143 | cd "$git" && | |
144 | git log >actual && | |
145 | grep "sœme cp-1252 tæxt" actual && | |
146 | grep "æuthœr" actual | |
147 | ) | |
148 | ' | |
149 | ||
150 | test_expect_success 'check cp850 contents parsed with correct fallback' ' | |
151 | test_when_finished cleanup_git && | |
152 | test_when_finished remove_user_cache && | |
153 | git -c git-p4.metadataDecodingStrategy=fallback -c git-p4.metadataFallbackEncoding=cp850 p4.py clone --dest="$git" //depot@all && | |
154 | ( | |
155 | cd "$git" && | |
156 | git log >actual && | |
157 | grep "hÅs some cp850 text" actual && | |
158 | grep "Åuthor" actual | |
159 | ) | |
160 | ' | |
161 | ||
162 | test_expect_success 'check cp850-only contents escaped when cp1252 is fallback' ' | |
163 | test_when_finished cleanup_git && | |
164 | test_when_finished remove_user_cache && | |
165 | git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all && | |
166 | ( | |
167 | cd "$git" && | |
168 | git log >actual && | |
169 | grep "h%8Fs some cp850 text" actual && | |
170 | grep "%8Futhor" actual | |
171 | ) | |
172 | ' | |
173 | ||
174 | test_expect_success 'check cp-1252 contents on later sync after clone with fallback strategy' ' | |
175 | test_when_finished cleanup_git && | |
176 | test_when_finished remove_user_cache && | |
177 | git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all && | |
178 | ( | |
179 | cd "$cli" && | |
180 | P4USER=cp1252_author && | |
181 | touch file10 && | |
182 | p4 add file10 && | |
183 | p4 submit -d "$(echo later CL has sœme more cp-1252 tæxt | | |
184 | iconv -f utf8 -t cp1252)" | |
185 | ) && | |
186 | ( | |
187 | cd "$git" && | |
188 | ||
189 | git p4.py sync --branch=master && | |
190 | ||
191 | git log p4/master >actual && | |
192 | grep "sœme more cp-1252 tæxt" actual && | |
193 | grep "æuthœr" actual | |
194 | ) | |
195 | ' | |
196 | ||
197 | ############################ | |
198 | ## / END REPEATED SECTION ## | |
199 | ############################ | |
200 | ||
201 | ||
202 | test_expect_success 'fallback (both utf-8 and cp-1252 contents handled) is the default with python3' ' | |
203 | test_when_finished cleanup_git && | |
204 | test_when_finished remove_user_cache && | |
205 | git p4.py clone --dest="$git" //depot@all && | |
206 | ( | |
207 | cd "$git" && | |
208 | git log >actual && | |
209 | grep "sœme cp-1252 tæxt" actual && | |
210 | grep "æuthœr" actual | |
211 | ) | |
212 | ' | |
213 | ||
214 | test_done |