Skip to content

Commit c7bdbd6

Browse files
committed
Merge branch 'ls/p4-translation-failure' into maint
Work around "git p4" failing when the P4 depot records the contents in UTF-16 without UTF-16 BOM. * ls/p4-translation-failure: git-p4: handle "Translation of file content failed" git-p4: add test case for "Translation of file content failed" error
2 parents c04b3a2 + 1f5f390 commit c7bdbd6

File tree

2 files changed

+66
-11
lines changed

2 files changed

+66
-11
lines changed

git-p4.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,11 @@ def read_pipe(c, ignore_error=False):
134134
sys.stderr.write('Reading pipe: %s\n' % str(c))
135135

136136
expand = isinstance(c,basestring)
137-
p = subprocess.Popen(c, stdout=subprocess.PIPE, shell=expand)
138-
pipe = p.stdout
139-
val = pipe.read()
140-
if p.wait() and not ignore_error:
141-
die('Command failed: %s' % str(c))
142-
143-
return val
137+
p = subprocess.Popen(c, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=expand)
138+
(out, err) = p.communicate()
139+
if p.returncode != 0 and not ignore_error:
140+
die('Command failed: %s\nError: %s' % (str(c), err))
141+
return out
144142

145143
def p4_read_pipe(c, ignore_error=False):
146144
real_cmd = p4_build_cmd(c)
@@ -2193,10 +2191,17 @@ def streamOneP4File(self, file, contents):
21932191
# them back too. This is not needed to the cygwin windows version,
21942192
# just the native "NT" type.
21952193
#
2196-
text = p4_read_pipe(['print', '-q', '-o', '-', "%s@%s" % (file['depotFile'], file['change']) ])
2197-
if p4_version_string().find("/NT") >= 0:
2198-
text = text.replace("\r\n", "\n")
2199-
contents = [ text ]
2194+
try:
2195+
text = p4_read_pipe(['print', '-q', '-o', '-', '%s@%s' % (file['depotFile'], file['change'])])
2196+
except Exception as e:
2197+
if 'Translation of file content failed' in str(e):
2198+
type_base = 'binary'
2199+
else:
2200+
raise e
2201+
else:
2202+
if p4_version_string().find('/NT') >= 0:
2203+
text = text.replace('\r\n', '\n')
2204+
contents = [ text ]
22002205

22012206
if type_base == "apple":
22022207
# Apple filetype files will be streamed as a concatenation of
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/sh
2+
3+
test_description='git p4 handling of UTF-16 files without BOM'
4+
5+
. ./lib-git-p4.sh
6+
7+
UTF16="\227\000\227\000"
8+
9+
test_expect_success 'start p4d' '
10+
start_p4d
11+
'
12+
13+
test_expect_success 'init depot with UTF-16 encoded file and artificially remove BOM' '
14+
(
15+
cd "$cli" &&
16+
printf "$UTF16" >file1 &&
17+
p4 add -t utf16 file1 &&
18+
p4 submit -d "file1"
19+
) &&
20+
21+
(
22+
cd db &&
23+
p4d -jc &&
24+
# P4D automatically adds a BOM. Remove it here to make the file invalid.
25+
sed -e "\$d" depot/file1,v >depot/file1,v.new &&
26+
mv depot/file1,v.new depot/file1,v &&
27+
printf "@$UTF16@" >>depot/file1,v &&
28+
p4d -jrF checkpoint.1
29+
)
30+
'
31+
32+
test_expect_success 'clone depot with invalid UTF-16 file in verbose mode' '
33+
git p4 clone --dest="$git" --verbose //depot &&
34+
test_when_finished cleanup_git &&
35+
(
36+
cd "$git" &&
37+
printf "$UTF16" >expect &&
38+
test_cmp_bin expect file1
39+
)
40+
'
41+
42+
test_expect_failure 'clone depot with invalid UTF-16 file in non-verbose mode' '
43+
git p4 clone --dest="$git" //depot
44+
'
45+
46+
test_expect_success 'kill p4d' '
47+
kill_p4d
48+
'
49+
50+
test_done

0 commit comments

Comments
 (0)