Mercurial > hg-stable
changeset 2071:67a0a3852024
import: use gpatch if present on system. patch is broken on solaris.
fixes issue 205.
add new useful function, util.find_in_path.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Thu, 13 Apr 2006 17:42:49 -0700 |
parents | 4bce7e8bb42b |
children | f71e9656524f 8742352db413 |
files | mercurial/util.py |
diffstat | 1 files changed, 14 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/util.py Thu Apr 13 17:12:09 2006 -0700 +++ b/mercurial/util.py Thu Apr 13 17:42:49 2006 -0700 @@ -71,10 +71,23 @@ return fn(s, cmd[len(name):].lstrip()) return pipefilter(s, cmd) +def find_in_path(name, path, default=None): + '''find name in search path. path can be string (will be split + with os.pathsep), or iterable thing that returns strings. if name + found, return path to name. else return default.''' + if isinstance(path, str): + path = path.split(os.pathsep) + for p in path: + p_name = os.path.join(p, name) + if os.path.exists(p_name): + return p_name + return default + def patch(strip, patchname, ui): """apply the patch <patchname> to the working directory. a list of patched files is returned""" - fp = os.popen('patch -p%d < "%s"' % (strip, patchname)) + patcher = find_in_path('gpatch', os.environ.get('PATH', ''), 'patch') + fp = os.popen('"%s" -p%d < "%s"' % (patcher, strip, patchname)) files = {} for line in fp: line = line.rstrip()