1. Simon H.
  2. hg-folding


Thomas Arendsen Hein  committed 849f011

Remember path to 'hg' executable and pass to external tools and hooks as $HG.

  • Participants
  • Parent commits 8c3d449
  • Branches default

Comments (0)

Files changed (4)

File mercurial/cmdutil.py

View file
 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
             if '--debugger' in args:
-                return dispatch(ui, args)
+                return dispatch(ui, args, argv0=argv0)
             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:

File mercurial/commands.py

View file
           " debugindex debugindexdot debugdate debuginstall")
 optionalrepo = ("paths serve showconfig")
-def dispatch(args):
+def dispatch(args, argv0=None):
         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]))

File mercurial/help.py

View file
     'environment|env|Environment Variables':
+    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.
     This is the name of the editor to use when committing. Defaults to the
     value of EDITOR.

File mercurial/util.py

View file
     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.
         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:
         rc = os.system(cmd)