4733 msgs = [] |
4733 msgs = [] |
4734 ret = 0 |
4734 ret = 0 |
4735 |
4735 |
4736 |
4736 |
4737 try: |
4737 try: |
4738 try: |
4738 wlock = repo.wlock() |
4739 wlock = repo.wlock() |
4739 |
4740 |
4740 if update: |
4741 if update: |
4741 cmdutil.checkunfinished(repo) |
4742 cmdutil.checkunfinished(repo) |
4742 if (exact or not opts.get('force')): |
4743 if (exact or not opts.get('force')): |
4743 cmdutil.bailifchanged(repo) |
4744 cmdutil.bailifchanged(repo) |
4744 |
4745 |
4745 if not opts.get('no_commit'): |
4746 if not opts.get('no_commit'): |
4746 lock = repo.lock() |
4747 lock = repo.lock() |
4747 tr = repo.transaction('import') |
4748 tr = repo.transaction('import') |
4748 else: |
|
4749 dsguard = cmdutil.dirstateguard(repo, 'import') |
|
4750 parents = repo[None].parents() |
|
4751 for patchurl in patches: |
|
4752 if patchurl == '-': |
|
4753 ui.status(_('applying patch from stdin\n')) |
|
4754 patchfile = ui.fin |
|
4755 patchurl = 'stdin' # for error message |
4749 else: |
4756 else: |
4750 dsguard = cmdutil.dirstateguard(repo, 'import') |
4757 patchurl = os.path.join(base, patchurl) |
4751 parents = repo[None].parents() |
4758 ui.status(_('applying %s\n') % patchurl) |
4752 for patchurl in patches: |
4759 patchfile = hg.openpath(ui, patchurl) |
4753 if patchurl == '-': |
4760 |
4754 ui.status(_('applying patch from stdin\n')) |
4761 haspatch = False |
4755 patchfile = ui.fin |
4762 for hunk in patch.split(patchfile): |
4756 patchurl = 'stdin' # for error message |
4763 (msg, node, rej) = cmdutil.tryimportone(ui, repo, hunk, |
|
4764 parents, opts, |
|
4765 msgs, hg.clean) |
|
4766 if msg: |
|
4767 haspatch = True |
|
4768 ui.note(msg + '\n') |
|
4769 if update or exact: |
|
4770 parents = repo[None].parents() |
4757 else: |
4771 else: |
4758 patchurl = os.path.join(base, patchurl) |
4772 parents = [repo[node]] |
4759 ui.status(_('applying %s\n') % patchurl) |
4773 if rej: |
4760 patchfile = hg.openpath(ui, patchurl) |
4774 ui.write_err(_("patch applied partially\n")) |
4761 |
4775 ui.write_err(_("(fix the .rej files and run " |
4762 haspatch = False |
4776 "`hg commit --amend`)\n")) |
4763 for hunk in patch.split(patchfile): |
4777 ret = 1 |
4764 (msg, node, rej) = cmdutil.tryimportone(ui, repo, hunk, |
4778 break |
4765 parents, opts, |
4779 |
4766 msgs, hg.clean) |
4780 if not haspatch: |
4767 if msg: |
4781 raise error.Abort(_('%s: no diffs found') % patchurl) |
4768 haspatch = True |
4782 |
4769 ui.note(msg + '\n') |
4783 if tr: |
4770 if update or exact: |
4784 tr.close() |
4771 parents = repo[None].parents() |
4785 if msgs: |
4772 else: |
4786 repo.savecommitmessage('\n* * *\n'.join(msgs)) |
4773 parents = [repo[node]] |
4787 if dsguard: |
4774 if rej: |
4788 dsguard.close() |
4775 ui.write_err(_("patch applied partially\n")) |
4789 return ret |
4776 ui.write_err(_("(fix the .rej files and run " |
|
4777 "`hg commit --amend`)\n")) |
|
4778 ret = 1 |
|
4779 break |
|
4780 |
|
4781 if not haspatch: |
|
4782 raise error.Abort(_('%s: no diffs found') % patchurl) |
|
4783 |
|
4784 if tr: |
|
4785 tr.close() |
|
4786 if msgs: |
|
4787 repo.savecommitmessage('\n* * *\n'.join(msgs)) |
|
4788 if dsguard: |
|
4789 dsguard.close() |
|
4790 return ret |
|
4791 finally: |
|
4792 # TODO: get rid of this meaningless try/finally enclosing. |
|
4793 # this is kept only to reduce changes in a patch. |
|
4794 pass |
|
4795 finally: |
4790 finally: |
4796 if tr: |
4791 if tr: |
4797 tr.release() |
4792 tr.release() |
4798 release(lock, dsguard, wlock) |
4793 release(lock, dsguard, wlock) |
4799 |
4794 |