Skip to content

Commit 5a98255

Browse files
committed
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
2 parents d09b692 + a8b0516 commit 5a98255

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

git-p4.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2484,11 +2484,24 @@ def writeToGitStream(self, gitMode, relPath, contents):
24842484
self.gitStream.write(d)
24852485
self.gitStream.write('\n')
24862486

2487+
def encodeWithUTF8(self, path):
2488+
try:
2489+
path.decode('ascii')
2490+
except:
2491+
encoding = 'utf8'
2492+
if gitConfig('git-p4.pathEncoding'):
2493+
encoding = gitConfig('git-p4.pathEncoding')
2494+
path = path.decode(encoding, 'replace').encode('utf8', 'replace')
2495+
if self.verbose:
2496+
print 'Path with non-ASCII characters detected. Used %s to encode: %s ' % (encoding, path)
2497+
return path
2498+
24872499
# output one file from the P4 stream
24882500
# - helper for streamP4Files
24892501

24902502
def streamOneP4File(self, file, contents):
24912503
relPath = self.stripRepoPath(file['depotFile'], self.branchPrefixes)
2504+
relPath = self.encodeWithUTF8(relPath)
24922505
if verbose:
24932506
size = int(self.stream_file['fileSize'])
24942507
sys.stdout.write('\r%s --> %s (%i MB)\n' % (file['depotFile'], relPath, size/1024/1024))
@@ -2561,23 +2574,14 @@ def streamOneP4File(self, file, contents):
25612574
text = regexp.sub(r'$\1$', text)
25622575
contents = [ text ]
25632576

2564-
try:
2565-
relPath.decode('ascii')
2566-
except:
2567-
encoding = 'utf8'
2568-
if gitConfig('git-p4.pathEncoding'):
2569-
encoding = gitConfig('git-p4.pathEncoding')
2570-
relPath = relPath.decode(encoding, 'replace').encode('utf8', 'replace')
2571-
if self.verbose:
2572-
print 'Path with non-ASCII characters detected. Used %s to encode: %s ' % (encoding, relPath)
2573-
25742577
if self.largeFileSystem:
25752578
(git_mode, contents) = self.largeFileSystem.processContent(git_mode, relPath, contents)
25762579

25772580
self.writeToGitStream(git_mode, relPath, contents)
25782581

25792582
def streamOneP4Deletion(self, file):
25802583
relPath = self.stripRepoPath(file['path'], self.branchPrefixes)
2584+
relPath = self.encodeWithUTF8(relPath)
25812585
if verbose:
25822586
sys.stdout.write("delete %s\n" % relPath)
25832587
sys.stdout.flush()

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,22 @@ test_expect_success 'Clone repo containing iso8859-1 encoded paths with git-p4.p
5151
)
5252
'
5353

54+
test_expect_success 'Delete iso8859-1 encoded paths and clone' '
55+
(
56+
cd "$cli" &&
57+
ISO8859="$(printf "$ISO8859_ESCAPED")" &&
58+
p4 delete "$ISO8859" &&
59+
p4 submit -d "remove file"
60+
) &&
61+
git p4 clone --destination="$git" //depot@all &&
62+
test_when_finished cleanup_git &&
63+
(
64+
cd "$git" &&
65+
git -c core.quotepath=false ls-files >actual &&
66+
test_must_be_empty actual
67+
)
68+
'
69+
5470
test_expect_success 'kill p4d' '
5571
kill_p4d
5672
'

0 commit comments

Comments
 (0)