/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Vincent Ladeuil
  • Date: 2007-07-20 18:59:29 UTC
  • mfrom: (2641 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2646.
  • Revision ID: v.ladeuil+lp@free.fr-20070720185929-lg19h2k1lfomgtxa
merge bzr.dev@2642

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
614
613
            if revision is not None:
615
614
                raise errors.BzrCommandError(
616
615
                    'Cannot use -r with merge directives or bundles')
617
 
            revision_id = mergeable.install_revisions(branch_to.repository)
 
616
            mergeable.install_revisions(branch_to.repository)
 
617
            base_revision_id, revision_id, verified = \
 
618
                mergeable.get_merge_request(branch_to.repository)
618
619
            branch_from = branch_to
619
620
        else:
620
621
            branch_from = Branch.open_from_transport(location_transport)
629
630
                raise errors.BzrCommandError(
630
631
                    'bzr pull --revision takes one value.')
631
632
 
632
 
        old_rh = branch_to.revision_history()
 
633
        if verbose:
 
634
            old_rh = branch_to.revision_history()
633
635
        if tree_to is not None:
634
636
            result = tree_to.pull(branch_from, overwrite, revision_id,
635
637
                delta._ChangeReporter(unversioned_filter=tree_to.is_ignored))
731
733
                # Found a branch, so we must have found a repository
732
734
                repository_to = br_to.repository
733
735
        push_result = None
734
 
        old_rh = []
 
736
        if verbose:
 
737
            old_rh = []
735
738
        if dir_to is None:
736
739
            # The destination doesn't exist; create it.
737
740
            # XXX: Refactor the create_prefix/no_create_prefix code into a
787
790
            # we don't need to successfully push because of possible divergence.
788
791
            if br_from.get_push_location() is None or remember:
789
792
                br_from.set_push_location(br_to.base)
790
 
            old_rh = br_to.revision_history()
 
793
            if verbose:
 
794
                old_rh = br_to.revision_history()
791
795
            try:
792
796
                try:
793
797
                    tree_to = dir_to.open_workingtree()
1007
1011
    'bzr revert' instead of 'bzr commit' after the update.
1008
1012
    """
1009
1013
 
1010
 
    _see_also = ['pull', 'working-trees']
 
1014
    _see_also = ['pull', 'working-trees', 'status-flags']
1011
1015
    takes_args = ['dir?']
1012
1016
    aliases = ['up']
1013
1017
 
2652
2656
 
2653
2657
        other_transport = None
2654
2658
        other_revision_id = None
 
2659
        base_revision_id = None
2655
2660
        possible_transports = []
2656
2661
 
2657
2662
        if branch is not None:
2658
2663
            mergeable, other_transport = _get_bundle_helper(branch)
2659
2664
            if mergeable:
2660
2665
                if revision is not None:
2661
 
                    raise errors.BzrCommandError('Cannot use -r with merge'
2662
 
                                                 ' directives or bundles')
2663
 
                other_revision_id = mergeable.install_revisions(
2664
 
                    tree.branch.repository)
2665
 
                revision = [RevisionSpec.from_string('revid:'
2666
 
                                                     + other_revision_id)]
 
2666
                    raise errors.BzrCommandError(
 
2667
                        'Cannot use -r with merge directives or bundles')
 
2668
                mergeable.install_revisions(tree.branch.repository)
 
2669
                base_revision_id, other_revision_id, verified =\
 
2670
                    mergeable.get_merge_request(tree.branch.repository)
 
2671
                if base_revision_id in tree.branch.repository.get_ancestry(
 
2672
                    tree.branch.last_revision(), topo_sorted=False):
 
2673
                    base_revision_id = None
 
2674
                other_branch = None
 
2675
                path = ''
 
2676
                other = None
 
2677
                base = None
2667
2678
            possible_transports.append(other_transport)
2668
2679
 
2669
 
        if revision is None \
2670
 
                or len(revision) < 1 or revision[0].needs_branch():
2671
 
            branch = self._get_remembered_parent(tree, branch, 'Merging from')
 
2680
        if other_revision_id is None:
 
2681
            verified = 'inapplicable'
 
2682
            if revision is None \
 
2683
                    or len(revision) < 1 or revision[0].needs_branch():
 
2684
                branch = self._get_remembered_parent(tree, branch,
 
2685
                    'Merging from')
2672
2686
 
2673
 
        if revision is None or len(revision) < 1:
2674
 
            if uncommitted:
2675
 
                base = [branch, -1]
2676
 
                other = [branch, None]
 
2687
            if revision is None or len(revision) < 1:
 
2688
                if uncommitted:
 
2689
                    base = [branch, -1]
 
2690
                    other = [branch, None]
 
2691
                else:
 
2692
                    base = [None, None]
 
2693
                    other = [branch, -1]
 
2694
                other_branch, path = Branch.open_containing(branch,
 
2695
                                                            possible_transports)
2677
2696
            else:
2678
 
                base = [None, None]
2679
 
                other = [branch, -1]
2680
 
            other_branch, path = Branch.open_containing(branch,
2681
 
                                                        possible_transports)
2682
 
        else:
2683
 
            if uncommitted:
2684
 
                raise errors.BzrCommandError('Cannot use --uncommitted and'
2685
 
                                             ' --revision at the same time.')
2686
 
            branch = revision[0].get_branch() or branch
2687
 
            if len(revision) == 1:
2688
 
                base = [None, None]
2689
 
                if other_revision_id is not None:
2690
 
                    # We merge from a bundle
2691
 
                    other_branch = None
2692
 
                    path = ""
2693
 
                    other = None
2694
 
                else:
 
2697
                if uncommitted:
 
2698
                    raise errors.BzrCommandError('Cannot use --uncommitted and'
 
2699
                        ' --revision at the same time.')
 
2700
                branch = revision[0].get_branch() or branch
 
2701
                if len(revision) == 1:
 
2702
                    base = [None, None]
2695
2703
                    other_branch, path = Branch.open_containing(
2696
2704
                        branch, possible_transports)
2697
2705
                    revno = revision[0].in_history(other_branch).revno
2698
2706
                    other = [branch, revno]
2699
 
            else:
2700
 
                assert len(revision) == 2
2701
 
                if None in revision:
2702
 
                    raise errors.BzrCommandError(
2703
 
                        "Merge doesn't permit empty revision specifier.")
2704
 
                base_branch, path = Branch.open_containing(branch,
2705
 
                                                           possible_transports)
2706
 
                branch1 = revision[1].get_branch() or branch
2707
 
                other_branch, path1 = Branch.open_containing(
2708
 
                    branch1, possible_transports)
2709
 
                if revision[0].get_branch() is not None:
2710
 
                    # then path was obtained from it, and is None.
2711
 
                    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(
 
2713
                        branch, possible_transports)
 
2714
                    branch1 = revision[1].get_branch() or branch
 
2715
                    other_branch, path1 = Branch.open_containing(
 
2716
                        branch1, possible_transports)
 
2717
                    if revision[0].get_branch() is not None:
 
2718
                        # then path was obtained from it, and is None.
 
2719
                        path = path1
2712
2720
 
2713
 
                base = [branch, revision[0].in_history(base_branch).revno]
2714
 
                other = [branch1, revision[1].in_history(other_branch).revno]
 
2721
                    base = [branch, revision[0].in_history(base_branch).revno]
 
2722
                    other = [branch1,
 
2723
                             revision[1].in_history(other_branch).revno]
2715
2724
 
2716
2725
        # Remember where we merge from
2717
2726
        if ((tree.branch.get_parent() is None or remember) and
2731
2740
        try:
2732
2741
            try:
2733
2742
                conflict_count = _merge_helper(
2734
 
                    other, base,
2735
 
                    other_rev_id=other_revision_id,
 
2743
                    other, base, other_rev_id=other_revision_id,
 
2744
                    base_rev_id=base_revision_id,
2736
2745
                    check_clean=(not force),
2737
2746
                    merge_type=merge_type,
2738
2747
                    reprocess=reprocess,
2744
2753
                    possible_transports=possible_transports)
2745
2754
            finally:
2746
2755
                pb.finished()
 
2756
            if verified == 'failed':
 
2757
                warning('Preview patch does not match changes')
2747
2758
            if conflict_count != 0:
2748
2759
                return 1
2749
2760
            else:
2850
2861
                    restore(tree.abspath(filename))
2851
2862
                except errors.NotConflicted:
2852
2863
                    pass
2853
 
            conflicts = _mod_merge.merge_inner(
2854
 
                                      tree.branch, other_tree, base_tree,
2855
 
                                      this_tree=tree,
2856
 
                                      interesting_ids=interesting_ids,
2857
 
                                      other_rev_id=parents[1],
2858
 
                                      merge_type=merge_type,
2859
 
                                      show_base=show_base,
2860
 
                                      reprocess=reprocess)
 
2864
            # Disable pending merges, because the file texts we are remerging
 
2865
            # have not had those merges performed.  If we use the wrong parents
 
2866
            # list, we imply that the working tree text has seen and rejected
 
2867
            # all the changes from the other tree, when in fact those changes
 
2868
            # have not yet been seen.
 
2869
            tree.set_parent_ids(parents[:1])
 
2870
            try:
 
2871
                conflicts = _mod_merge.merge_inner(
 
2872
                                          tree.branch, other_tree, base_tree,
 
2873
                                          this_tree=tree,
 
2874
                                          interesting_ids=interesting_ids,
 
2875
                                          other_rev_id=parents[1],
 
2876
                                          merge_type=merge_type,
 
2877
                                          show_base=show_base,
 
2878
                                          reprocess=reprocess)
 
2879
            finally:
 
2880
                tree.set_parent_ids(parents)
2861
2881
        finally:
2862
2882
            tree.unlock()
2863
2883
        if conflicts > 0:
3096
3116
 
3097
3117
 
3098
3118
class cmd_plugins(Command):
3099
 
    """List plugins"""
3100
 
    hidden = True
 
3119
    """List the installed plugins.
 
3120
    
 
3121
    This command displays the list of installed plugins including the
 
3122
    path where each one is located and a short description of each.
 
3123
 
 
3124
    A plugin is an external component for Bazaar that extends the
 
3125
    revision control system, by adding or replacing code in Bazaar.
 
3126
    Plugins can do a variety of things, including overriding commands,
 
3127
    adding new commands, providing additional network transports and
 
3128
    customizing log output.
 
3129
 
 
3130
    See the Bazaar web site, http://bazaar-vcs.org, for further
 
3131
    information on plugins including where to find them and how to
 
3132
    install them. Instructions are also provided there on how to
 
3133
    write new plugins using the Python programming language.
 
3134
    """
 
3135
 
3101
3136
    @display_command
3102
3137
    def run(self):
3103
3138
        import bzrlib.plugin
3566
3601
 
3567
3602
    takes_args = ['submit_branch?', 'public_branch?']
3568
3603
 
 
3604
    hidden = True
 
3605
 
 
3606
    _see_also = ['submit']
 
3607
 
3569
3608
    takes_options = [
3570
3609
        RegistryOption.from_kwargs('patch-type',
3571
3610
            'The type of patch to include in the directive',
3587
3626
    def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
3588
3627
            sign=False, revision=None, mail_to=None, message=None):
3589
3628
        from bzrlib.revision import ensure_null, NULL_REVISION
3590
 
        if patch_type == 'plain':
3591
 
            patch_type = None
 
3629
        include_patch, include_bundle = {
 
3630
            'plain': (False, False),
 
3631
            'diff': (True, False),
 
3632
            'bundle': (True, True),
 
3633
            }[patch_type]
3592
3634
        branch = Branch.open('.')
3593
3635
        stored_submit_branch = branch.get_submit_branch()
3594
3636
        if submit_branch is None:
3606
3648
            public_branch = stored_public_branch
3607
3649
        elif stored_public_branch is None:
3608
3650
            branch.set_public_branch(public_branch)
3609
 
        if patch_type != "bundle" and public_branch is None:
 
3651
        if not include_bundle and public_branch is None:
3610
3652
            raise errors.BzrCommandError('No public branch specified or'
3611
3653
                                         ' known')
 
3654
        base_revision_id = None
3612
3655
        if revision is not None:
3613
 
            if len(revision) != 1:
 
3656
            if len(revision) > 2:
3614
3657
                raise errors.BzrCommandError('bzr merge-directive takes '
3615
 
                    'exactly one revision identifier')
3616
 
            else:
3617
 
                revision_id = revision[0].in_history(branch).rev_id
 
3658
                    'at most two one revision identifiers')
 
3659
            revision_id = revision[-1].in_history(branch).rev_id
 
3660
            if len(revision) == 2:
 
3661
                base_revision_id = revision[0].in_history(branch).rev_id
 
3662
                base_revision_id = ensure_null(base_revision_id)
3618
3663
        else:
3619
3664
            revision_id = branch.last_revision()
3620
3665
        revision_id = ensure_null(revision_id)
3621
3666
        if revision_id == NULL_REVISION:
3622
3667
            raise errors.BzrCommandError('No revisions to bundle.')
3623
 
        directive = merge_directive.MergeDirective.from_objects(
 
3668
        directive = merge_directive.MergeDirective2.from_objects(
3624
3669
            branch.repository, revision_id, time.time(),
3625
3670
            osutils.local_time_offset(), submit_branch,
3626
 
            public_branch=public_branch, patch_type=patch_type,
3627
 
            message=message)
 
3671
            public_branch=public_branch, include_patch=include_patch,
 
3672
            include_bundle=include_bundle, message=message,
 
3673
            base_revision_id=base_revision_id)
3628
3674
        if mail_to is None:
3629
3675
            if sign:
3630
3676
                self.outf.write(directive.to_signed(branch))
3636
3682
            s.send_email(message)
3637
3683
 
3638
3684
 
 
3685
class cmd_submit(Command):
 
3686
    """Create a merge-directive for submiting changes.
 
3687
 
 
3688
    A merge directive provides many things needed for requesting merges:
 
3689
    - A machine-readable description of the merge to perform
 
3690
    - An optional patch that is a preview of the changes requested
 
3691
    - An optional bundle of revision data, so that the changes can be applied
 
3692
      directly from the merge directive, without retrieving data from a
 
3693
      branch.
 
3694
 
 
3695
    If --no-bundle is specified, then public_branch is needed (and must be
 
3696
    up-to-date), so that the receiver can perform the merge using the
 
3697
    public_branch.  The public_branch is always included if known, so that
 
3698
    people can check it later.
 
3699
 
 
3700
    The submit branch defaults to the parent, but can be overridden.  Both
 
3701
    submit branch and public branch will be remembered if supplied.
 
3702
 
 
3703
    If a public_branch is known for the submit_branch, that public submit
 
3704
    branch is used in the merge instructions.  This means that a local mirror
 
3705
    can be used as your actual submit branch, once you have set public_branch
 
3706
    for that mirror.
 
3707
    """
 
3708
 
 
3709
    encoding_type = 'exact'
 
3710
 
 
3711
    aliases = ['bundle', 'bundle-revisions']
 
3712
 
 
3713
    _see_also = ['merge']
 
3714
 
 
3715
    takes_args = ['submit_branch?', 'public_branch?']
 
3716
    takes_options = [
 
3717
        Option('no-bundle',
 
3718
               help='Do not include a bundle in the merge directive.'),
 
3719
        Option('no-patch', help='Do not include a preview patch in the merge'
 
3720
               ' directive.'),
 
3721
        Option('remember',
 
3722
               help='Remember submit and public branch.'),
 
3723
        Option('from',
 
3724
               help='Branch to generate the submission from, '
 
3725
               'rather than the one containing the working directory.',
 
3726
               short_name='f',
 
3727
               type=unicode),
 
3728
        Option('output', short_name='o', help='Write directive to this file.',
 
3729
               type=unicode),
 
3730
        'revision',
 
3731
        ]
 
3732
 
 
3733
    def run(self, submit_branch=None, public_branch=None, no_bundle=False,
 
3734
            no_patch=False, revision=None, remember=False, output=None,
 
3735
            **kwargs):
 
3736
        from bzrlib.revision import ensure_null, NULL_REVISION
 
3737
        if output is None:
 
3738
            outfile = self.outf
 
3739
        else:
 
3740
            outfile = open(output, 'wb')
 
3741
        try:
 
3742
            from_ = kwargs.get('from', '.')
 
3743
            branch = Branch.open_containing(from_)[0]
 
3744
            if remember and submit_branch is None:
 
3745
                raise errors.BzrCommandError(
 
3746
                    '--remember requires a branch to be specified.')
 
3747
            stored_submit_branch = branch.get_submit_branch()
 
3748
            remembered_submit_branch = False
 
3749
            if submit_branch is None:
 
3750
                submit_branch = stored_submit_branch
 
3751
                remembered_submit_branch = True
 
3752
            else:
 
3753
                if stored_submit_branch is None or remember:
 
3754
                    branch.set_submit_branch(submit_branch)
 
3755
            if submit_branch is None:
 
3756
                submit_branch = branch.get_parent()
 
3757
                remembered_submit_branch = True
 
3758
            if submit_branch is None:
 
3759
                raise errors.BzrCommandError('No submit branch known or'
 
3760
                                             ' specified')
 
3761
            if remembered_submit_branch:
 
3762
                note('Using saved location: %s', submit_branch)
 
3763
 
 
3764
            stored_public_branch = branch.get_public_branch()
 
3765
            if public_branch is None:
 
3766
                public_branch = stored_public_branch
 
3767
            elif stored_public_branch is None or remember:
 
3768
                branch.set_public_branch(public_branch)
 
3769
            if no_bundle and public_branch is None:
 
3770
                raise errors.BzrCommandError('No public branch specified or'
 
3771
                                             ' known')
 
3772
            base_revision_id = None
 
3773
            if revision is not None:
 
3774
                if len(revision) > 2:
 
3775
                    raise errors.BzrCommandError('bzr submit takes '
 
3776
                        'at most two one revision identifiers')
 
3777
                revision_id = revision[-1].in_history(branch).rev_id
 
3778
                if len(revision) == 2:
 
3779
                    base_revision_id = revision[0].in_history(branch).rev_id
 
3780
                    base_revision_id = ensure_null(base_revision_id)
 
3781
            else:
 
3782
                revision_id = branch.last_revision()
 
3783
            revision_id = ensure_null(revision_id)
 
3784
            if revision_id == NULL_REVISION:
 
3785
                raise errors.BzrCommandError('No revisions to submit.')
 
3786
            directive = merge_directive.MergeDirective2.from_objects(
 
3787
                branch.repository, revision_id, time.time(),
 
3788
                osutils.local_time_offset(), submit_branch,
 
3789
                public_branch=public_branch, include_patch=not no_patch,
 
3790
                include_bundle=not no_bundle, message=None,
 
3791
                base_revision_id=base_revision_id)
 
3792
            outfile.writelines(directive.to_lines())
 
3793
        finally:
 
3794
            if output is not None:
 
3795
                outfile.close()
 
3796
 
3639
3797
class cmd_tag(Command):
3640
3798
    """Create a tag naming a revision.
3641
3799
    
3729
3887
                  pull=False,
3730
3888
                  pb=DummyProgress(),
3731
3889
                  change_reporter=None,
3732
 
                  other_rev_id=None,
 
3890
                  other_rev_id=None, base_rev_id=None,
3733
3891
                  possible_transports=None):
3734
3892
    """Merge changes into a tree.
3735
3893
 
3791
3949
        else:
3792
3950
            merger.set_other(other_revision, possible_transports)
3793
3951
        merger.pp.next_phase()
3794
 
        merger.set_base(base_revision)
 
3952
        if base_rev_id is not None:
 
3953
            merger.set_base_revision(base_rev_id, this_tree.branch)
 
3954
        elif base_revision is not None:
 
3955
            merger.set_base(base_revision)
 
3956
        else:
 
3957
            merger.find_base()
3795
3958
        if merger.base_rev_id == merger.other_rev_id:
3796
3959
            note('Nothing to do.')
3797
3960
            return 0
3879
4042
# details were needed.
3880
4043
from bzrlib.cmd_version_info import cmd_version_info
3881
4044
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore
3882
 
from bzrlib.bundle.commands import cmd_bundle_revisions
 
4045
from bzrlib.bundle.commands import (
 
4046
    cmd_bundle_info,
 
4047
    )
3883
4048
from bzrlib.sign_my_commits import cmd_sign_my_commits
3884
4049
from bzrlib.weave_commands import cmd_versionedfile_list, cmd_weave_join, \
3885
4050
        cmd_weave_plan_merge, cmd_weave_merge_text