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

login
register
mail settings
Submitter phabricator
Date Sept. 2, 2019, 6:48 a.m.
Message ID <differential-rev-PHID-DREV-r42d3k7ufrd2hzqevmgr-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/41463/
State Superseded
Headers show

Comments

phabricator - Sept. 2, 2019, 6:48 a.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

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

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6782

AFFECTED FILES
  mercurial/utils/procutil.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel
phabricator - Sept. 5, 2019, 11:26 p.m.
martinvonz added a comment.


  In D6782#99619 <https://phab.mercurial-scm.org/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.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6782/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6782

To: martinvonz, #hg-reviewers
Cc: yuja, mercurial-devel

Patch

diff --git a/mercurial/utils/procutil.py b/mercurial/utils/procutil.py
--- a/mercurial/utils/procutil.py
+++ b/mercurial/utils/procutil.py
@@ -245,8 +245,9 @@ 
             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 = (pycompat.fsencode(findexe('hg')) or
+                   os.path.basename(pycompat.sysargv[0]))
+            _sethgexecutable(exe)
     return _hgexecutable
 
 def _sethgexecutable(path):