diff mercurial/util.py @ 2760:e6bef16b6cec

import: make patch apply if run in subdir fix is same as for mq patch. patch apply code should be merged.
author Vadim Gelfer <vadim.gelfer@gmail.com>
date Tue, 01 Aug 2006 15:51:13 -0700
parents 386f04d6ecb3
children f4d916351366
line wrap: on
line diff
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -93,11 +93,15 @@ def find_in_path(name, path, default=Non
             return p_name
     return default
 
-def patch(strip, patchname, ui):
+def patch(strip, patchname, ui, cwd=None):
     """apply the patch <patchname> to the working directory.
     a list of patched files is returned"""
     patcher = find_in_path('gpatch', os.environ.get('PATH', ''), 'patch')
-    fp = os.popen('%s -p%d < "%s"' % (patcher, strip, patchname))
+    args = []
+    if cwd:
+        args.append('-d "%s"' % cwd)
+    fp = os.popen('%s %s -p%d < "%s"' % (patcher, ' '.join(args), strip,
+                                         patchname))
     files = {}
     for line in fp:
         line = line.rstrip()