import: use gpatch if present on system. patch is broken on solaris.
authorVadim Gelfer <vadim.gelfer@gmail.com>
Thu, 13 Apr 2006 17:42:49 -0700
changeset 2071 67a0a3852024
parent 2070 4bce7e8bb42b
child 2085 f71e9656524f
child 2086 8742352db413
import: use gpatch if present on system. patch is broken on solaris. fixes issue 205. add new useful function, util.find_in_path.
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 <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()