Skip to content

Commit 1f5f390

Browse files
larsxschneidergitster
authored andcommitted
git-p4: handle "Translation of file content failed"
A P4 repository can get into a state where it contains a file with type UTF-16 that does not contain a valid UTF-16 BOM. If git-p4 attempts to retrieve the file then the process crashes with a "Translation of file content failed" error. More info here: http://answers.perforce.com/articles/KB/3117 Fix this by detecting this error and retrieving the file as binary instead. The result in Git is the same. Known issue: This works only if git-p4 is executed in verbose mode. In normal mode no exceptions are thrown and git-p4 just exits. Signed-off-by: Lars Schneider <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fe18a0f commit 1f5f390

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
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

t/t9825-git-p4-handle-utf16-without-bom.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ test_expect_success 'init depot with UTF-16 encoded file and artificially remove
2929
)
3030
'
3131

32-
test_expect_failure 'clone depot with invalid UTF-16 file in verbose mode' '
32+
test_expect_success 'clone depot with invalid UTF-16 file in verbose mode' '
3333
git p4 clone --dest="$git" --verbose //depot &&
3434
test_when_finished cleanup_git &&
3535
(

0 commit comments

Comments
 (0)