~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: John Arbash Meinel
  • Date: 2007-07-20 17:34:48 UTC
  • mfrom: (2641 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2643.
  • Revision ID: john@arbash-meinel.com-20070720173448-cn7og836bl8dovwv
[merge] bzr.dev 2641

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
    urlutils,
54
54
    )
55
55
from bzrlib.branch import Branch
56
 
from bzrlib.bundle.apply_bundle import install_bundle, merge_bundle
57
56
from bzrlib.conflicts import ConflictList
58
57
from bzrlib.revisionspec import RevisionSpec
59
58
from bzrlib.smtp_connection import SMTPConnection
618
617
            if revision is not None:
619
618
                raise errors.BzrCommandError(
620
619
                    'Cannot use -r with merge directives or bundles')
621
 
            revision_id = mergeable.install_revisions(branch_to.repository)
 
620
            mergeable.install_revisions(branch_to.repository)
 
621
            base_revision_id, revision_id, verified = \
 
622
                mergeable.get_merge_request(branch_to.repository)
622
623
            branch_from = branch_to
623
624
        else:
624
625
            branch_from = Branch.open(location)
633
634
                raise errors.BzrCommandError(
634
635
                    'bzr pull --revision takes one value.')
635
636
 
636
 
        old_rh = branch_to.revision_history()
 
637
        if verbose:
 
638
            old_rh = branch_to.revision_history()
637
639
        if tree_to is not None:
638
640
            result = tree_to.pull(branch_from, overwrite, revision_id,
639
641
                delta._ChangeReporter(unversioned_filter=tree_to.is_ignored))
735
737
                # Found a branch, so we must have found a repository
736
738
                repository_to = br_to.repository
737
739
        push_result = None
738
 
        old_rh = []
 
740
        if verbose:
 
741
            old_rh = []
739
742
        if dir_to is None:
740
743
            # The destination doesn't exist; create it.
741
744
            # XXX: Refactor the create_prefix/no_create_prefix code into a
791
794
            # we don't need to successfully push because of possible divergence.
792
795
            if br_from.get_push_location() is None or remember:
793
796
                br_from.set_push_location(br_to.base)
794
 
            old_rh = br_to.revision_history()
 
797
            if verbose:
 
798
                old_rh = br_to.revision_history()
795
799
            try:
796
800
                try:
797
801
                    tree_to = dir_to.open_workingtree()
1010
1014
    'bzr revert' instead of 'bzr commit' after the update.
1011
1015
    """
1012
1016
 
1013
 
    _see_also = ['pull', 'working-trees']
 
1017
    _see_also = ['pull', 'working-trees', 'status-flags']
1014
1018
    takes_args = ['dir?']
1015
1019
    aliases = ['up']
1016
1020
 
2638
2642
            ):
2639
2643
        from bzrlib.tag import _merge_tags_if_possible
2640
2644
        other_revision_id = None
 
2645
        base_revision_id = None
2641
2646
        if merge_type is None:
2642
2647
            merge_type = _mod_merge.Merge3Merger
2643
2648
 
2663
2668
                if revision is not None:
2664
2669
                    raise errors.BzrCommandError(
2665
2670
                        'Cannot use -r with merge directives or bundles')
2666
 
                other_revision_id = mergeable.install_revisions(
2667
 
                    tree.branch.repository)
2668
 
                revision = [RevisionSpec.from_string(
2669
 
                    'revid:' + other_revision_id)]
2670
 
 
2671
 
        if revision is None \
2672
 
                or len(revision) < 1 or revision[0].needs_branch():
2673
 
            branch = self._get_remembered_parent(tree, branch, 'Merging from')
2674
 
 
2675
 
        if revision is None or len(revision) < 1:
2676
 
            if uncommitted:
2677
 
                base = [branch, -1]
2678
 
                other = [branch, None]
 
2671
                mergeable.install_revisions(tree.branch.repository)
 
2672
                base_revision_id, other_revision_id, verified =\
 
2673
                    mergeable.get_merge_request(tree.branch.repository)
 
2674
                if base_revision_id in tree.branch.repository.get_ancestry(
 
2675
                    tree.branch.last_revision(), topo_sorted=False):
 
2676
                    base_revision_id = None
 
2677
                other_branch = None
 
2678
                path = ''
 
2679
                other = None
 
2680
                base = None
 
2681
 
 
2682
        if other_revision_id is None:
 
2683
            verified = 'inapplicable'
 
2684
            if revision is None \
 
2685
                    or len(revision) < 1 or revision[0].needs_branch():
 
2686
                branch = self._get_remembered_parent(tree, branch,
 
2687
                    'Merging from')
 
2688
 
 
2689
            if revision is None or len(revision) < 1:
 
2690
                if uncommitted:
 
2691
                    base = [branch, -1]
 
2692
                    other = [branch, None]
 
2693
                else:
 
2694
                    base = [None, None]
 
2695
                    other = [branch, -1]
 
2696
                other_branch, path = Branch.open_containing(branch)
2679
2697
            else:
2680
 
                base = [None, None]
2681
 
                other = [branch, -1]
2682
 
            other_branch, path = Branch.open_containing(branch)
2683
 
        else:
2684
 
            if uncommitted:
2685
 
                raise errors.BzrCommandError('Cannot use --uncommitted and'
2686
 
                                             ' --revision at the same time.')
2687
 
            branch = revision[0].get_branch() or branch
2688
 
            if len(revision) == 1:
2689
 
                base = [None, None]
2690
 
                if other_revision_id is not None:
2691
 
                    other_branch = None
2692
 
                    path = ""
2693
 
                    other = None
2694
 
                else:
 
2698
                if uncommitted:
 
2699
                    raise errors.BzrCommandError('Cannot use --uncommitted and'
 
2700
                        ' --revision at the same time.')
 
2701
                branch = revision[0].get_branch() or branch
 
2702
                if len(revision) == 1:
 
2703
                    base = [None, None]
2695
2704
                    other_branch, path = Branch.open_containing(branch)
2696
2705
                    revno = revision[0].in_history(other_branch).revno
2697
2706
                    other = [branch, revno]
2698
 
            else:
2699
 
                assert len(revision) == 2
2700
 
                if None in revision:
2701
 
                    raise errors.BzrCommandError(
2702
 
                        "Merge doesn't permit empty revision specifier.")
2703
 
                base_branch, path = Branch.open_containing(branch)
2704
 
                branch1 = revision[1].get_branch() or branch
2705
 
                other_branch, path1 = Branch.open_containing(branch1)
2706
 
                if revision[0].get_branch() is not None:
2707
 
                    # then path was obtained from it, and is None.
2708
 
                    path = path1
 
2707
                else:
 
2708
                    assert len(revision) == 2
 
2709
                    if None in revision:
 
2710
                        raise errors.BzrCommandError(
 
2711
                            "Merge doesn't permit empty revision specifier.")
 
2712
                    base_branch, path = Branch.open_containing(branch)
 
2713
                    branch1 = revision[1].get_branch() or branch
 
2714
                    other_branch, path1 = Branch.open_containing(branch1)
 
2715
                    if revision[0].get_branch() is not None:
 
2716
                        # then path was obtained from it, and is None.
 
2717
                        path = path1
2709
2718
 
2710
 
                base = [branch, revision[0].in_history(base_branch).revno]
2711
 
                other = [branch1, revision[1].in_history(other_branch).revno]
 
2719
                    base = [branch, revision[0].in_history(base_branch).revno]
 
2720
                    other = [branch1,
 
2721
                             revision[1].in_history(other_branch).revno]
2712
2722
 
2713
2723
        if ((tree.branch.get_parent() is None or remember) and
2714
2724
            other_branch is not None):
2728
2738
            try:
2729
2739
                conflict_count = _merge_helper(
2730
2740
                    other, base, other_rev_id=other_revision_id,
 
2741
                    base_rev_id=base_revision_id,
2731
2742
                    check_clean=(not force),
2732
2743
                    merge_type=merge_type,
2733
2744
                    reprocess=reprocess,
2738
2749
                    change_reporter=change_reporter)
2739
2750
            finally:
2740
2751
                pb.finished()
 
2752
            if verified == 'failed':
 
2753
                warning('Preview patch does not match changes')
2741
2754
            if conflict_count != 0:
2742
2755
                return 1
2743
2756
            else:
2844
2857
                    restore(tree.abspath(filename))
2845
2858
                except errors.NotConflicted:
2846
2859
                    pass
2847
 
            conflicts = _mod_merge.merge_inner(
2848
 
                                      tree.branch, other_tree, base_tree,
2849
 
                                      this_tree=tree,
2850
 
                                      interesting_ids=interesting_ids,
2851
 
                                      other_rev_id=parents[1],
2852
 
                                      merge_type=merge_type,
2853
 
                                      show_base=show_base,
2854
 
                                      reprocess=reprocess)
 
2860
            # Disable pending merges, because the file texts we are remerging
 
2861
            # have not had those merges performed.  If we use the wrong parents
 
2862
            # list, we imply that the working tree text has seen and rejected
 
2863
            # all the changes from the other tree, when in fact those changes
 
2864
            # have not yet been seen.
 
2865
            tree.set_parent_ids(parents[:1])
 
2866
            try:
 
2867
                conflicts = _mod_merge.merge_inner(
 
2868
                                          tree.branch, other_tree, base_tree,
 
2869
                                          this_tree=tree,
 
2870
                                          interesting_ids=interesting_ids,
 
2871
                                          other_rev_id=parents[1],
 
2872
                                          merge_type=merge_type,
 
2873
                                          show_base=show_base,
 
2874
                                          reprocess=reprocess)
 
2875
            finally:
 
2876
                tree.set_parent_ids(parents)
2855
2877
        finally:
2856
2878
            tree.unlock()
2857
2879
        if conflicts > 0:
3086
3108
 
3087
3109
 
3088
3110
class cmd_plugins(Command):
3089
 
    """List plugins"""
3090
 
    hidden = True
 
3111
    """List the installed plugins.
 
3112
    
 
3113
    This command displays the list of installed plugins including the
 
3114
    path where each one is located and a short description of each.
 
3115
 
 
3116
    A plugin is an external component for Bazaar that extends the
 
3117
    revision control system, by adding or replacing code in Bazaar.
 
3118
    Plugins can do a variety of things, including overriding commands,
 
3119
    adding new commands, providing additional network transports and
 
3120
    customizing log output.
 
3121
 
 
3122
    See the Bazaar web site, http://bazaar-vcs.org, for further
 
3123
    information on plugins including where to find them and how to
 
3124
    install them. Instructions are also provided there on how to
 
3125
    write new plugins using the Python programming language.
 
3126
    """
 
3127
 
3091
3128
    @display_command
3092
3129
    def run(self):
3093
3130
        import bzrlib.plugin
3556
3593
 
3557
3594
    takes_args = ['submit_branch?', 'public_branch?']
3558
3595
 
 
3596
    hidden = True
 
3597
 
 
3598
    _see_also = ['submit']
 
3599
 
3559
3600
    takes_options = [
3560
3601
        RegistryOption.from_kwargs('patch-type',
3561
3602
            'The type of patch to include in the directive',
3577
3618
    def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
3578
3619
            sign=False, revision=None, mail_to=None, message=None):
3579
3620
        from bzrlib.revision import ensure_null, NULL_REVISION
3580
 
        if patch_type == 'plain':
3581
 
            patch_type = None
 
3621
        include_patch, include_bundle = {
 
3622
            'plain': (False, False),
 
3623
            'diff': (True, False),
 
3624
            'bundle': (True, True),
 
3625
            }[patch_type]
3582
3626
        branch = Branch.open('.')
3583
3627
        stored_submit_branch = branch.get_submit_branch()
3584
3628
        if submit_branch is None:
3596
3640
            public_branch = stored_public_branch
3597
3641
        elif stored_public_branch is None:
3598
3642
            branch.set_public_branch(public_branch)
3599
 
        if patch_type != "bundle" and public_branch is None:
 
3643
        if not include_bundle and public_branch is None:
3600
3644
            raise errors.BzrCommandError('No public branch specified or'
3601
3645
                                         ' known')
 
3646
        base_revision_id = None
3602
3647
        if revision is not None:
3603
 
            if len(revision) != 1:
 
3648
            if len(revision) > 2:
3604
3649
                raise errors.BzrCommandError('bzr merge-directive takes '
3605
 
                    'exactly one revision identifier')
3606
 
            else:
3607
 
                revision_id = revision[0].in_history(branch).rev_id
 
3650
                    'at most two one revision identifiers')
 
3651
            revision_id = revision[-1].in_history(branch).rev_id
 
3652
            if len(revision) == 2:
 
3653
                base_revision_id = revision[0].in_history(branch).rev_id
 
3654
                base_revision_id = ensure_null(base_revision_id)
3608
3655
        else:
3609
3656
            revision_id = branch.last_revision()
3610
3657
        revision_id = ensure_null(revision_id)
3611
3658
        if revision_id == NULL_REVISION:
3612
3659
            raise errors.BzrCommandError('No revisions to bundle.')
3613
 
        directive = merge_directive.MergeDirective.from_objects(
 
3660
        directive = merge_directive.MergeDirective2.from_objects(
3614
3661
            branch.repository, revision_id, time.time(),
3615
3662
            osutils.local_time_offset(), submit_branch,
3616
 
            public_branch=public_branch, patch_type=patch_type,
3617
 
            message=message)
 
3663
            public_branch=public_branch, include_patch=include_patch,
 
3664
            include_bundle=include_bundle, message=message,
 
3665
            base_revision_id=base_revision_id)
3618
3666
        if mail_to is None:
3619
3667
            if sign:
3620
3668
                self.outf.write(directive.to_signed(branch))
3626
3674
            s.send_email(message)
3627
3675
 
3628
3676
 
 
3677
class cmd_submit(Command):
 
3678
    """Create a merge-directive for submiting changes.
 
3679
 
 
3680
    A merge directive provides many things needed for requesting merges:
 
3681
    - A machine-readable description of the merge to perform
 
3682
    - An optional patch that is a preview of the changes requested
 
3683
    - An optional bundle of revision data, so that the changes can be applied
 
3684
      directly from the merge directive, without retrieving data from a
 
3685
      branch.
 
3686
 
 
3687
    If --no-bundle is specified, then public_branch is needed (and must be
 
3688
    up-to-date), so that the receiver can perform the merge using the
 
3689
    public_branch.  The public_branch is always included if known, so that
 
3690
    people can check it later.
 
3691
 
 
3692
    The submit branch defaults to the parent, but can be overridden.  Both
 
3693
    submit branch and public branch will be remembered if supplied.
 
3694
 
 
3695
    If a public_branch is known for the submit_branch, that public submit
 
3696
    branch is used in the merge instructions.  This means that a local mirror
 
3697
    can be used as your actual submit branch, once you have set public_branch
 
3698
    for that mirror.
 
3699
    """
 
3700
 
 
3701
    encoding_type = 'exact'
 
3702
 
 
3703
    aliases = ['bundle', 'bundle-revisions']
 
3704
 
 
3705
    _see_also = ['merge']
 
3706
 
 
3707
    takes_args = ['submit_branch?', 'public_branch?']
 
3708
    takes_options = [
 
3709
        Option('no-bundle',
 
3710
               help='Do not include a bundle in the merge directive.'),
 
3711
        Option('no-patch', help='Do not include a preview patch in the merge'
 
3712
               ' directive.'),
 
3713
        Option('remember',
 
3714
               help='Remember submit and public branch.'),
 
3715
        Option('from',
 
3716
               help='Branch to generate the submission from, '
 
3717
               'rather than the one containing the working directory.',
 
3718
               short_name='f',
 
3719
               type=unicode),
 
3720
        Option('output', short_name='o', help='Write directive to this file.',
 
3721
               type=unicode),
 
3722
        'revision',
 
3723
        ]
 
3724
 
 
3725
    def run(self, submit_branch=None, public_branch=None, no_bundle=False,
 
3726
            no_patch=False, revision=None, remember=False, output=None,
 
3727
            **kwargs):
 
3728
        from bzrlib.revision import ensure_null, NULL_REVISION
 
3729
        if output is None:
 
3730
            outfile = self.outf
 
3731
        else:
 
3732
            outfile = open(output, 'wb')
 
3733
        try:
 
3734
            from_ = kwargs.get('from', '.')
 
3735
            branch = Branch.open_containing(from_)[0]
 
3736
            if remember and submit_branch is None:
 
3737
                raise errors.BzrCommandError(
 
3738
                    '--remember requires a branch to be specified.')
 
3739
            stored_submit_branch = branch.get_submit_branch()
 
3740
            remembered_submit_branch = False
 
3741
            if submit_branch is None:
 
3742
                submit_branch = stored_submit_branch
 
3743
                remembered_submit_branch = True
 
3744
            else:
 
3745
                if stored_submit_branch is None or remember:
 
3746
                    branch.set_submit_branch(submit_branch)
 
3747
            if submit_branch is None:
 
3748
                submit_branch = branch.get_parent()
 
3749
                remembered_submit_branch = True
 
3750
            if submit_branch is None:
 
3751
                raise errors.BzrCommandError('No submit branch known or'
 
3752
                                             ' specified')
 
3753
            if remembered_submit_branch:
 
3754
                note('Using saved location: %s', submit_branch)
 
3755
 
 
3756
            stored_public_branch = branch.get_public_branch()
 
3757
            if public_branch is None:
 
3758
                public_branch = stored_public_branch
 
3759
            elif stored_public_branch is None or remember:
 
3760
                branch.set_public_branch(public_branch)
 
3761
            if no_bundle and public_branch is None:
 
3762
                raise errors.BzrCommandError('No public branch specified or'
 
3763
                                             ' known')
 
3764
            base_revision_id = None
 
3765
            if revision is not None:
 
3766
                if len(revision) > 2:
 
3767
                    raise errors.BzrCommandError('bzr submit takes '
 
3768
                        'at most two one revision identifiers')
 
3769
                revision_id = revision[-1].in_history(branch).rev_id
 
3770
                if len(revision) == 2:
 
3771
                    base_revision_id = revision[0].in_history(branch).rev_id
 
3772
                    base_revision_id = ensure_null(base_revision_id)
 
3773
            else:
 
3774
                revision_id = branch.last_revision()
 
3775
            revision_id = ensure_null(revision_id)
 
3776
            if revision_id == NULL_REVISION:
 
3777
                raise errors.BzrCommandError('No revisions to submit.')
 
3778
            directive = merge_directive.MergeDirective2.from_objects(
 
3779
                branch.repository, revision_id, time.time(),
 
3780
                osutils.local_time_offset(), submit_branch,
 
3781
                public_branch=public_branch, include_patch=not no_patch,
 
3782
                include_bundle=not no_bundle, message=None,
 
3783
                base_revision_id=base_revision_id)
 
3784
            outfile.writelines(directive.to_lines())
 
3785
        finally:
 
3786
            if output is not None:
 
3787
                outfile.close()
 
3788
 
3629
3789
class cmd_tag(Command):
3630
3790
    """Create a tag naming a revision.
3631
3791
    
3719
3879
                  pull=False,
3720
3880
                  pb=DummyProgress(),
3721
3881
                  change_reporter=None,
3722
 
                  other_rev_id=None):
 
3882
                  other_rev_id=None, base_rev_id=None):
3723
3883
    """Merge changes into a tree.
3724
3884
 
3725
3885
    base_revision
3780
3940
        else:
3781
3941
            merger.set_other(other_revision)
3782
3942
        merger.pp.next_phase()
3783
 
        merger.set_base(base_revision)
 
3943
        if base_rev_id is not None:
 
3944
            merger.set_base_revision(base_rev_id, this_tree.branch)
 
3945
        elif base_revision is not None:
 
3946
            merger.set_base(base_revision)
 
3947
        else:
 
3948
            merger.find_base()
3784
3949
        if merger.base_rev_id == merger.other_rev_id:
3785
3950
            note('Nothing to do.')
3786
3951
            return 0
3840
4005
# details were needed.
3841
4006
from bzrlib.cmd_version_info import cmd_version_info
3842
4007
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore
3843
 
from bzrlib.bundle.commands import cmd_bundle_revisions
 
4008
from bzrlib.bundle.commands import (
 
4009
    cmd_bundle_info,
 
4010
    )
3844
4011
from bzrlib.sign_my_commits import cmd_sign_my_commits
3845
4012
from bzrlib.weave_commands import cmd_versionedfile_list, cmd_weave_join, \
3846
4013
        cmd_weave_plan_merge, cmd_weave_merge_text