Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/util.py @ 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 | 547ede0123a2 |
children | f71e9656524f |
comparison
equal
deleted
inserted
replaced
2070:4bce7e8bb42b | 2071:67a0a3852024 |
---|---|
69 for name, fn in filtertable.iteritems(): | 69 for name, fn in filtertable.iteritems(): |
70 if cmd.startswith(name): | 70 if cmd.startswith(name): |
71 return fn(s, cmd[len(name):].lstrip()) | 71 return fn(s, cmd[len(name):].lstrip()) |
72 return pipefilter(s, cmd) | 72 return pipefilter(s, cmd) |
73 | 73 |
74 def find_in_path(name, path, default=None): | |
75 '''find name in search path. path can be string (will be split | |
76 with os.pathsep), or iterable thing that returns strings. if name | |
77 found, return path to name. else return default.''' | |
78 if isinstance(path, str): | |
79 path = path.split(os.pathsep) | |
80 for p in path: | |
81 p_name = os.path.join(p, name) | |
82 if os.path.exists(p_name): | |
83 return p_name | |
84 return default | |
85 | |
74 def patch(strip, patchname, ui): | 86 def patch(strip, patchname, ui): |
75 """apply the patch <patchname> to the working directory. | 87 """apply the patch <patchname> to the working directory. |
76 a list of patched files is returned""" | 88 a list of patched files is returned""" |
77 fp = os.popen('patch -p%d < "%s"' % (strip, patchname)) | 89 patcher = find_in_path('gpatch', os.environ.get('PATH', ''), 'patch') |
90 fp = os.popen('"%s" -p%d < "%s"' % (patcher, strip, patchname)) | |
78 files = {} | 91 files = {} |
79 for line in fp: | 92 for line in fp: |
80 line = line.rstrip() | 93 line = line.rstrip() |
81 ui.status("%s\n" % line) | 94 ui.status("%s\n" % line) |
82 if line.startswith('patching file '): | 95 if line.startswith('patching file '): |