~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Martin Pool
  • Date: 2007-04-04 01:22:11 UTC
  • mfrom: (2393.1.1 bzr.docs)
  • mto: This revision was merged to the branch mainline in revision 2397.
  • Revision ID: mbp@sourcefrog.net-20070404012211-sq269me6bai9m6xk
merge trunk and doc fix from elliot

Show diffs side-by-side

added added

removed removed

Lines of Context:
569
569
            directory=None):
570
570
        from bzrlib.tag import _merge_tags_if_possible
571
571
        # FIXME: too much stuff is in the command class
 
572
        revision_id = None
 
573
        mergeable = None
572
574
        if directory is None:
573
575
            directory = u'.'
574
576
        try:
581
583
        reader = None
582
584
        if location is not None:
583
585
            try:
584
 
                reader = bundle.read_bundle_from_url(location)
 
586
                mergeable = bundle.read_mergeable_from_url(
 
587
                    location)
585
588
            except errors.NotABundle:
586
589
                pass # Continue on considering this url a Branch
587
590
 
596
599
                self.outf.write("Using saved location: %s\n" % display_url)
597
600
                location = stored_loc
598
601
 
599
 
        if reader is not None:
600
 
            install_bundle(branch_to.repository, reader)
 
602
        if mergeable is not None:
 
603
            if revision is not None:
 
604
                raise errors.BzrCommandError(
 
605
                    'Cannot use -r with merge directives or bundles')
 
606
            revision_id = mergeable.install_revisions(branch_to.repository)
601
607
            branch_from = branch_to
602
608
        else:
603
609
            branch_from = Branch.open(location)
605
611
            if branch_to.get_parent() is None or remember:
606
612
                branch_to.set_parent(branch_from.base)
607
613
 
608
 
        rev_id = None
609
 
        if revision is None:
610
 
            if reader is not None:
611
 
                rev_id = reader.target
612
 
        elif len(revision) == 1:
613
 
            rev_id = revision[0].in_history(branch_from).rev_id
614
 
        else:
615
 
            raise errors.BzrCommandError('bzr pull --revision takes one value.')
 
614
        if revision is not None:
 
615
            if len(revision) == 1:
 
616
                revision_id = revision[0].in_history(branch_from).rev_id
 
617
            else:
 
618
                raise errors.BzrCommandError(
 
619
                    'bzr pull --revision takes one value.')
616
620
 
617
621
        old_rh = branch_to.revision_history()
618
622
        if tree_to is not None:
619
 
            result = tree_to.pull(branch_from, overwrite, rev_id,
 
623
            result = tree_to.pull(branch_from, overwrite, revision_id,
620
624
                delta._ChangeReporter(unversioned_filter=tree_to.is_ignored))
621
625
        else:
622
 
            result = branch_to.pull(branch_from, overwrite, rev_id)
 
626
            result = branch_to.pull(branch_from, overwrite, revision_id)
623
627
 
624
628
        result.report(self.outf)
625
629
        if verbose:
626
630
            from bzrlib.log import show_changed_revisions
627
631
            new_rh = branch_to.revision_history()
628
 
            show_changed_revisions(branch_to, old_rh, new_rh, to_file=self.outf)
 
632
            show_changed_revisions(branch_to, old_rh, new_rh,
 
633
                                   to_file=self.outf)
629
634
 
630
635
 
631
636
class cmd_push(Command):
835
840
 
836
841
    To retrieve the branch as of a particular revision, supply the --revision
837
842
    parameter, as in "branch foo/bar -r 5".
838
 
 
839
 
    --basis is to speed up branching from remote branches.  When specified, it
840
 
    copies all the file-contents, inventory and revision data from the basis
841
 
    branch before copying anything from the remote branch.
842
843
    """
843
844
    takes_args = ['from_location', 'to_location?']
844
 
    takes_options = ['revision', 'basis']
 
845
    takes_options = ['revision']
845
846
    aliases = ['get', 'clone']
846
847
 
847
 
    def run(self, from_location, to_location=None, revision=None, basis=None):
 
848
    def run(self, from_location, to_location=None, revision=None):
848
849
        from bzrlib.tag import _merge_tags_if_possible
849
850
        if revision is None:
850
851
            revision = [None]
855
856
        br_from = Branch.open(from_location)
856
857
        br_from.lock_read()
857
858
        try:
858
 
            if basis is not None:
859
 
                basis_dir = bzrdir.BzrDir.open_containing(basis)[0]
860
 
            else:
861
 
                basis_dir = None
862
859
            if len(revision) == 1 and revision[0] is not None:
863
860
                revision_id = revision[0].in_history(br_from)[1]
864
861
            else:
883
880
                                             % to_location)
884
881
            try:
885
882
                # preserve whatever source format we have.
886
 
                dir = br_from.bzrdir.sprout(to_transport.base,
887
 
                        revision_id, basis_dir)
 
883
                dir = br_from.bzrdir.sprout(to_transport.base, revision_id)
888
884
                branch = dir.open_branch()
889
885
            except errors.NoSuchRevision:
890
886
                to_transport.delete_tree('.')
891
887
                msg = "The branch %s has no revision %s." % (from_location, revision[0])
892
888
                raise errors.BzrCommandError(msg)
893
 
            except errors.UnlistableBranch:
894
 
                osutils.rmtree(to_location)
895
 
                msg = "The branch %s cannot be used as a --basis" % (basis,)
896
 
                raise errors.BzrCommandError(msg)
897
889
            if name:
898
890
                branch.control_files.put_utf8('branch-name', name)
899
891
            _merge_tags_if_possible(br_from, branch)
921
913
    See "help checkouts" for more information on checkouts.
922
914
    """
923
915
    takes_args = ['branch_location?', 'to_location?']
924
 
    takes_options = ['revision', # , 'basis']
 
916
    takes_options = ['revision',
925
917
                     Option('lightweight',
926
918
                            help="perform a lightweight checkout. Lightweight "
927
919
                                 "checkouts depend on access to the branch for "
932
924
                     ]
933
925
    aliases = ['co']
934
926
 
935
 
    def run(self, branch_location=None, to_location=None, revision=None, basis=None,
 
927
    def run(self, branch_location=None, to_location=None, revision=None,
936
928
            lightweight=False):
937
929
        if revision is None:
938
930
            revision = [None]
2497
2489
            directory=None,
2498
2490
            ):
2499
2491
        from bzrlib.tag import _merge_tags_if_possible
 
2492
        other_revision_id = None
2500
2493
        if merge_type is None:
2501
2494
            merge_type = _mod_merge.Merge3Merger
2502
2495
 
2514
2507
 
2515
2508
        if branch is not None:
2516
2509
            try:
2517
 
                reader = bundle.read_bundle_from_url(branch)
 
2510
                mergeable = bundle.read_mergeable_from_url(
 
2511
                    branch)
2518
2512
            except errors.NotABundle:
2519
2513
                pass # Continue on considering this url a Branch
2520
2514
            else:
2521
 
                conflicts = merge_bundle(reader, tree, not force, merge_type,
2522
 
                                         reprocess, show_base, change_reporter)
2523
 
                if conflicts == 0:
2524
 
                    return 0
2525
 
                else:
2526
 
                    return 1
 
2515
                if revision is not None:
 
2516
                    raise errors.BzrCommandError(
 
2517
                        'Cannot use -r with merge directives or bundles')
 
2518
                other_revision_id = mergeable.install_revisions(
 
2519
                    tree.branch.repository)
 
2520
                revision = [RevisionSpec.from_string(
 
2521
                    'revid:' + other_revision_id)]
2527
2522
 
2528
2523
        if revision is None \
2529
2524
                or len(revision) < 1 or revision[0].needs_branch():
2544
2539
            branch = revision[0].get_branch() or branch
2545
2540
            if len(revision) == 1:
2546
2541
                base = [None, None]
2547
 
                other_branch, path = Branch.open_containing(branch)
2548
 
                revno = revision[0].in_history(other_branch).revno
2549
 
                other = [branch, revno]
 
2542
                if other_revision_id is not None:
 
2543
                    other_branch = None
 
2544
                    path = ""
 
2545
                    other = None
 
2546
                else:
 
2547
                    other_branch, path = Branch.open_containing(branch)
 
2548
                    revno = revision[0].in_history(other_branch).revno
 
2549
                    other = [branch, revno]
2550
2550
            else:
2551
2551
                assert len(revision) == 2
2552
2552
                if None in revision:
2562
2562
                base = [branch, revision[0].in_history(base_branch).revno]
2563
2563
                other = [branch1, revision[1].in_history(other_branch).revno]
2564
2564
 
2565
 
        if tree.branch.get_parent() is None or remember:
 
2565
        if ((tree.branch.get_parent() is None or remember) and
 
2566
            other_branch is not None):
2566
2567
            tree.branch.set_parent(other_branch.base)
2567
2568
 
2568
2569
        # pull tags now... it's a bit inconsistent to do it ahead of copying
2569
2570
        # the history but that's done inside the merge code
2570
 
        _merge_tags_if_possible(other_branch, tree.branch)
 
2571
        if other_branch is not None:
 
2572
            _merge_tags_if_possible(other_branch, tree.branch)
2571
2573
 
2572
2574
        if path != "":
2573
2575
            interesting_files = [path]
2577
2579
        try:
2578
2580
            try:
2579
2581
                conflict_count = _merge_helper(
2580
 
                    other, base, check_clean=(not force),
 
2582
                    other, base, other_rev_id=other_revision_id,
 
2583
                    check_clean=(not force),
2581
2584
                    merge_type=merge_type,
2582
2585
                    reprocess=reprocess,
2583
2586
                    show_base=show_base,
3503
3506
                  file_list=None, show_base=False, reprocess=False,
3504
3507
                  pull=False,
3505
3508
                  pb=DummyProgress(),
3506
 
                  change_reporter=None):
 
3509
                  change_reporter=None,
 
3510
                  other_rev_id=None):
3507
3511
    """Merge changes into a tree.
3508
3512
 
3509
3513
    base_revision
3559
3563
        merger.pp = ProgressPhase("Merge phase", 5, pb)
3560
3564
        merger.pp.next_phase()
3561
3565
        merger.check_basis(check_clean)
3562
 
        merger.set_other(other_revision)
 
3566
        if other_rev_id is not None:
 
3567
            merger.set_other_revision(other_rev_id, this_tree.branch)
 
3568
        else:
 
3569
            merger.set_other(other_revision)
3563
3570
        merger.pp.next_phase()
3564
3571
        merger.set_base(base_revision)
3565
3572
        if merger.base_rev_id == merger.other_rev_id: