[PATCH 4 of 4] windows: expand '~/' and '~\' to %USERPROFILE% when translating to cmd.exe

Matt Harbison mharbison72 at gmail.com
Wed Jul 18 08:32:32 EDT 2018


> On Jul 18, 2018, at 8:13 AM, Yuya Nishihara <yuya at tcha.org> wrote:
> 
> On Tue, 17 Jul 2018 10:42:33 -0400, Matt Harbison wrote:
>>>> On Jul 17, 2018, at 8:27 AM, Yuya Nishihara <yuya at tcha.org> wrote:
>>>> On Mon, 16 Jul 2018 17:31:35 -0400, Matt Harbison wrote:
>>>> # HG changeset patch
>>>> # User Matt Harbison <matt_harbison at yahoo.com>
>>>> # Date 1531715553 14400
>>>> #      Mon Jul 16 00:32:33 2018 -0400
>>>> # Node ID 54611420fcf7868ee195e9fa3070efc0d57e9757
>>>> # Parent  e71e478d5e49768357287a2f181e8a2b23213239
>>>> windows: expand '~/' and '~\' to %USERPROFILE% when translating to cmd.exe
>>> 
>>> Queued, thanks.
>>> 
>>>> +        elif (c == b'~' and index + 1 < pathlen
>>>> +              and path[index + 1] in (b'\\', b'/')):
>>>> +            res += "%USERPROFILE%"
>>> 
>>> Nit: ~/ is substituted only at the beginning. ('"~/"' and 'foo~/' shouldn't
>>> be expanded.)
>> 
>> Good catch.
>> 
>> Is there a way to mark this (tilde expansion) experimental?  (Or just undocumented it?)  I see we use os.path.expanduser() for various things, which uses a slightly more elaborate scheme.  The downside is it checks HOME first, which has a different definition under msys.  The config files under ~/ in msys gets read before the regular Windows user’s mercurial.ini, which means there’s no way to disable expansion under msys, but leave it enabled when run with cmd.exe.  So it seems to boil down to consistency vs portability, and I’d probably lean slightly to portable, based on my usage.
> 
> Should I drop this for now?
> 
> I think this patch is good enough, and the excessive tilde expansion can
> be fixed later.

If you think this can be fixed later, it’s probably OK to keep.  I was just toying with expanduser(), and wondering out loud if we would be able to shift to approximately that after releasing this.


More information about the Mercurial-devel mailing list