--- a/mercurial/util.py Tue Apr 08 18:40:11 2008 +0200
+++ b/mercurial/util.py Wed Apr 09 15:28:30 2008 -0700
@@ -15,7 +15,7 @@
from i18n import _
import cStringIO, errno, getpass, re, shutil, sys, tempfile
import os, stat, threading, time, calendar, ConfigParser, locale, glob, osutil
-import urlparse
+import imp, urlparse
# Python compatibility
@@ -563,13 +563,29 @@
_hgexecutable = None
+def main_is_frozen():
+ """return True if we are a frozen executable.
+
+ The code supports py2exe (most common, Windows only) and tools/freeze
+ (portable, not much used).
+ """
+ return (hasattr(sys, "frozen") or # new py2exe
+ hasattr(sys, "importers") or # old py2exe
+ imp.is_frozen("__main__")) # tools/freeze
+
def hgexecutable():
"""return location of the 'hg' executable.
Defaults to $HG or 'hg' in the search path.
"""
if _hgexecutable is None:
- set_hgexecutable(os.environ.get('HG') or find_exe('hg', 'hg'))
+ hg = os.environ.get('HG')
+ if hg:
+ set_hgexecutable(hg)
+ elif main_is_frozen():
+ set_hgexecutable(sys.executable)
+ else:
+ set_hgexecutable(find_exe('hg', 'hg'))
return _hgexecutable
def set_hgexecutable(path):