Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/patch.py @ 3465:2d35a8d2b32d
patch: return list of modified files even when an exception is raised
The file list is passed in as an argument and updated in place.
This fixes issue399.
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Wed, 18 Oct 2006 10:37:34 -0700 |
parents | 2065789f6a3e |
children | 0e68608bd11d |
comparison
equal
deleted
inserted
replaced
3464:ba3a96750de0 | 3465:2d35a8d2b32d |
---|---|
264 raise | 264 raise |
265 | 265 |
266 tmpfp.close() | 266 tmpfp.close() |
267 return patchname | 267 return patchname |
268 | 268 |
269 def patch(patchname, ui, strip=1, cwd=None): | 269 def patch(patchname, ui, strip=1, cwd=None, files={}): |
270 """apply the patch <patchname> to the working directory. | 270 """apply the patch <patchname> to the working directory. |
271 a list of patched files is returned""" | 271 a list of patched files is returned""" |
272 | 272 |
273 # helper function | 273 # helper function |
274 def __patch(patchname): | 274 def __patch(patchname): |
275 """patch and updates the files and fuzz variables""" | 275 """patch and updates the files and fuzz variables""" |
276 files = {} | |
277 fuzz = False | 276 fuzz = False |
278 | 277 |
279 patcher = util.find_in_path('gpatch', os.environ.get('PATH', ''), | 278 patcher = util.find_in_path('gpatch', os.environ.get('PATH', ''), |
280 'patch') | 279 'patch') |
281 args = [] | 280 args = [] |
306 ui.warn(line + '\n') | 305 ui.warn(line + '\n') |
307 code = fp.close() | 306 code = fp.close() |
308 if code: | 307 if code: |
309 raise util.Abort(_("patch command failed: %s") % | 308 raise util.Abort(_("patch command failed: %s") % |
310 util.explain_exit(code)[0]) | 309 util.explain_exit(code)[0]) |
311 return files, fuzz | 310 return fuzz |
312 | 311 |
313 (dopatch, gitpatches) = readgitpatch(patchname) | 312 (dopatch, gitpatches) = readgitpatch(patchname) |
314 | 313 for gp in gitpatches: |
315 files, fuzz = {}, False | 314 files[gp.path] = (gp.op, gp) |
315 | |
316 fuzz = False | |
316 if dopatch: | 317 if dopatch: |
317 if dopatch in ('filter', 'binary'): | 318 if dopatch in ('filter', 'binary'): |
318 patchname = dogitpatch(patchname, gitpatches, cwd=cwd) | 319 patchname = dogitpatch(patchname, gitpatches, cwd=cwd) |
319 try: | 320 try: |
320 if dopatch != 'binary': | 321 if dopatch != 'binary': |
321 files, fuzz = __patch(patchname) | 322 fuzz = __patch(patchname) |
322 finally: | 323 finally: |
323 if dopatch == 'filter': | 324 if dopatch == 'filter': |
324 os.unlink(patchname) | 325 os.unlink(patchname) |
325 | 326 |
326 for gp in gitpatches: | 327 return fuzz |
327 files[gp.path] = (gp.op, gp) | |
328 | |
329 return (files, fuzz) | |
330 | 328 |
331 def diffopts(ui, opts={}): | 329 def diffopts(ui, opts={}): |
332 return mdiff.diffopts( | 330 return mdiff.diffopts( |
333 text=opts.get('text'), | 331 text=opts.get('text'), |
334 git=(opts.get('git') or | 332 git=(opts.get('git') or |