summaryrefslogtreecommitdiff
path: root/git-p4.py
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-02-16 14:45:12 -0800
committerJunio C Hamano <gitster@pobox.com>2017-02-16 14:45:12 -0800
commit5a98255dec1578cc6dc3f25e85d7ea96028687b7 (patch)
treecd518fc5ec8312d8b9a90f656e3936d38c47bf36 /git-p4.py
parentd09b6927978d70ca53126e80d0dc8a070cc06635 (diff)
parenta8b05162e894b88aeb7d5064daba07e1a4f58463 (diff)
downloadgit-5a98255dec1578cc6dc3f25e85d7ea96028687b7.tar.gz
Merge branch 'ls/p4-path-encoding'
When "git p4" imports changelist that removes paths, it failed to convert pathnames when the p4 used encoding different from the one used on the Git side. This has been corrected. * ls/p4-path-encoding: git-p4: fix git-p4.pathEncoding for removed files
Diffstat (limited to 'git-p4.py')
-rwxr-xr-xgit-p4.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/git-p4.py b/git-p4.py
index 9695d2ed3e..eab319d76e 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -2484,11 +2484,24 @@ class P4Sync(Command, P4UserMap):
self.gitStream.write(d)
self.gitStream.write('\n')
+ def encodeWithUTF8(self, path):
+ try:
+ path.decode('ascii')
+ except:
+ encoding = 'utf8'
+ if gitConfig('git-p4.pathEncoding'):
+ encoding = gitConfig('git-p4.pathEncoding')
+ path = path.decode(encoding, 'replace').encode('utf8', 'replace')
+ if self.verbose:
+ print 'Path with non-ASCII characters detected. Used %s to encode: %s ' % (encoding, path)
+ return path
+
# output one file from the P4 stream
# - helper for streamP4Files
def streamOneP4File(self, file, contents):
relPath = self.stripRepoPath(file['depotFile'], self.branchPrefixes)
+ relPath = self.encodeWithUTF8(relPath)
if verbose:
size = int(self.stream_file['fileSize'])
sys.stdout.write('\r%s --> %s (%i MB)\n' % (file['depotFile'], relPath, size/1024/1024))
@@ -2561,16 +2574,6 @@ class P4Sync(Command, P4UserMap):
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, 'replace').encode('utf8', 'replace')
- if self.verbose:
- print 'Path with non-ASCII characters detected. Used %s to encode: %s ' % (encoding, relPath)
-
if self.largeFileSystem:
(git_mode, contents) = self.largeFileSystem.processContent(git_mode, relPath, contents)
@@ -2578,6 +2581,7 @@ class P4Sync(Command, P4UserMap):
def streamOneP4Deletion(self, file):
relPath = self.stripRepoPath(file['path'], self.branchPrefixes)
+ relPath = self.encodeWithUTF8(relPath)
if verbose:
sys.stdout.write("delete %s\n" % relPath)
sys.stdout.flush()