Patchwork [2,of,2] procutil: don't allow the main 'hg' script to be treated as the Windows exe

login
register
mail settings
Submitter Matt Harbison
Date Nov. 24, 2018, 6:46 a.m.
Message ID <1f9de5636e5f7f4bfe2d.1543041997@Envy>
Download mbox | patch
Permalink /patch/36761/
State Accepted
Headers show

Comments

Matt Harbison - Nov. 24, 2018, 6:46 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1543030077 18000
#      Fri Nov 23 22:27:57 2018 -0500
# Node ID 1f9de5636e5f7f4bfe2d3fb8c5dde543a1870161
# Parent  2abf33243bea3e4679ac944315d82fce21918d8f
procutil: don't allow the main 'hg' script to be treated as the Windows exe

Previously, there were a handful of errors like this:

     $ hg prefetch --repack
     (running background incremental repack)
  +  abort: %1 is not a valid Win32 application
  +  [255]

CreateProcess() doesn't append .exe when `lpApplicationName` contains a path,
and a python script isn't directly executable.

Patch

diff --git a/mercurial/utils/procutil.py b/mercurial/utils/procutil.py
--- a/mercurial/utils/procutil.py
+++ b/mercurial/utils/procutil.py
@@ -241,7 +241,7 @@  def hgexecutable():
                 _sethgexecutable(encoding.environ['EXECUTABLEPATH'])
             else:
                 _sethgexecutable(pycompat.sysexecutable)
-        elif (os.path.basename(
+        elif (not pycompat.iswindows and os.path.basename(
             pycompat.fsencode(getattr(mainmod, '__file__', ''))) == 'hg'):
             _sethgexecutable(pycompat.fsencode(mainmod.__file__))
         else: