Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 4488:62019c4427e3
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.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Sun, 27 May 2007 14:26:54 -0700 |
parents | 439b1c35348a |
children | 0026ccc2bf23 |
comparison
equal
deleted
inserted
replaced
4487:1b5b98837bb5 | 4488:62019c4427e3 |
---|---|
1085 p_name = os.path.join(p, name) | 1085 p_name = os.path.join(p, name) |
1086 if os.path.exists(p_name): | 1086 if os.path.exists(p_name): |
1087 return p_name | 1087 return p_name |
1088 return default | 1088 return default |
1089 | 1089 |
1090 def find_exe(name, default=None): | |
1091 '''find path of an executable. | |
1092 if name contains a path component, return it as is. otherwise, | |
1093 use normal executable search path.''' | |
1094 | |
1095 if os.sep in name: | |
1096 # don't check the executable bit. if the file isn't | |
1097 # executable, whoever tries to actually run it will give a | |
1098 # much more useful error message. | |
1099 return name | |
1100 return find_in_path(name, os.environ.get('PATH', ''), default=default) | |
1101 | |
1090 def _buildencodefun(): | 1102 def _buildencodefun(): |
1091 e = '_' | 1103 e = '_' |
1092 win_reserved = [ord(x) for x in '\\:*?"<>|'] | 1104 win_reserved = [ord(x) for x in '\\:*?"<>|'] |
1093 cmap = dict([ (chr(x), chr(x)) for x in xrange(127) ]) | 1105 cmap = dict([ (chr(x), chr(x)) for x in xrange(127) ]) |
1094 for x in (range(32) + range(126, 256) + win_reserved): | 1106 for x in (range(32) + range(126, 256) + win_reserved): |