]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'ls/p4-path-encoding'
authorJunio C Hamano <gitster@pobox.com>
Thu, 16 Feb 2017 22:45:12 +0000 (14:45 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 16 Feb 2017 22:45:12 +0000 (14:45 -0800)
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

git-p4.py
t/t9822-git-p4-path-encoding.sh

index 9695d2ed3ec2071ed7a279eac785b7e280b718e4..eab319d76e4597ebbb27019695fd9ce14d145285 100755 (executable)
--- 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()
index 7b83e696a92a5c97e8c022af2601d60a95ab1cbc..c78477c19b4330f990c0cdd7d96997b8ed2ed02c 100755 (executable)
@@ -51,6 +51,22 @@ test_expect_success 'Clone repo containing iso8859-1 encoded paths with git-p4.p
        )
 '
 
+test_expect_success 'Delete iso8859-1 encoded paths and clone' '
+       (
+               cd "$cli" &&
+               ISO8859="$(printf "$ISO8859_ESCAPED")" &&
+               p4 delete "$ISO8859" &&
+               p4 submit -d "remove file"
+       ) &&
+       git p4 clone --destination="$git" //depot@all &&
+       test_when_finished cleanup_git &&
+       (
+               cd "$git" &&
+               git -c core.quotepath=false ls-files >actual &&
+               test_must_be_empty actual
+       )
+'
+
 test_expect_success 'kill p4d' '
        kill_p4d
 '