Mercurial > public > mercurial-scm > hg-stable
diff mercurial/util.py @ 5062:3d35c8cb5eb4
Simplify/correct finding the hg executable (fixes issue644)
Simply use find_exe('hg') as the default value for $HG and require to manually
set it if you have special requirements.
While the default will not always be 100% correct (i.e. the identical hg
version) for many users it is and for the others the hg executable found in
the PATH should do most things correctly.
Developers or other users with multiple installs can set $HG or run something
like util.set_hgexecutable in their shell or python scripts.
Additionally util.hgexecutable() is now available so extensions can access
the value with a public interface, too.
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Sat, 04 Aug 2007 22:25:12 +0200 |
parents | 0875082d5471 |
children | 84b10dc3dccc d5126a0172ba |
line wrap: on
line diff
--- a/mercurial/util.py Tue Jul 10 10:06:24 2007 -0700 +++ b/mercurial/util.py Sat Aug 04 22:25:12 2007 +0200 @@ -540,17 +540,21 @@ return (roots, match, (inc or exc or anypats) and True) -_hgexecutable = 'hg' +_hgexecutable = None + +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')) + return _hgexecutable 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. - """ + """set location of the 'hg' executable""" global _hgexecutable - if path: - _hgexecutable = os.path.abspath(path) + _hgexecutable = path def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None): '''enhanced shell command execution. @@ -577,8 +581,7 @@ try: for k, v in environ.iteritems(): os.environ[k] = py2shell(v) - if 'HG' not in os.environ: - os.environ['HG'] = _hgexecutable + os.environ['HG'] = hgexecutable() if cwd is not None and oldcwd != cwd: os.chdir(cwd) rc = os.system(cmd)