Why does mercurial.util.username() return None on Windows?

Matt Harbison mharbison72 at gmail.com
Wed Jul 10 00:01:20 EDT 2019


On Mon, 08 Jul 2019 21:00:32 -0400, Matt Harbison <mharbison72 at gmail.com>  
wrote:

> On Mon, 08 Jul 2019 14:58:36 -0400, Augie Fackler <raf at durin42.com>  
> wrote:
>
>> I just tripped on this today:  
>> https://www.mercurial-scm.org/repo/hg/file/tip/mercurial/windows.py#l514
>>
>> It's been that way since at least 2009 when mpm split out the  
>> {posix,windows,win32} modules. Does anyone (maybe mharbison?) have an  
>> idea why this is the case? Would it be okay to make util.username(None)  
>> return getpass.getuser() on Windows? I'm guessing the answer is yes,  
>> but figured I should ask some Windows gurus before I leap into the  
>> unknown.
>
> I can't think of any issue offhand.  The help says USERNAME must be set  
> on Windows, but experimentally, it seems to work without it.  It also  
> doesn't seem to report a different value if USERNAME is tampered with.   
> I'll check tomorrow to see how a domain account is reported, if I  
> remember.

The string returned for a domain user is the simple username, not  
username at domain or DOMAIN\username.


More information about the Mercurial-devel mailing list