git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Re* [PATCH] remote-hg: unquote C-style paths when exporting

From
Antoine Pelisse <apelisse@gmail.com>
Date
Oct 23, 2013, 15:53 UTC
Message-ID
<CALWbr2z-+S_rNFEKNH2fYJQmn1z9SyO2Z4sNDoz=Kh8P8Y_ccQ@mail.gmail.com>
In-Reply-To
<xmqqa9i0rnzo.fsf_-_@gitster.dls.corp.google.com>
On Wed, Oct 23, 2013 at 5:44 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 14 quoted lines
> Antoine Pelisse <apelisse@gmail.com> writes:
>
>>> def c_style_unescape(string):
>>>     if string[0] == string[-1] == '"':
>>>         return string.decode('string-escape')[1:-1]
>>>     return string
>>>
>>> It's in git-remote-bzr.py.
>>
>> Yeah, that's certainly better,
>>
>> Thanks,
>
> OK, so an amended one will look like this?
The commit message needs to be updated as well.
Show 9 quoted lines
> -- >8 --
> From: Antoine Pelisse <apelisse@gmail.com>
> Subject: 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 result in the following situation:
s/result/&s/
> - clone a mercurial repository with git
> - Add a file with space: `mkdir dir/foo\ bar`
- Add a file with space in a directory: `>dir/foo\ bar`
> - Commit that new file, and push the change to mercurial
> - The mercurial repository as now a new directory named '"dir', which
> contains a file named 'foo bar"'
I'm so ashamed I'd rather not report this one: s/as/has/
> Use python ast.literal_eval to unquote the string if it starts with ".

Use python str.decode('string-escape') to unquote the string if it starts and ends with ".

Show 32 quoted lines
> 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>
> ---
>  contrib/remote-helpers/git-remote-hg | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg
> index 0194c67..85abbed 100755
> --- a/contrib/remote-helpers/git-remote-hg
> +++ b/contrib/remote-helpers/git-remote-hg
> @@ -678,6 +678,11 @@ def get_merge_files(repo, p1, p2, files):
>              f = { 'ctx' : repo[p1][e] }
>              files[e] = f
>
> +def c_style_unescape(string):
> +    if string[0] == string[-1] == '"':
> +        return string.decode('string-escape')[1:-1]
> +    return string
> +
>  def parse_commit(parser):
>      global marks, blob_marks, parsed_refs
>      global mode
> @@ -720,6 +725,7 @@ def parse_commit(parser):
>              f = { 'deleted' : True }
>          else:
>              die('Unknown file command: %s' % line)
> +        path = c_style_unescape(path).decode('utf-8')
>          files[path] = f
>
>      # only export the commits if we are on an internal proxy repo
That is consistent with git-remote-bzr,
Thanks
Previous: Junio C Hamano
Message 7 of 7 in “remote-hg: unquote C-style paths when exporting”
  1. remote-hg: unquote C-style paths when exportingAntoine Pelisse, Oct 18, 2013
  2. Junio C HamanoOct 22, 2013
  3. Antoine PelisseOct 22, 2013
  4. Felipe ContrerasOct 23, 2013
  5. Antoine PelisseOct 23, 2013
  6. Re* [PATCH] remote-hg: unquote C-style paths when exportingJunio C Hamano, Oct 23, 2013
  7. Antoine PelisseOct 23, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.