This is an archive of the discontinued Mercurial Phabricator instance.

py3: use pycompat.sysargv[0] for instead of fsencode(sys.argv[0])
ClosedPublic

Authored by martinvonz on Sep 2 2019, 2:48 AM.

Details

Summary

Yuya noted in a recent review that fsencode(sys.argv[0]) could be
incorrect on Windows.

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

martinvonz created this revision.Sep 2 2019, 2:48 AM
martinvonz updated this revision to Diff 16363.Sep 2 2019, 2:51 AM
This revision was not accepted when it landed; it landed in state Needs Review.
This revision was automatically updated to reflect the committed changes.
yuja added a subscriber: yuja.Sep 5 2019, 7:20 PM

@@ -245,8 +245,11 @@

    pycompat.fsencode(getattr(mainmod, '__file__', ''))) == 'hg'):
    _sethgexecutable(pycompat.fsencode(mainmod.__file__))
else:
  • exe = findexe('hg') or os.path.basename(sys.argv[0])
  • _sethgexecutable(pycompat.fsencode(exe))

+ exe = findexe('hg')
+ if exe:
+ _sethgexecutable(pycompat.fsencode(exe))
+ else:
+ _sethgexecutable(os.path.basename(pycompat.sysargv[0]))

findexe() is supposed to return bytes. If not always, it's the bug
of findexe().

In D6782#99619, @yuja wrote:

@@ -245,8 +245,11 @@

    pycompat.fsencode(getattr(mainmod, '__file__', ''))) == 'hg'):
    _sethgexecutable(pycompat.fsencode(mainmod.__file__))
else:
  • exe = findexe('hg') or os.path.basename(sys.argv[0])
  • _sethgexecutable(pycompat.fsencode(exe))

+ exe = findexe('hg')
+ if exe:
+ _sethgexecutable(pycompat.fsencode(exe))
+ else:
+ _sethgexecutable(os.path.basename(pycompat.sysargv[0]))

findexe() is supposed to return bytes. If not always, it's the bug
of findexe().

Oh, findexe() is our own function. I somehow thought it was from the standard library. I'll send another follow-up. Thanks.