Git development
 help / color / mirror / Atom feed
* [PATCH] git-p4: don't convert utf16 files.
@ 2011-08-19 22:50 Chris Li
  2011-08-21 15:21 ` Pete Wyckoff
  0 siblings, 1 reply; 3+ messages in thread
From: Chris Li @ 2011-08-19 22:50 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

Some repository has some utf16 files git-p4 don't know
how to convert. For those files, git-p4 just write the utf8
files. That is wrong, because git get different file than
perforce does, causing some windows resource file fail
to compile.

Using the "p4 print -o tmpfile depotfile" can avoid this
convertion (and possible failure) all together.

Signed-off-by: Chris Li <git@chrisli.org>

---
 git-p4 |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/git-p4 b/git-p4
index 672b0c2..0c6a5cc 100755
--- a/git-p4
+++ b/git-p4
@@ -755,12 +755,11 @@ class P4FileReader:
                     break

             if header['type'].startswith('utf16'):
-                try:
-                    text = textBuffer.getvalue().encode('utf_16')
-                except UnicodeDecodeError:
-                    # File checked in to Perforce has an error. Try
without encoding
-                    print "Corrupt UTF-16 file in Perforce: %s" %
header['depotFile']
-                    text = textBuffer.getvalue()
+                # Don't even try to convert utf16. Ask p4 to write
the file directly.
+                tmpFile = tempfile.NamedTemporaryFile()
+                P4Helper().p4_system("print -o %s %s"%(tmpFile.name,
header['depotFile']))
+                text = open(tmpFile.name).read()
+      	        tmpFile.close()
             else:
                 text = textBuffer.getvalue()
             textBuffer.close()
-- 
1.7.6

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-08-21 19:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-19 22:50 [PATCH] git-p4: don't convert utf16 files Chris Li
2011-08-21 15:21 ` Pete Wyckoff
2011-08-21 19:09   ` Chris Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox