/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: Robert Collins
  • Date: 2007-07-20 00:58:41 UTC
  • mfrom: (2633 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2634.
  • Revision ID: robertc@robertcollins.net-20070720005841-xnu6um6vx0n41h0k
Merge bzr.dev.

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()
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:
3086
3099
 
3087
3100
 
3088
3101
class cmd_plugins(Command):
3089
 
    """List plugins"""
3090
 
    hidden = True
 
3102
    """List the installed plugins.
 
3103
    
 
3104
    This command displays the list of installed plugins including the
 
3105
    path where each one is located and a short description of each.
 
3106
 
 
3107
    A plugin is an external component for Bazaar that extends the
 
3108
    revision control system, by adding or replacing code in Bazaar.
 
3109
    Plugins can do a variety of things, including overriding commands,
 
3110
    adding new commands, providing additional network transports and
 
3111
    customizing log output.
 
3112
 
 
3113
    See the Bazaar web site, http://bazaar-vcs.org, for further
 
3114
    information on plugins including where to find them and how to
 
3115
    install them. Instructions are also provided there on how to
 
3116
    write new plugins using the Python programming language.
 
3117
    """
 
3118
 
3091
3119
    @display_command
3092
3120
    def run(self):
3093
3121
        import bzrlib.plugin
3556
3584
 
3557
3585
    takes_args = ['submit_branch?', 'public_branch?']
3558
3586
 
 
3587
    hidden = True
 
3588
 
 
3589
    _see_also = ['submit']
 
3590
 
3559
3591
    takes_options = [
3560
3592
        RegistryOption.from_kwargs('patch-type',
3561
3593
            'The type of patch to include in the directive',
3577
3609
    def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
3578
3610
            sign=False, revision=None, mail_to=None, message=None):
3579
3611
        from bzrlib.revision import ensure_null, NULL_REVISION
3580
 
        if patch_type == 'plain':
3581
 
            patch_type = None
 
3612
        include_patch, include_bundle = {
 
3613
            'plain': (False, False),
 
3614
            'diff': (True, False),
 
3615
            'bundle': (True, True),
 
3616
            }[patch_type]
3582
3617
        branch = Branch.open('.')
3583
3618
        stored_submit_branch = branch.get_submit_branch()
3584
3619
        if submit_branch is None:
3596
3631
            public_branch = stored_public_branch
3597
3632
        elif stored_public_branch is None:
3598
3633
            branch.set_public_branch(public_branch)
3599
 
        if patch_type != "bundle" and public_branch is None:
 
3634
        if not include_bundle and public_branch is None:
3600
3635
            raise errors.BzrCommandError('No public branch specified or'
3601
3636
                                         ' known')
 
3637
        base_revision_id = None
3602
3638
        if revision is not None:
3603
 
            if len(revision) != 1:
 
3639
            if len(revision) > 2:
3604
3640
                raise errors.BzrCommandError('bzr merge-directive takes '
3605
 
                    'exactly one revision identifier')
3606
 
            else:
3607
 
                revision_id = revision[0].in_history(branch).rev_id
 
3641
                    'at most two one revision identifiers')
 
3642
            revision_id = revision[-1].in_history(branch).rev_id
 
3643
            if len(revision) == 2:
 
3644
                base_revision_id = revision[0].in_history(branch).rev_id
 
3645
                base_revision_id = ensure_null(base_revision_id)
3608
3646
        else:
3609
3647
            revision_id = branch.last_revision()
3610
3648
        revision_id = ensure_null(revision_id)
3611
3649
        if revision_id == NULL_REVISION:
3612
3650
            raise errors.BzrCommandError('No revisions to bundle.')
3613
 
        directive = merge_directive.MergeDirective.from_objects(
 
3651
        directive = merge_directive.MergeDirective2.from_objects(
3614
3652
            branch.repository, revision_id, time.time(),
3615
3653
            osutils.local_time_offset(), submit_branch,
3616
 
            public_branch=public_branch, patch_type=patch_type,
3617
 
            message=message)
 
3654
            public_branch=public_branch, include_patch=include_patch,
 
3655
            include_bundle=include_bundle, message=message,
 
3656
            base_revision_id=base_revision_id)
3618
3657
        if mail_to is None:
3619
3658
            if sign:
3620
3659
                self.outf.write(directive.to_signed(branch))
3626
3665
            s.send_email(message)
3627
3666
 
3628
3667
 
 
3668
class cmd_submit(Command):
 
3669
    """Create a merge-directive for submiting changes.
 
3670
 
 
3671
    A merge directive provides many things needed for requesting merges:
 
3672
    - A machine-readable description of the merge to perform
 
3673
    - An optional patch that is a preview of the changes requested
 
3674
    - An optional bundle of revision data, so that the changes can be applied
 
3675
      directly from the merge directive, without retrieving data from a
 
3676
      branch.
 
3677
 
 
3678
    If --no-bundle is specified, then public_branch is needed (and must be
 
3679
    up-to-date), so that the receiver can perform the merge using the
 
3680
    public_branch.  The public_branch is always included if known, so that
 
3681
    people can check it later.
 
3682
 
 
3683
    The submit branch defaults to the parent, but can be overridden.  Both
 
3684
    submit branch and public branch will be remembered if supplied.
 
3685
 
 
3686
    If a public_branch is known for the submit_branch, that public submit
 
3687
    branch is used in the merge instructions.  This means that a local mirror
 
3688
    can be used as your actual submit branch, once you have set public_branch
 
3689
    for that mirror.
 
3690
    """
 
3691
 
 
3692
    encoding_type = 'exact'
 
3693
 
 
3694
    aliases = ['bundle', 'bundle-revisions']
 
3695
 
 
3696
    _see_also = ['merge']
 
3697
 
 
3698
    takes_args = ['submit_branch?', 'public_branch?']
 
3699
    takes_options = [
 
3700
        Option('no-bundle',
 
3701
               help='Do not include a bundle in the merge directive.'),
 
3702
        Option('no-patch', help='Do not include a preview patch in the merge'
 
3703
               ' directive.'),
 
3704
        Option('remember',
 
3705
               help='Remember submit and public branch.'),
 
3706
        Option('from',
 
3707
               help='Branch to generate the submission from, '
 
3708
               'rather than the one containing the working directory.',
 
3709
               short_name='f',
 
3710
               type=unicode),
 
3711
        Option('output', short_name='o', help='Write directive to this file.',
 
3712
               type=unicode),
 
3713
        'revision',
 
3714
        ]
 
3715
 
 
3716
    def run(self, submit_branch=None, public_branch=None, no_bundle=False,
 
3717
            no_patch=False, revision=None, remember=False, output=None,
 
3718
            **kwargs):
 
3719
        from bzrlib.revision import ensure_null, NULL_REVISION
 
3720
        if output is None:
 
3721
            outfile = self.outf
 
3722
        else:
 
3723
            outfile = open(output, 'wb')
 
3724
        try:
 
3725
            from_ = kwargs.get('from', '.')
 
3726
            branch = Branch.open_containing(from_)[0]
 
3727
            if remember and submit_branch is None:
 
3728
                raise errors.BzrCommandError(
 
3729
                    '--remember requires a branch to be specified.')
 
3730
            stored_submit_branch = branch.get_submit_branch()
 
3731
            remembered_submit_branch = False
 
3732
            if submit_branch is None:
 
3733
                submit_branch = stored_submit_branch
 
3734
                remembered_submit_branch = True
 
3735
            else:
 
3736
                if stored_submit_branch is None or remember:
 
3737
                    branch.set_submit_branch(submit_branch)
 
3738
            if submit_branch is None:
 
3739
                submit_branch = branch.get_parent()
 
3740
                remembered_submit_branch = True
 
3741
            if submit_branch is None:
 
3742
                raise errors.BzrCommandError('No submit branch known or'
 
3743
                                             ' specified')
 
3744
            if remembered_submit_branch:
 
3745
                note('Using saved location: %s', submit_branch)
 
3746
 
 
3747
            stored_public_branch = branch.get_public_branch()
 
3748
            if public_branch is None:
 
3749
                public_branch = stored_public_branch
 
3750
            elif stored_public_branch is None or remember:
 
3751
                branch.set_public_branch(public_branch)
 
3752
            if no_bundle and public_branch is None:
 
3753
                raise errors.BzrCommandError('No public branch specified or'
 
3754
                                             ' known')
 
3755
            base_revision_id = None
 
3756
            if revision is not None:
 
3757
                if len(revision) > 2:
 
3758
                    raise errors.BzrCommandError('bzr submit takes '
 
3759
                        'at most two one revision identifiers')
 
3760
                revision_id = revision[-1].in_history(branch).rev_id
 
3761
                if len(revision) == 2:
 
3762
                    base_revision_id = revision[0].in_history(branch).rev_id
 
3763
                    base_revision_id = ensure_null(base_revision_id)
 
3764
            else:
 
3765
                revision_id = branch.last_revision()
 
3766
            revision_id = ensure_null(revision_id)
 
3767
            if revision_id == NULL_REVISION:
 
3768
                raise errors.BzrCommandError('No revisions to submit.')
 
3769
            directive = merge_directive.MergeDirective2.from_objects(
 
3770
                branch.repository, revision_id, time.time(),
 
3771
                osutils.local_time_offset(), submit_branch,
 
3772
                public_branch=public_branch, include_patch=not no_patch,
 
3773
                include_bundle=not no_bundle, message=None,
 
3774
                base_revision_id=base_revision_id)
 
3775
            outfile.writelines(directive.to_lines())
 
3776
        finally:
 
3777
            if output is not None:
 
3778
                outfile.close()
 
3779
 
3629
3780
class cmd_tag(Command):
3630
3781
    """Create a tag naming a revision.
3631
3782
    
3719
3870
                  pull=False,
3720
3871
                  pb=DummyProgress(),
3721
3872
                  change_reporter=None,
3722
 
                  other_rev_id=None):
 
3873
                  other_rev_id=None, base_rev_id=None):
3723
3874
    """Merge changes into a tree.
3724
3875
 
3725
3876
    base_revision
3780
3931
        else:
3781
3932
            merger.set_other(other_revision)
3782
3933
        merger.pp.next_phase()
3783
 
        merger.set_base(base_revision)
 
3934
        if base_rev_id is not None:
 
3935
            merger.set_base_revision(base_rev_id, this_tree.branch)
 
3936
        elif base_revision is not None:
 
3937
            merger.set_base(base_revision)
 
3938
        else:
 
3939
            merger.find_base()
3784
3940
        if merger.base_rev_id == merger.other_rev_id:
3785
3941
            note('Nothing to do.')
3786
3942
            return 0
3840
3996
# details were needed.
3841
3997
from bzrlib.cmd_version_info import cmd_version_info
3842
3998
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore
3843
 
from bzrlib.bundle.commands import cmd_bundle_revisions
 
3999
from bzrlib.bundle.commands import (
 
4000
    cmd_bundle_info,
 
4001
    )
3844
4002
from bzrlib.sign_my_commits import cmd_sign_my_commits
3845
4003
from bzrlib.weave_commands import cmd_versionedfile_list, cmd_weave_join, \
3846
4004
        cmd_weave_plan_merge, cmd_weave_merge_text