3541 return (msg, n) |
3541 return (msg, n) |
3542 finally: |
3542 finally: |
3543 os.unlink(tmpname) |
3543 os.unlink(tmpname) |
3544 |
3544 |
3545 try: |
3545 try: |
3546 wlock = repo.wlock() |
3546 try: |
3547 lock = repo.lock() |
3547 wlock = repo.wlock() |
3548 tr = repo.transaction('import') |
3548 lock = repo.lock() |
3549 parents = repo.parents() |
3549 tr = repo.transaction('import') |
3550 for patchurl in patches: |
3550 parents = repo.parents() |
3551 if patchurl == '-': |
3551 for patchurl in patches: |
3552 ui.status(_('applying patch from stdin\n')) |
3552 if patchurl == '-': |
3553 patchfile = ui.fin |
3553 ui.status(_('applying patch from stdin\n')) |
3554 patchurl = 'stdin' # for error message |
3554 patchfile = ui.fin |
3555 else: |
3555 patchurl = 'stdin' # for error message |
3556 patchurl = os.path.join(base, patchurl) |
|
3557 ui.status(_('applying %s\n') % patchurl) |
|
3558 patchfile = url.open(ui, patchurl) |
|
3559 |
|
3560 haspatch = False |
|
3561 for hunk in patch.split(patchfile): |
|
3562 (msg, node) = tryone(ui, hunk, parents) |
|
3563 if msg: |
|
3564 haspatch = True |
|
3565 ui.note(msg + '\n') |
|
3566 if update or opts.get('exact'): |
|
3567 parents = repo.parents() |
|
3568 else: |
3556 else: |
3569 parents = [repo[node]] |
3557 patchurl = os.path.join(base, patchurl) |
3570 |
3558 ui.status(_('applying %s\n') % patchurl) |
3571 if not haspatch: |
3559 patchfile = url.open(ui, patchurl) |
3572 raise util.Abort(_('%s: no diffs found') % patchurl) |
3560 |
3573 |
3561 haspatch = False |
3574 tr.close() |
3562 for hunk in patch.split(patchfile): |
3575 if msgs: |
3563 (msg, node) = tryone(ui, hunk, parents) |
3576 repo.savecommitmessage('\n* * *\n'.join(msgs)) |
3564 if msg: |
3577 except: |
3565 haspatch = True |
3578 # wlock.release() indirectly calls dirstate.write(): since |
3566 ui.note(msg + '\n') |
3579 # we're crashing, we do not want to change the working dir |
3567 if update or opts.get('exact'): |
3580 # parent after all, so make sure it writes nothing |
3568 parents = repo.parents() |
3581 repo.dirstate.invalidate() |
3569 else: |
3582 raise |
3570 parents = [repo[node]] |
|
3571 |
|
3572 if not haspatch: |
|
3573 raise util.Abort(_('%s: no diffs found') % patchurl) |
|
3574 |
|
3575 tr.close() |
|
3576 if msgs: |
|
3577 repo.savecommitmessage('\n* * *\n'.join(msgs)) |
|
3578 except: |
|
3579 # wlock.release() indirectly calls dirstate.write(): since |
|
3580 # we're crashing, we do not want to change the working dir |
|
3581 # parent after all, so make sure it writes nothing |
|
3582 repo.dirstate.invalidate() |
|
3583 raise |
3583 finally: |
3584 finally: |
3584 if tr: |
3585 if tr: |
3585 tr.release() |
3586 tr.release() |
3586 release(lock, wlock) |
3587 release(lock, wlock) |
3587 |
3588 |