[PATCH 1 of 2] windows: add a method to convert Unix style command lines to Windows style

Yuya Nishihara yuya at tcha.org
Fri Jun 29 07:46:57 EDT 2018


On Thu, 28 Jun 2018 23:10:33 -0400, Matt Harbison wrote:
> On Thu, 28 Jun 2018 07:49:42 -0400, Yuya Nishihara <yuya at tcha.org> wrote:
> 
> > On Wed, 27 Jun 2018 08:44:26 -0400, Matt Harbison wrote:
> >> # HG changeset patch
> >> # User Matt Harbison <matt_harbison at yahoo.com>
> >> # Date 1529817189 14400
> >> #      Sun Jun 24 01:13:09 2018 -0400
> >> # Node ID 7ac9de5a8826fc95864ee4ba844eb8b5c9e71332
> >> # Parent  2c2e82469b8915c8153979cd89a970b7317f882d
> >> windows: add a method to convert Unix style command lines to Windows  
> >> style
> >
> > Queued, thanks.
> >
> >> +        elif c == b'\\' and index + 1 < pathlen and path[index + 1] ==  
> >> b'$':
> >> +            # Skip '\', but only if it is escaping $
> >> +            res += b'$'
> >> +            index += 1
> >
> > \-escape might be confusing since \ is the directory separator on  
> > Windows, and a hook command is likely to contain backslashes.
> 
> Ugh.  I didn't even think about that, though I don't think path components  
> starting with '$' are that common.
> 
> Thinking about this a bit more...
> 
>    - Maybe we should drop $$ -> $ too, since that's not what a Unix shell  
> would do, and the point of this is portability.

+1

>    - Escaped '$' is a problem for hg -> cmd.exe -> sh.exe.  Consider `hook  
> = echo \$var` in the config file.  This gets passed to cmd.exe as `echo  
> $var`, but that doesn't change if something other than sh.exe runs.
>    - I think translating `'` to `"` is the most useful thing to do, but  
> that runs into the same problem.
> 
> What do you think?  Do we need an experimental knob to turn this off?  I'm  
> assuming sh.exe is rare, and there aren't a whole lot of ways to hit this  
> in practice.  I'd prefer it does the sensible thing out of the box.

I think we should do as little shell emulation as possible because it can't
be perfect. Maybe we can leave \$foo unmodified (i.e. no $foo nor \%foo%) as
it is ambiguous?

I'm not so worrying about the hg->cmd.exe->sh thing, but if we add a config
knob, I think per-hook option is nicer.


More information about the Mercurial-devel mailing list