git-p4: improve path encoding verbose output
[gitweb.git] / git-p4.py
index 073f87bbfdc1dc7ebc3fe610e78709667f597d82..65feb22f58f89e425302e7a8e3428c0af8c9619a 100755 (executable)
--- a/git-p4.py
+++ b/git-p4.py
@@ -2213,6 +2213,16 @@ def streamOneP4File(self, file, contents):
             text = regexp.sub(r'$\1$', text)
             contents = [ text ]
 
+        try:
+            relPath.decode('ascii')
+        except:
+            encoding = 'utf8'
+            if gitConfig('git-p4.pathEncoding'):
+                encoding = gitConfig('git-p4.pathEncoding')
+            relPath = relPath.decode(encoding).encode('utf8', 'replace')
+            if self.verbose:
+                print 'Path with non-ASCII characters detected. Used %s to encode: %s ' % (encoding, relPath)
+
         self.gitStream.write("M %s inline %s\n" % (git_mode, relPath))
 
         # total length...