diff mercurial/patch.py @ 4482: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 a764edb6fc95
children c927c568a5ad
line wrap: on
line diff
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -295,11 +295,13 @@ def patch(patchname, ui, strip=1, cwd=No
 
         args = []
         patcher = ui.config('ui', 'patch')
+        patcher = ((patcher and util.find_exe(patcher)) or
+                   util.find_exe('gpatch') or
+                   util.find_exe('patch'))
         if not patcher:
-            patcher = util.find_in_path('gpatch', os.environ.get('PATH', ''),
-                                        'patch')
-            if util.needbinarypatch():
-                args.append('--binary')
+            raise util.Abort(_('no patch command found in hgrc or PATH'))
+        if util.needbinarypatch():
+            args.append('--binary')
                                     
         if cwd:
             args.append('-d %s' % util.shellquote(cwd))
@@ -643,7 +645,7 @@ def export(repo, revs, template='hg-%h.p
         single(rev, seqno+1, fp)
 
 def diffstat(patchlines):
-    if not util.find_in_path('diffstat', os.environ.get('PATH', '')):
+    if not util.find_exe('diffstat'):
         return
     fd, name = tempfile.mkstemp(prefix="hg-patchbomb-", suffix=".txt")
     try: