@@ -2484,11 +2484,24 @@ def writeToGitStream(self, gitMode, relPath, contents):
2484
2484
self .gitStream .write (d )
2485
2485
self .gitStream .write ('\n ' )
2486
2486
2487
+ def encodeWithUTF8 (self , path ):
2488
+ try :
2489
+ path .decode ('ascii' )
2490
+ except :
2491
+ encoding = 'utf8'
2492
+ if gitConfig ('git-p4.pathEncoding' ):
2493
+ encoding = gitConfig ('git-p4.pathEncoding' )
2494
+ path = path .decode (encoding , 'replace' ).encode ('utf8' , 'replace' )
2495
+ if self .verbose :
2496
+ print 'Path with non-ASCII characters detected. Used %s to encode: %s ' % (encoding , path )
2497
+ return path
2498
+
2487
2499
# output one file from the P4 stream
2488
2500
# - helper for streamP4Files
2489
2501
2490
2502
def streamOneP4File (self , file , contents ):
2491
2503
relPath = self .stripRepoPath (file ['depotFile' ], self .branchPrefixes )
2504
+ relPath = self .encodeWithUTF8 (relPath )
2492
2505
if verbose :
2493
2506
size = int (self .stream_file ['fileSize' ])
2494
2507
sys .stdout .write ('\r %s --> %s (%i MB)\n ' % (file ['depotFile' ], relPath , size / 1024 / 1024 ))
@@ -2561,23 +2574,14 @@ def streamOneP4File(self, file, contents):
2561
2574
text = regexp .sub (r'$\1$' , text )
2562
2575
contents = [ text ]
2563
2576
2564
- try :
2565
- relPath .decode ('ascii' )
2566
- except :
2567
- encoding = 'utf8'
2568
- if gitConfig ('git-p4.pathEncoding' ):
2569
- encoding = gitConfig ('git-p4.pathEncoding' )
2570
- relPath = relPath .decode (encoding , 'replace' ).encode ('utf8' , 'replace' )
2571
- if self .verbose :
2572
- print 'Path with non-ASCII characters detected. Used %s to encode: %s ' % (encoding , relPath )
2573
-
2574
2577
if self .largeFileSystem :
2575
2578
(git_mode , contents ) = self .largeFileSystem .processContent (git_mode , relPath , contents )
2576
2579
2577
2580
self .writeToGitStream (git_mode , relPath , contents )
2578
2581
2579
2582
def streamOneP4Deletion (self , file ):
2580
2583
relPath = self .stripRepoPath (file ['path' ], self .branchPrefixes )
2584
+ relPath = self .encodeWithUTF8 (relPath )
2581
2585
if verbose :
2582
2586
sys .stdout .write ("delete %s\n " % relPath )
2583
2587
sys .stdout .flush ()
0 commit comments