~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Vincent Ladeuil
  • Date: 2007-06-06 13:52:02 UTC
  • mto: (2485.8.44 bzr.connection.sharing)
  • mto: This revision was merged to the branch mainline in revision 2646.
  • Revision ID: v.ladeuil+lp@free.fr-20070606135202-mqhxcv6z57uce434
Fix merge multiple connections. Test suite *not* passing (sftp
refactoring pending but unrelated to merge).

* bzrlib/builtins.py:
(cmd_merge.run): Fix the multiple connections bug by reusing the
tramsport used to check for a bundle and keep all other used
transports in possible_transports.
(_merge_helper): Add a possible_transports parameter for
reuse.

* bzrlib/transport/__init__.py:
(Transport._reuse_for): By default, Transports are not reusable.
(ConnectedTransport._reuse_for): ConnectedTransports are reusable
under certain conditions.
(_urlRE): Fix misleading group name.
(_try_transport_factories): Moved after get_transport (another use
case for moved lines). The do_catching_redirections was
incorrectly inserted between get_transport and
_try_transport_factories.

* bzrlib/tests/test_transport.py:
(TestReusedTransports.test_reuse_same_transport)
(TestReusedTransports.test_don_t_reuse_different_transport): Add
more tests.

* bzrlib/merge.py:
(_get_tree, Merger.set_other): Add a possible_transports parameter
for reuse.

* bzrlib/bzrdir.py:
(BzrDir.open_containing): Add a possible_transports parameter for
reuse.

* bzrlib/branch.py:
(Branch.open_containing): Add a possible_transports parameter for
reuse.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2646
2646
            directory=None,
2647
2647
            ):
2648
2648
        from bzrlib.tag import _merge_tags_if_possible
2649
 
        other_revision_id = None
2650
2649
        if merge_type is None:
2651
2650
            merge_type = _mod_merge.Merge3Merger
2652
2651
 
2662
2661
        change_reporter = delta._ChangeReporter(
2663
2662
            unversioned_filter=tree.is_ignored)
2664
2663
 
 
2664
        other_transport = None
 
2665
        other_revision_id = None
 
2666
        possible_transports = []
 
2667
        # The user may provide a bundle or branch as 'branch' We first try to
 
2668
        # identify a bundle, if it's not, we try to preserve connection used by
 
2669
        # the transport to access the branch.
2665
2670
        if branch is not None:
2666
 
            try:
2667
 
                mergeable = bundle.read_mergeable_from_url(
2668
 
                    branch)
2669
 
            except errors.NotABundle:
2670
 
                pass # Continue on considering this url a Branch
2671
 
            else:
2672
 
                if revision is not None:
2673
 
                    raise errors.BzrCommandError(
2674
 
                        'Cannot use -r with merge directives or bundles')
2675
 
                other_revision_id = mergeable.install_revisions(
2676
 
                    tree.branch.repository)
2677
 
                revision = [RevisionSpec.from_string(
2678
 
                    'revid:' + other_revision_id)]
 
2671
            url = urlutils.normalize_url(branch)
 
2672
            url, filename = urlutils.split(url, exclude_trailing_slash=False)
 
2673
            other_transport = transport.get_transport(url)
 
2674
            if filename:
 
2675
                try:
 
2676
                    read_bundle = bundle.read_mergeable_from_transport
 
2677
                    # There may be redirections but we ignore the intermediate
 
2678
                    # and final transports used
 
2679
                    mergeable, t = read_bundle(other_transport, filename)
 
2680
                except errors.NotABundle:
 
2681
                    # Continue on considering this url a Branch but adjust the
 
2682
                    # other_transport
 
2683
                    other_transport = other_transport.clone(filename)
 
2684
                else:
 
2685
                    if revision is not None:
 
2686
                        raise errors.BzrCommandError('Cannot use -r with merge'
 
2687
                                                     ' directives or bundles')
 
2688
                    other_revision_id = mergeable.install_revisions(
 
2689
                        tree.branch.repository)
 
2690
                    revision = [RevisionSpec.from_string(
 
2691
                        'revid:' + other_revision_id)]
 
2692
                possible_transports.append(other_transport)
2679
2693
 
2680
2694
        if revision is None \
2681
2695
                or len(revision) < 1 or revision[0].needs_branch():
2688
2702
            else:
2689
2703
                base = [None, None]
2690
2704
                other = [branch, -1]
2691
 
            other_branch, path = Branch.open_containing(branch)
 
2705
            other_branch, path = Branch.open_containing(branch,
 
2706
                                                        possible_transports)
2692
2707
        else:
2693
2708
            if uncommitted:
2694
2709
                raise errors.BzrCommandError('Cannot use --uncommitted and'
2697
2712
            if len(revision) == 1:
2698
2713
                base = [None, None]
2699
2714
                if other_revision_id is not None:
 
2715
                    # We merge from a bundle
2700
2716
                    other_branch = None
2701
2717
                    path = ""
2702
2718
                    other = None
2703
2719
                else:
2704
 
                    other_branch, path = Branch.open_containing(branch)
 
2720
                    other_branch, path = Branch.open_containing(
 
2721
                        branch, possible_transports)
2705
2722
                    revno = revision[0].in_history(other_branch).revno
2706
2723
                    other = [branch, revno]
2707
2724
            else:
2709
2726
                if None in revision:
2710
2727
                    raise errors.BzrCommandError(
2711
2728
                        "Merge doesn't permit empty revision specifier.")
2712
 
                base_branch, path = Branch.open_containing(branch)
 
2729
                base_branch, path = Branch.open_containing(branch,
 
2730
                                                           possible_transports)
2713
2731
                branch1 = revision[1].get_branch() or branch
2714
 
                other_branch, path1 = Branch.open_containing(branch1)
 
2732
                other_branch, path1 = Branch.open_containing(
 
2733
                    branch1, possible_transports)
2715
2734
                if revision[0].get_branch() is not None:
2716
2735
                    # then path was obtained from it, and is None.
2717
2736
                    path = path1
2719
2738
                base = [branch, revision[0].in_history(base_branch).revno]
2720
2739
                other = [branch1, revision[1].in_history(other_branch).revno]
2721
2740
 
 
2741
        # Remember where we merge from
2722
2742
        if ((tree.branch.get_parent() is None or remember) and
2723
2743
            other_branch is not None):
2724
2744
            tree.branch.set_parent(other_branch.base)
2736
2756
        try:
2737
2757
            try:
2738
2758
                conflict_count = _merge_helper(
2739
 
                    other, base, other_rev_id=other_revision_id,
 
2759
                    other, base, possible_transports,
 
2760
                    other_rev_id=other_revision_id,
2740
2761
                    check_clean=(not force),
2741
2762
                    merge_type=merge_type,
2742
2763
                    reprocess=reprocess,
3682
3703
 
3683
3704
 
3684
3705
# command-line interpretation helper for merge-related commands
3685
 
def _merge_helper(other_revision, base_revision,
 
3706
def _merge_helper(other_revision, base_revision, possible_transports=None,
3686
3707
                  check_clean=True, ignore_zero=False,
3687
3708
                  this_dir=None, backup_files=False,
3688
3709
                  merge_type=None,
3749
3770
        if other_rev_id is not None:
3750
3771
            merger.set_other_revision(other_rev_id, this_tree.branch)
3751
3772
        else:
3752
 
            merger.set_other(other_revision)
 
3773
            merger.set_other(other_revision, possible_transports)
3753
3774
        merger.pp.next_phase()
3754
3775
        merger.set_base(base_revision)
3755
3776
        if merger.base_rev_id == merger.other_rev_id: