~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-04-01 05:11:40 UTC
  • mfrom: (1551.14.13 mergedirective)
  • Revision ID: pqm@pqm.ubuntu.com-20070401051140-280aed4369df0386
merge and pull support merge directives

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):
2484
2489
            directory=None,
2485
2490
            ):
2486
2491
        from bzrlib.tag import _merge_tags_if_possible
 
2492
        other_revision_id = None
2487
2493
        if merge_type is None:
2488
2494
            merge_type = _mod_merge.Merge3Merger
2489
2495
 
2501
2507
 
2502
2508
        if branch is not None:
2503
2509
            try:
2504
 
                reader = bundle.read_bundle_from_url(branch)
 
2510
                mergeable = bundle.read_mergeable_from_url(
 
2511
                    branch)
2505
2512
            except errors.NotABundle:
2506
2513
                pass # Continue on considering this url a Branch
2507
2514
            else:
2508
 
                conflicts = merge_bundle(reader, tree, not force, merge_type,
2509
 
                                         reprocess, show_base, change_reporter)
2510
 
                if conflicts == 0:
2511
 
                    return 0
2512
 
                else:
2513
 
                    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)]
2514
2522
 
2515
2523
        if revision is None \
2516
2524
                or len(revision) < 1 or revision[0].needs_branch():
2531
2539
            branch = revision[0].get_branch() or branch
2532
2540
            if len(revision) == 1:
2533
2541
                base = [None, None]
2534
 
                other_branch, path = Branch.open_containing(branch)
2535
 
                revno = revision[0].in_history(other_branch).revno
2536
 
                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]
2537
2550
            else:
2538
2551
                assert len(revision) == 2
2539
2552
                if None in revision:
2549
2562
                base = [branch, revision[0].in_history(base_branch).revno]
2550
2563
                other = [branch1, revision[1].in_history(other_branch).revno]
2551
2564
 
2552
 
        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):
2553
2567
            tree.branch.set_parent(other_branch.base)
2554
2568
 
2555
2569
        # pull tags now... it's a bit inconsistent to do it ahead of copying
2556
2570
        # the history but that's done inside the merge code
2557
 
        _merge_tags_if_possible(other_branch, tree.branch)
 
2571
        if other_branch is not None:
 
2572
            _merge_tags_if_possible(other_branch, tree.branch)
2558
2573
 
2559
2574
        if path != "":
2560
2575
            interesting_files = [path]
2564
2579
        try:
2565
2580
            try:
2566
2581
                conflict_count = _merge_helper(
2567
 
                    other, base, check_clean=(not force),
 
2582
                    other, base, other_rev_id=other_revision_id,
 
2583
                    check_clean=(not force),
2568
2584
                    merge_type=merge_type,
2569
2585
                    reprocess=reprocess,
2570
2586
                    show_base=show_base,
3490
3506
                  file_list=None, show_base=False, reprocess=False,
3491
3507
                  pull=False,
3492
3508
                  pb=DummyProgress(),
3493
 
                  change_reporter=None):
 
3509
                  change_reporter=None,
 
3510
                  other_rev_id=None):
3494
3511
    """Merge changes into a tree.
3495
3512
 
3496
3513
    base_revision
3546
3563
        merger.pp = ProgressPhase("Merge phase", 5, pb)
3547
3564
        merger.pp.next_phase()
3548
3565
        merger.check_basis(check_clean)
3549
 
        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)
3550
3570
        merger.pp.next_phase()
3551
3571
        merger.set_base(base_revision)
3552
3572
        if merger.base_rev_id == merger.other_rev_id: