diff mercurial/util.py @ 4684:849f011dbf79

Remember path to 'hg' executable and pass to external tools and hooks as $HG.
author Thomas Arendsen Hein <thomas@intevation.de>
date Sat, 23 Jun 2007 20:21:10 +0200
parents d8442fc0da8d
children 01f9ee4de1ad
line wrap: on
line diff
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -537,6 +537,17 @@ def _matcher(canonroot, cwd, names, inc,
 
     return (roots, match, (inc or exc or anypats) and True)
 
+_hgexecutable = None
+
+def set_hgexecutable(path):
+    """remember location of the 'hg' executable if easily possible
+
+    path might be None or empty if hg was loaded as a module,
+    fall back to 'hg' in this case.
+    """
+    global _hgexecutable
+    _hgexecutable = path and os.path.abspath(path) or 'hg'
+
 def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None):
     '''enhanced shell command execution.
     run with environment maybe modified, maybe in different dir.
@@ -562,6 +573,8 @@ def system(cmd, environ={}, cwd=None, on
     try:
         for k, v in environ.iteritems():
             os.environ[k] = py2shell(v)
+        if 'HG' not in os.environ:
+            os.environ['HG'] = _hgexecutable
         if cwd is not None and oldcwd != cwd:
             os.chdir(cwd)
         rc = os.system(cmd)