Show More
@@ -20,7 +20,7 b' class AmbiguousCommand(Exception):' | |||||
20 | class ParseError(Exception): |
|
20 | class ParseError(Exception): | |
21 | """Exception raised on errors in parsing the command line.""" |
|
21 | """Exception raised on errors in parsing the command line.""" | |
22 |
|
22 | |||
23 | def runcatch(ui, args): |
|
23 | def runcatch(ui, args, argv0=None): | |
24 | def catchterm(*args): |
|
24 | def catchterm(*args): | |
25 | raise util.SignalInterrupt |
|
25 | raise util.SignalInterrupt | |
26 |
|
26 | |||
@@ -34,7 +34,7 b' def runcatch(ui, args):' | |||||
34 | if '--debugger' in args: |
|
34 | if '--debugger' in args: | |
35 | pdb.set_trace() |
|
35 | pdb.set_trace() | |
36 | try: |
|
36 | try: | |
37 | return dispatch(ui, args) |
|
37 | return dispatch(ui, args, argv0=argv0) | |
38 | finally: |
|
38 | finally: | |
39 | ui.flush() |
|
39 | ui.flush() | |
40 | except: |
|
40 | except: | |
@@ -255,7 +255,10 b' def earlygetopt(aliases, args):' | |||||
255 | return args[args.index(opt) + 1] |
|
255 | return args[args.index(opt) + 1] | |
256 | return None |
|
256 | return None | |
257 |
|
257 | |||
258 | def dispatch(ui, args): |
|
258 | def dispatch(ui, args, argv0=None): | |
|
259 | # remember how to call 'hg' before changing the working dir | |||
|
260 | util.set_hgexecutable(argv0) | |||
|
261 | ||||
259 | # check for cwd first |
|
262 | # check for cwd first | |
260 | cwd = earlygetopt(['--cwd'], args) |
|
263 | cwd = earlygetopt(['--cwd'], args) | |
261 | if cwd: |
|
264 | if cwd: |
@@ -3090,13 +3090,13 b' norepo = ("clone init version help debug' | |||||
3090 | " debugindex debugindexdot debugdate debuginstall") |
|
3090 | " debugindex debugindexdot debugdate debuginstall") | |
3091 | optionalrepo = ("paths serve showconfig") |
|
3091 | optionalrepo = ("paths serve showconfig") | |
3092 |
|
3092 | |||
3093 | def dispatch(args): |
|
3093 | def dispatch(args, argv0=None): | |
3094 | try: |
|
3094 | try: | |
3095 | u = ui.ui(traceback='--traceback' in args) |
|
3095 | u = ui.ui(traceback='--traceback' in args) | |
3096 | except util.Abort, inst: |
|
3096 | except util.Abort, inst: | |
3097 | sys.stderr.write(_("abort: %s\n") % inst) |
|
3097 | sys.stderr.write(_("abort: %s\n") % inst) | |
3098 | return -1 |
|
3098 | return -1 | |
3099 | return cmdutil.runcatch(u, args) |
|
3099 | return cmdutil.runcatch(u, args, argv0=argv0) | |
3100 |
|
3100 | |||
3101 | def run(): |
|
3101 | def run(): | |
3102 | sys.exit(dispatch(sys.argv[1:])) |
|
3102 | sys.exit(dispatch(sys.argv[1:], argv0=sys.argv[0])) |
@@ -37,6 +37,11 b' helptable = {' | |||||
37 |
|
37 | |||
38 | 'environment|env|Environment Variables': |
|
38 | 'environment|env|Environment Variables': | |
39 | r''' |
|
39 | r''' | |
|
40 | HG:: | |||
|
41 | Path to the 'hg' executable, automatically passed when running hooks | |||
|
42 | or external tools. Falls back to 'hg' if unset and the value can't be | |||
|
43 | autodetected, e.g. when Mercurial is run as a Python module. | |||
|
44 | ||||
40 | HGEDITOR:: |
|
45 | HGEDITOR:: | |
41 | This is the name of the editor to use when committing. Defaults to the |
|
46 | This is the name of the editor to use when committing. Defaults to the | |
42 | value of EDITOR. |
|
47 | value of EDITOR. |
@@ -537,6 +537,17 b' def _matcher(canonroot, cwd, names, inc,' | |||||
537 |
|
537 | |||
538 | return (roots, match, (inc or exc or anypats) and True) |
|
538 | return (roots, match, (inc or exc or anypats) and True) | |
539 |
|
539 | |||
|
540 | _hgexecutable = None | |||
|
541 | ||||
|
542 | def set_hgexecutable(path): | |||
|
543 | """remember location of the 'hg' executable if easily possible | |||
|
544 | ||||
|
545 | path might be None or empty if hg was loaded as a module, | |||
|
546 | fall back to 'hg' in this case. | |||
|
547 | """ | |||
|
548 | global _hgexecutable | |||
|
549 | _hgexecutable = path and os.path.abspath(path) or 'hg' | |||
|
550 | ||||
540 | def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None): |
|
551 | def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None): | |
541 | '''enhanced shell command execution. |
|
552 | '''enhanced shell command execution. | |
542 | run with environment maybe modified, maybe in different dir. |
|
553 | run with environment maybe modified, maybe in different dir. | |
@@ -562,6 +573,8 b' def system(cmd, environ={}, cwd=None, on' | |||||
562 | try: |
|
573 | try: | |
563 | for k, v in environ.iteritems(): |
|
574 | for k, v in environ.iteritems(): | |
564 | os.environ[k] = py2shell(v) |
|
575 | os.environ[k] = py2shell(v) | |
|
576 | if 'HG' not in os.environ: | |||
|
577 | os.environ['HG'] = _hgexecutable | |||
565 | if cwd is not None and oldcwd != cwd: |
|
578 | if cwd is not None and oldcwd != cwd: | |
566 | os.chdir(cwd) |
|
579 | os.chdir(cwd) | |
567 | rc = os.system(cmd) |
|
580 | rc = os.system(cmd) |
General Comments 0
You need to be logged in to leave comments.
Login now