git-p4: improve path encoding verbose output

If a path with non-ASCII characters is detected then print the encoding and the encoded string in verbose mode. Signed-off-by: Lars Schneider <larsxschneider@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Lars Schneider committed Sep 16, 2015 at 14:37 UTC 00a9403a1069b19f27d690853db34459b32b3d3d
1 file changed +9 -10
git-p4.py
+9 -10
@@ -2213,16 +2213,15 @@ class P4Sync(Command, P4UserMap):
2213 text = regexp.sub(r'$\1$', text)
2214 contents = [ text ]
2215
2216 - if gitConfig("git-p4.pathEncoding"):
2217 - relPath = relPath.decode(gitConfig("git-p4.pathEncoding")).encode('utf8', 'replace')
2218 - elif self.verbose:
2219 - try:
2220 - relPath.decode('ascii')
2221 - except:
2222 - print (
2223 - "Path with Non-ASCII characters detected and no path encoding defined. "
2224 - "Please check the encoding: %s" % relPath
2225 - )
2216 + try:
2217 + relPath.decode('ascii')
2218 + except:
2219 + encoding = 'utf8'
2220 + if gitConfig('git-p4.pathEncoding'):
2221 + encoding = gitConfig('git-p4.pathEncoding')
2222 + relPath = relPath.decode(encoding).encode('utf8', 'replace')
2223 + if self.verbose:
2224 + print 'Path with non-ASCII characters detected. Used %s to encode: %s ' % (encoding, relPath)
2225
2226 self.gitStream.write("M %s inline %s\n" % (git_mode, relPath))
2227