# HG changeset patch # User Vadim Gelfer # Date 1144975369 25200 # Node ID 67a0a38520246c8148c583689840d74adcaeb8c8 # Parent 4bce7e8bb42bc48ba266a3d6c6780175acd32176 import: use gpatch if present on system. patch is broken on solaris. fixes issue 205. add new useful function, util.find_in_path. diff -r 4bce7e8bb42b -r 67a0a3852024 mercurial/util.py --- 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 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()