Mercurial > hg
changeset 4686: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 | 8c3d449ecc63 |
children | b5bbfa18daf7 |
files | mercurial/cmdutil.py mercurial/commands.py mercurial/help.py mercurial/util.py |
diffstat | 4 files changed, 27 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Sat Jun 23 12:05:00 2007 +0200 +++ b/mercurial/cmdutil.py Sat Jun 23 20:21:10 2007 +0200 @@ -20,7 +20,7 @@ class ParseError(Exception): """Exception raised on errors in parsing the command line.""" -def runcatch(ui, args): +def runcatch(ui, args, argv0=None): def catchterm(*args): raise util.SignalInterrupt @@ -34,7 +34,7 @@ if '--debugger' in args: pdb.set_trace() try: - return dispatch(ui, args) + return dispatch(ui, args, argv0=argv0) finally: ui.flush() except: @@ -255,7 +255,10 @@ return args[args.index(opt) + 1] return None -def dispatch(ui, args): +def dispatch(ui, args, argv0=None): + # remember how to call 'hg' before changing the working dir + util.set_hgexecutable(argv0) + # check for cwd first cwd = earlygetopt(['--cwd'], args) if cwd:
--- a/mercurial/commands.py Sat Jun 23 12:05:00 2007 +0200 +++ b/mercurial/commands.py Sat Jun 23 20:21:10 2007 +0200 @@ -3090,13 +3090,13 @@ " debugindex debugindexdot debugdate debuginstall") optionalrepo = ("paths serve showconfig") -def dispatch(args): +def dispatch(args, argv0=None): try: u = ui.ui(traceback='--traceback' in args) except util.Abort, inst: sys.stderr.write(_("abort: %s\n") % inst) return -1 - return cmdutil.runcatch(u, args) + return cmdutil.runcatch(u, args, argv0=argv0) def run(): - sys.exit(dispatch(sys.argv[1:])) + sys.exit(dispatch(sys.argv[1:], argv0=sys.argv[0]))
--- a/mercurial/help.py Sat Jun 23 12:05:00 2007 +0200 +++ b/mercurial/help.py Sat Jun 23 20:21:10 2007 +0200 @@ -37,6 +37,11 @@ 'environment|env|Environment Variables': r''' +HG:: + Path to the 'hg' executable, automatically passed when running hooks + or external tools. Falls back to 'hg' if unset and the value can't be + autodetected, e.g. when Mercurial is run as a Python module. + HGEDITOR:: This is the name of the editor to use when committing. Defaults to the value of EDITOR.
--- a/mercurial/util.py Sat Jun 23 12:05:00 2007 +0200 +++ b/mercurial/util.py Sat Jun 23 20:21:10 2007 +0200 @@ -537,6 +537,17 @@ 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 @@ 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)