util: fix finding of hgexecutable
The version introduced in
89d9f92f6fdd would for example return thg
(thanks to Mads Kiilerich for pointing to this)
--- a/mercurial/util.py Fri Sep 16 14:37:57 2011 -0500
+++ b/mercurial/util.py Sat Jul 23 06:18:18 2011 +0200
@@ -370,12 +370,13 @@
"""
if _hgexecutable is None:
hg = os.environ.get('HG')
+ mainmod = sys.modules['__main__']
if hg:
_sethgexecutable(hg)
elif mainfrozen():
_sethgexecutable(sys.executable)
- elif getattr(sys.modules['__main__'], '__file__', '').endswith('hg'):
- _sethgexecutable(sys.modules['__main__'].__file__)
+ elif os.path.basename(getattr(mainmod, '__file__', '')) == 'hg':
+ _sethgexecutable(mainmod.__file__)
else:
exe = findexe('hg') or os.path.basename(sys.argv[0])
_sethgexecutable(exe)