Skip to content

Commit

Permalink
git-p4: improve path encoding verbose output
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Lars Schneider authored and Junio C Hamano committed Sep 16, 2015
1 parent a9e3835 commit 00a9403
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions git-p4.py
Original file line number Diff line number Diff line change
Expand Up @@ -2213,16 +2213,15 @@ def streamOneP4File(self, file, contents):
text = regexp.sub(r'$\1$', text)
contents = [ text ]

if gitConfig("git-p4.pathEncoding"):
relPath = relPath.decode(gitConfig("git-p4.pathEncoding")).encode('utf8', 'replace')
elif self.verbose:
try:
relPath.decode('ascii')
except:
print (
"Path with Non-ASCII characters detected and no path encoding defined. "
"Please check the encoding: %s" % relPath
)
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))

Expand Down

0 comments on commit 00a9403

Please sign in to comment.