3698 cmdutil.checkunfinished(repo) |
3694 cmdutil.checkunfinished(repo) |
3699 if (opts.get('exact') or not opts.get('force')) and update: |
3695 if (opts.get('exact') or not opts.get('force')) and update: |
3700 cmdutil.bailifchanged(repo) |
3696 cmdutil.bailifchanged(repo) |
3701 |
3697 |
3702 base = opts["base"] |
3698 base = opts["base"] |
3703 strip = opts["strip"] |
|
3704 wlock = lock = tr = None |
3699 wlock = lock = tr = None |
3705 msgs = [] |
3700 msgs = [] |
3706 |
3701 |
3707 def tryone(ui, hunk, parents): |
|
3708 tmpname, message, user, date, branch, nodeid, p1, p2 = \ |
|
3709 patch.extract(ui, hunk) |
|
3710 |
|
3711 if not tmpname: |
|
3712 return (None, None) |
|
3713 msg = _('applied to working directory') |
|
3714 |
|
3715 try: |
|
3716 cmdline_message = cmdutil.logmessage(ui, opts) |
|
3717 if cmdline_message: |
|
3718 # pickup the cmdline msg |
|
3719 message = cmdline_message |
|
3720 elif message: |
|
3721 # pickup the patch msg |
|
3722 message = message.strip() |
|
3723 else: |
|
3724 # launch the editor |
|
3725 message = None |
|
3726 ui.debug('message:\n%s\n' % message) |
|
3727 |
|
3728 if len(parents) == 1: |
|
3729 parents.append(repo[nullid]) |
|
3730 if opts.get('exact'): |
|
3731 if not nodeid or not p1: |
|
3732 raise util.Abort(_('not a Mercurial patch')) |
|
3733 p1 = repo[p1] |
|
3734 p2 = repo[p2 or nullid] |
|
3735 elif p2: |
|
3736 try: |
|
3737 p1 = repo[p1] |
|
3738 p2 = repo[p2] |
|
3739 # Without any options, consider p2 only if the |
|
3740 # patch is being applied on top of the recorded |
|
3741 # first parent. |
|
3742 if p1 != parents[0]: |
|
3743 p1 = parents[0] |
|
3744 p2 = repo[nullid] |
|
3745 except error.RepoError: |
|
3746 p1, p2 = parents |
|
3747 else: |
|
3748 p1, p2 = parents |
|
3749 |
|
3750 n = None |
|
3751 if update: |
|
3752 if p1 != parents[0]: |
|
3753 hg.clean(repo, p1.node()) |
|
3754 if p2 != parents[1]: |
|
3755 repo.setparents(p1.node(), p2.node()) |
|
3756 |
|
3757 if opts.get('exact') or opts.get('import_branch'): |
|
3758 repo.dirstate.setbranch(branch or 'default') |
|
3759 |
|
3760 files = set() |
|
3761 patch.patch(ui, repo, tmpname, strip=strip, files=files, |
|
3762 eolmode=None, similarity=sim / 100.0) |
|
3763 files = list(files) |
|
3764 if opts.get('no_commit'): |
|
3765 if message: |
|
3766 msgs.append(message) |
|
3767 else: |
|
3768 if opts.get('exact') or p2: |
|
3769 # If you got here, you either use --force and know what |
|
3770 # you are doing or used --exact or a merge patch while |
|
3771 # being updated to its first parent. |
|
3772 m = None |
|
3773 else: |
|
3774 m = scmutil.matchfiles(repo, files or []) |
|
3775 n = repo.commit(message, opts.get('user') or user, |
|
3776 opts.get('date') or date, match=m, |
|
3777 editor=editor) |
|
3778 else: |
|
3779 if opts.get('exact') or opts.get('import_branch'): |
|
3780 branch = branch or 'default' |
|
3781 else: |
|
3782 branch = p1.branch() |
|
3783 store = patch.filestore() |
|
3784 try: |
|
3785 files = set() |
|
3786 try: |
|
3787 patch.patchrepo(ui, repo, p1, store, tmpname, strip, |
|
3788 files, eolmode=None) |
|
3789 except patch.PatchError, e: |
|
3790 raise util.Abort(str(e)) |
|
3791 memctx = context.makememctx(repo, (p1.node(), p2.node()), |
|
3792 message, |
|
3793 opts.get('user') or user, |
|
3794 opts.get('date') or date, |
|
3795 branch, files, store, |
|
3796 editor=cmdutil.commiteditor) |
|
3797 repo.savecommitmessage(memctx.description()) |
|
3798 n = memctx.commit() |
|
3799 finally: |
|
3800 store.close() |
|
3801 if opts.get('exact') and hex(n) != nodeid: |
|
3802 raise util.Abort(_('patch is damaged or loses information')) |
|
3803 if n: |
|
3804 # i18n: refers to a short changeset id |
|
3805 msg = _('created %s') % short(n) |
|
3806 return (msg, n) |
|
3807 finally: |
|
3808 os.unlink(tmpname) |
|
3809 |
3702 |
3810 try: |
3703 try: |
3811 try: |
3704 try: |
3812 wlock = repo.wlock() |
3705 wlock = repo.wlock() |
3813 if not opts.get('no_commit'): |
3706 if not opts.get('no_commit'): |
3824 ui.status(_('applying %s\n') % patchurl) |
3717 ui.status(_('applying %s\n') % patchurl) |
3825 patchfile = hg.openpath(ui, patchurl) |
3718 patchfile = hg.openpath(ui, patchurl) |
3826 |
3719 |
3827 haspatch = False |
3720 haspatch = False |
3828 for hunk in patch.split(patchfile): |
3721 for hunk in patch.split(patchfile): |
3829 (msg, node) = tryone(ui, hunk, parents) |
3722 (msg, node) = cmdutil.tryimportone(ui, repo, hunk, parents, |
|
3723 opts, msgs, hg.clean) |
3830 if msg: |
3724 if msg: |
3831 haspatch = True |
3725 haspatch = True |
3832 ui.note(msg + '\n') |
3726 ui.note(msg + '\n') |
3833 if update or opts.get('exact'): |
3727 if update or opts.get('exact'): |
3834 parents = repo.parents() |
3728 parents = repo.parents() |