Show More
@@ -542,6 +542,131 b' def service(opts, parentfn=None, initfn=' | |||
|
542 | 542 | if runfn: |
|
543 | 543 | return runfn() |
|
544 | 544 | |
|
545 | def tryimportone(ui, repo, hunk, parents, opts, msgs, updatefunc): | |
|
546 | """Utility function used by commands.import to import a single patch | |
|
547 | ||
|
548 | This function is explicitly defined here to help the evolve extension to | |
|
549 | wrap this part of the import logic. | |
|
550 | ||
|
551 | The API is currently a bit ugly because it a simple code translation from | |
|
552 | the import command. Feel free to make it better. | |
|
553 | ||
|
554 | :hunk: a patch (as a binary string) | |
|
555 | :parents: nodes that will be parent of the created commit | |
|
556 | :opts: the full dict of option passed to the import command | |
|
557 | :msgs: list to save commit message to. | |
|
558 | (used in case we need to save it when failing) | |
|
559 | :updatefunc: a function that update a repo to a given node | |
|
560 | updatefunc(<repo>, <node>) | |
|
561 | """ | |
|
562 | tmpname, message, user, date, branch, nodeid, p1, p2 = \ | |
|
563 | patch.extract(ui, hunk) | |
|
564 | ||
|
565 | editor = commiteditor | |
|
566 | if opts.get('edit'): | |
|
567 | editor = commitforceeditor | |
|
568 | update = not opts.get('bypass') | |
|
569 | strip = opts["strip"] | |
|
570 | sim = float(opts.get('similarity') or 0) | |
|
571 | if not tmpname: | |
|
572 | return (None, None) | |
|
573 | msg = _('applied to working directory') | |
|
574 | ||
|
575 | try: | |
|
576 | cmdline_message = logmessage(ui, opts) | |
|
577 | if cmdline_message: | |
|
578 | # pickup the cmdline msg | |
|
579 | message = cmdline_message | |
|
580 | elif message: | |
|
581 | # pickup the patch msg | |
|
582 | message = message.strip() | |
|
583 | else: | |
|
584 | # launch the editor | |
|
585 | message = None | |
|
586 | ui.debug('message:\n%s\n' % message) | |
|
587 | ||
|
588 | if len(parents) == 1: | |
|
589 | parents.append(repo[nullid]) | |
|
590 | if opts.get('exact'): | |
|
591 | if not nodeid or not p1: | |
|
592 | raise util.Abort(_('not a Mercurial patch')) | |
|
593 | p1 = repo[p1] | |
|
594 | p2 = repo[p2 or nullid] | |
|
595 | elif p2: | |
|
596 | try: | |
|
597 | p1 = repo[p1] | |
|
598 | p2 = repo[p2] | |
|
599 | # Without any options, consider p2 only if the | |
|
600 | # patch is being applied on top of the recorded | |
|
601 | # first parent. | |
|
602 | if p1 != parents[0]: | |
|
603 | p1 = parents[0] | |
|
604 | p2 = repo[nullid] | |
|
605 | except error.RepoError: | |
|
606 | p1, p2 = parents | |
|
607 | else: | |
|
608 | p1, p2 = parents | |
|
609 | ||
|
610 | n = None | |
|
611 | if update: | |
|
612 | if p1 != parents[0]: | |
|
613 | updatefunc(repo, p1.node()) | |
|
614 | if p2 != parents[1]: | |
|
615 | repo.setparents(p1.node(), p2.node()) | |
|
616 | ||
|
617 | if opts.get('exact') or opts.get('import_branch'): | |
|
618 | repo.dirstate.setbranch(branch or 'default') | |
|
619 | ||
|
620 | files = set() | |
|
621 | patch.patch(ui, repo, tmpname, strip=strip, files=files, | |
|
622 | eolmode=None, similarity=sim / 100.0) | |
|
623 | files = list(files) | |
|
624 | if opts.get('no_commit'): | |
|
625 | if message: | |
|
626 | msgs.append(message) | |
|
627 | else: | |
|
628 | if opts.get('exact') or p2: | |
|
629 | # If you got here, you either use --force and know what | |
|
630 | # you are doing or used --exact or a merge patch while | |
|
631 | # being updated to its first parent. | |
|
632 | m = None | |
|
633 | else: | |
|
634 | m = scmutil.matchfiles(repo, files or []) | |
|
635 | n = repo.commit(message, opts.get('user') or user, | |
|
636 | opts.get('date') or date, match=m, | |
|
637 | editor=editor) | |
|
638 | else: | |
|
639 | if opts.get('exact') or opts.get('import_branch'): | |
|
640 | branch = branch or 'default' | |
|
641 | else: | |
|
642 | branch = p1.branch() | |
|
643 | store = patch.filestore() | |
|
644 | try: | |
|
645 | files = set() | |
|
646 | try: | |
|
647 | patch.patchrepo(ui, repo, p1, store, tmpname, strip, | |
|
648 | files, eolmode=None) | |
|
649 | except patch.PatchError, e: | |
|
650 | raise util.Abort(str(e)) | |
|
651 | memctx = context.makememctx(repo, (p1.node(), p2.node()), | |
|
652 | message, | |
|
653 | opts.get('user') or user, | |
|
654 | opts.get('date') or date, | |
|
655 | branch, files, store, | |
|
656 | editor=commiteditor) | |
|
657 | repo.savecommitmessage(memctx.description()) | |
|
658 | n = memctx.commit() | |
|
659 | finally: | |
|
660 | store.close() | |
|
661 | if opts.get('exact') and hex(n) != nodeid: | |
|
662 | raise util.Abort(_('patch is damaged or loses information')) | |
|
663 | if n: | |
|
664 | # i18n: refers to a short changeset id | |
|
665 | msg = _('created %s') % short(n) | |
|
666 | return (msg, n) | |
|
667 | finally: | |
|
668 | os.unlink(tmpname) | |
|
669 | ||
|
545 | 670 | def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False, |
|
546 | 671 | opts=None): |
|
547 | 672 | '''export changesets as hg patches.''' |
@@ -3678,10 +3678,6 b' def import_(ui, repo, patch1=None, *patc' | |||
|
3678 | 3678 | if date: |
|
3679 | 3679 | opts['date'] = util.parsedate(date) |
|
3680 | 3680 | |
|
3681 | editor = cmdutil.commiteditor | |
|
3682 | if opts.get('edit'): | |
|
3683 | editor = cmdutil.commitforceeditor | |
|
3684 | ||
|
3685 | 3681 | update = not opts.get('bypass') |
|
3686 | 3682 | if not update and opts.get('no_commit'): |
|
3687 | 3683 | raise util.Abort(_('cannot use --no-commit with --bypass')) |
@@ -3700,112 +3696,9 b' def import_(ui, repo, patch1=None, *patc' | |||
|
3700 | 3696 | cmdutil.bailifchanged(repo) |
|
3701 | 3697 | |
|
3702 | 3698 | base = opts["base"] |
|
3703 | strip = opts["strip"] | |
|
3704 | 3699 | wlock = lock = tr = None |
|
3705 | 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 | 3703 | try: |
|
3811 | 3704 | try: |
@@ -3826,7 +3719,8 b' def import_(ui, repo, patch1=None, *patc' | |||
|
3826 | 3719 | |
|
3827 | 3720 | haspatch = False |
|
3828 | 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 | 3724 | if msg: |
|
3831 | 3725 | haspatch = True |
|
3832 | 3726 | ui.note(msg + '\n') |
General Comments 0
You need to be logged in to leave comments.
Login now