Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 <larsxschneider@gmail.com>
Reviewed-by: Luke Diamand <luke@diamand.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
larsxschneider authored and gitster committed Feb 10, 2017
1 parent 50b4a78 commit a8b0516
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
24 changes: 14 additions & 10 deletions git-p4.py
Expand Up @@ -2388,11 +2388,24 @@ def writeToGitStream(self, gitMode, relPath, contents):
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))
Expand Down Expand Up @@ -2465,23 +2478,14 @@ def streamOneP4File(self, file, contents):
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)

self.writeToGitStream(git_mode, relPath, contents)

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()
Expand Down
16 changes: 16 additions & 0 deletions t/t9822-git-p4-path-encoding.sh
Expand Up @@ -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
'
Expand Down

0 comments on commit a8b0516

Please sign in to comment.