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

Matt Harbison mharbison72 at gmail.com
Mon Jul 8 21:00:32 EDT 2019


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.

However, `os.stat($file).st_uid` seems to always return 0 on py2 and py3.   
And the only usage I see of `util.username()` with no argument compares  
against `util.username(st.st_uid)`.  So I can't see how it's useful for  
the current codebase.


More information about the Mercurial-devel mailing list