remote-hg: unquote C-style paths when exporting

git-fast-import documentation says that paths can be C-style quoted. Unfortunately, the current remote-hg helper doesn't unquote quoted path and pass them as-is to Mercurial when the commit is created. This results in the following situation: - clone a mercurial repository with git - add a file with space in a directory: `>dir/foo\ bar` - commit that new file, and push the change to mercurial - the mercurial repository now has a new directory named '"dir', which contains a file named 'foo bar"' Use Python str.decode('string-escape') to unquote the string if it starts and ends with ". It has been tested with quotes, spaces, and utf-8 encoded file-names. Signed-off-by: Antoine Pelisse <apelisse@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Antoine Pelisse committed Oct 23, 2013 at 08:44 UTC 113626537711e290af46548683e02ae0a2f51b6f
1 file changed +6
contrib/remote-helpers/git-remote-hg
+6
@@ -678,6 +678,11 @@ def get_merge_files(repo, p1, p2, files):
678 f = { 'ctx' : repo[p1][e] }
679 files[e] = f
680
681 +def c_style_unescape(string):
682 + if string[0] == string[-1] == '"':
683 + return string.decode('string-escape')[1:-1]
684 + return string
685 +
686 def parse_commit(parser):
687 global marks, blob_marks, parsed_refs
688 global mode
@@ -720,6 +725,7 @@ def parse_commit(parser):
725 f = { 'deleted' : True }
726 else:
727 die('Unknown file command: %s' % line)
728 + path = c_style_unescape(path).decode('utf-8')
729 files[path] = f
730
731 # only export the commits if we are on an internal proxy repo