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.
This commit is contained in:
Bryan O'Sullivan 2007-05-27 14:26:54 -07:00
parent ebb57c99be
commit d67a234671
3 changed files with 24 additions and 15 deletions

View File

@ -880,11 +880,10 @@ def debuginstall(ui):
# 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 @@ def debuginstall(ui):
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 @@ def debuginstall(ui):
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"))

View File

@ -295,11 +295,13 @@ def patch(patchname, ui, strip=1, cwd=None, files={}):
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 @@ def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False,
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:

View File

@ -1087,6 +1087,18 @@ else:
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 '\\:*?"<>|']