Skip to content

Commit a8b0516

Browse files
larsxschneidergitster
authored andcommitted
git-p4: fix git-p4.pathEncoding for removed files
In a9e3835 we taught git-p4 a way to re-encode path names from what was used in Perforce to UTF-8. This path re-encoding worked properly for "added" paths. "Removed" paths were not re-encoded and therefore different from the "added" paths. Consequently, these files were not removed in a git-p4 cloned Git repository because the path names did not match. Fix this by moving the re-encoding to a place that affects "added" and "removed" paths. Add a test to demonstrate the issue. Signed-off-by: Lars Schneider <[email protected]> Reviewed-by: Luke Diamand <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 50b4a78 commit a8b0516

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
@@ -2388,11 +2388,24 @@ def writeToGitStream(self, gitMode, relPath, contents):
23882388
self.gitStream.write(d)
23892389
self.gitStream.write('\n')
23902390

2391+
def encodeWithUTF8(self, path):
2392+
try:
2393+
path.decode('ascii')
2394+
except:
2395+
encoding = 'utf8'
2396+
if gitConfig('git-p4.pathEncoding'):
2397+
encoding = gitConfig('git-p4.pathEncoding')
2398+
path = path.decode(encoding, 'replace').encode('utf8', 'replace')
2399+
if self.verbose:
2400+
print 'Path with non-ASCII characters detected. Used %s to encode: %s ' % (encoding, path)
2401+
return path
2402+
23912403
# output one file from the P4 stream
23922404
# - helper for streamP4Files
23932405

23942406
def streamOneP4File(self, file, contents):
23952407
relPath = self.stripRepoPath(file['depotFile'], self.branchPrefixes)
2408+
relPath = self.encodeWithUTF8(relPath)
23962409
if verbose:
23972410
size = int(self.stream_file['fileSize'])
23982411
sys.stdout.write('\r%s --> %s (%i MB)\n' % (file['depotFile'], relPath, size/1024/1024))
@@ -2465,23 +2478,14 @@ def streamOneP4File(self, file, contents):
24652478
text = regexp.sub(r'$\1$', text)
24662479
contents = [ text ]
24672480

2468-
try:
2469-
relPath.decode('ascii')
2470-
except:
2471-
encoding = 'utf8'
2472-
if gitConfig('git-p4.pathEncoding'):
2473-
encoding = gitConfig('git-p4.pathEncoding')
2474-
relPath = relPath.decode(encoding, 'replace').encode('utf8', 'replace')
2475-
if self.verbose:
2476-
print 'Path with non-ASCII characters detected. Used %s to encode: %s ' % (encoding, relPath)
2477-
24782481
if self.largeFileSystem:
24792482
(git_mode, contents) = self.largeFileSystem.processContent(git_mode, relPath, contents)
24802483

24812484
self.writeToGitStream(git_mode, relPath, contents)
24822485

24832486
def streamOneP4Deletion(self, file):
24842487
relPath = self.stripRepoPath(file['path'], self.branchPrefixes)
2488+
relPath = self.encodeWithUTF8(relPath)
24852489
if verbose:
24862490
sys.stdout.write("delete %s\n" % relPath)
24872491
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)