comparison 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
comparison
equal deleted inserted replaced
2759:19436facb073 2760:e6bef16b6cec
91 p_name = os.path.join(p, name) 91 p_name = os.path.join(p, name)
92 if os.path.exists(p_name): 92 if os.path.exists(p_name):
93 return p_name 93 return p_name
94 return default 94 return default
95 95
96 def patch(strip, patchname, ui): 96 def patch(strip, patchname, ui, cwd=None):
97 """apply the patch <patchname> to the working directory. 97 """apply the patch <patchname> to the working directory.
98 a list of patched files is returned""" 98 a list of patched files is returned"""
99 patcher = find_in_path('gpatch', os.environ.get('PATH', ''), 'patch') 99 patcher = find_in_path('gpatch', os.environ.get('PATH', ''), 'patch')
100 fp = os.popen('%s -p%d < "%s"' % (patcher, strip, patchname)) 100 args = []
101 if cwd:
102 args.append('-d "%s"' % cwd)
103 fp = os.popen('%s %s -p%d < "%s"' % (patcher, ' '.join(args), strip,
104 patchname))
101 files = {} 105 files = {}
102 for line in fp: 106 for line in fp:
103 line = line.rstrip() 107 line = line.rstrip()
104 ui.status("%s\n" % line) 108 ui.status("%s\n" % line)
105 if line.startswith('patching file '): 109 if line.startswith('patching file '):