Introduce find_exe. Use instead of find_in_path for programs.
The behaviour of find_in_path was broken for config options containing
path names, because it always searched the given path, even when not
necessary. The find_exe function is more polite: if the name passed
to it contains a path component, it just returns it.
--- a/mercurial/commands.py Sun May 27 13:50:59 2007 -0700
+++ b/mercurial/commands.py Sun May 27 14:26:54 2007 -0700
@@ -880,11 +880,10 @@
# patch
ui.status(_("Checking patch...\n"))
- path = os.environ.get('PATH', '')
patcher = ui.config('ui', 'patch')
- if not patcher:
- patcher = util.find_in_path('gpatch', path,
- util.find_in_path('patch', path, None))
+ patcher = ((patcher and util.find_exe(patcher)) or
+ util.find_exe('gpatch') or
+ util.find_exe('patch'))
if not patcher:
ui.write(_(" Can't find patch or gpatch in PATH\n"))
ui.write(_(" (specify a patch utility in your .hgrc file)\n"))
@@ -922,9 +921,7 @@
ui.status(_("Checking merge helper...\n"))
cmd = (os.environ.get("HGMERGE") or ui.config("ui", "merge")
or "hgmerge")
- cmdpath = util.find_in_path(cmd, path)
- if not cmdpath:
- cmdpath = util.find_in_path(cmd.split()[0], path)
+ cmdpath = util.find_exe(cmd) or util.find_exe(cmd.split()[0])
if not cmdpath:
if cmd == 'hgmerge':
ui.write(_(" No merge helper set and can't find default"
@@ -958,9 +955,7 @@
editor = (os.environ.get("HGEDITOR") or
ui.config("ui", "editor") or
os.environ.get("EDITOR", "vi"))
- cmdpath = util.find_in_path(editor, path)
- if not cmdpath:
- cmdpath = util.find_in_path(editor.split()[0], path)
+ cmdpath = util.find_exe(editor) or util.find_exe(editor.split()[0])
if not cmdpath:
if editor == 'vi':
ui.write(_(" No commit editor set and can't find vi in PATH\n"))
--- a/mercurial/patch.py Sun May 27 13:50:59 2007 -0700
+++ b/mercurial/patch.py Sun May 27 14:26:54 2007 -0700
@@ -295,11 +295,13 @@
args = []
patcher = ui.config('ui', 'patch')
+ patcher = ((patcher and util.find_exe(patcher)) or
+ util.find_exe('gpatch') or
+ util.find_exe('patch'))
if not patcher:
- patcher = util.find_in_path('gpatch', os.environ.get('PATH', ''),
- 'patch')
- if util.needbinarypatch():
- args.append('--binary')
+ raise util.Abort(_('no patch command found in hgrc or PATH'))
+ if util.needbinarypatch():
+ args.append('--binary')
if cwd:
args.append('-d %s' % util.shellquote(cwd))
@@ -643,7 +645,7 @@
single(rev, seqno+1, fp)
def diffstat(patchlines):
- if not util.find_in_path('diffstat', os.environ.get('PATH', '')):
+ if not util.find_exe('diffstat'):
return
fd, name = tempfile.mkstemp(prefix="hg-patchbomb-", suffix=".txt")
try:
--- a/mercurial/util.py Sun May 27 13:50:59 2007 -0700
+++ b/mercurial/util.py Sun May 27 14:26:54 2007 -0700
@@ -1087,6 +1087,18 @@
return p_name
return default
+def find_exe(name, default=None):
+ '''find path of an executable.
+ if name contains a path component, return it as is. otherwise,
+ use normal executable search path.'''
+
+ if os.sep in name:
+ # don't check the executable bit. if the file isn't
+ # executable, whoever tries to actually run it will give a
+ # much more useful error message.
+ return name
+ return find_in_path(name, os.environ.get('PATH', ''), default=default)
+
def _buildencodefun():
e = '_'
win_reserved = [ord(x) for x in '\\:*?"<>|']