~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Vincent Ladeuil
  • Date: 2007-07-20 16:57:41 UTC
  • mto: This revision was merged to the branch mainline in revision 2646.
  • Revision ID: v.ladeuil+lp@free.fr-20070720165741-a15p58sjtdm8qd6i
Update from review comments.

* bzrlib/tests/blackbox/test_branch.py:
(TestRemoteBranch): New class ensuring that working trees are not
created remotely.

* bzrlib/transport/sftp.py:
(SFTPTransport.__init__): Make from_transport parameter private.

* bzrlib/transport/remote.py:
(RemoteTransport.__init__): Make from_transport parameter private.
(RemoteHTTPTransport.__init__): Make from_transport parameter private.
(RemoteHTTPTransport.clone): Use _from_transport as a keyword
parameter.

* bzrlib/transport/http/_urllib.py:
(HttpTransport_urllib.__init__): Make from_transport parameter private.

* bzrlib/transport/http/_pycurl.py:
(PyCurlTransport.__init__): Make from_transport parameter private.

* bzrlib/transport/http/__init__.py:
(HttpTransportBase.__init__): Make from_transport parameter private.

* bzrlib/transport/ftp.py:
(FtpTransport.__init__): Make from_transport parameter private.

* bzrlib/transport/__init__.py:
(ConnectedTransport.__init__): Make from_transport parameter private.
(ConnectedTransport.clone, ConnectedTransport._reuse_for): Use
_from_transport as a keyword parameter.

* bzrlib/tests/commands/test_push.py:
(TestPush.test_push): Don't add self.reset_hooks to cleanup,
install_hooks did it.

* bzrlib/tests/commands/test_pull.py:
(TestPull.test_pull): Don't add self.reset_hooks to cleanup,
install_hooks did it.

* bzrlib/tests/commands/test_missing.py:
(TestMissing.test_missing): Don't add self.reset_hooks to cleanup,
install_hooks did it.

* bzrlib/tests/commands/test_merge.py:
(TestMerge.test_merge): Don't add self.reset_hooks to cleanup,
install_hooks did it.

* bzrlib/tests/commands/test_init_repository.py:
(TestInitRepository.setUp): Don't add self.reset_hooks to cleanup,
install_hooks did it.

* bzrlib/tests/commands/test_init.py:
(TestInit.setUp): Don't add self.reset_hooks to cleanup, install_hooks
did it.

* bzrlib/tests/commands/test_checkout.py:
(TestCheckout.test_checkout): Don't add self.reset_hooks to cleanup,
install_hooks did it.

* bzrlib/tests/commands/test_cat.py:
(TestCat.test_cat): Don't add self.reset_hooks to cleanup,
install_hooks did it. Skip the test until sftp transport/server problem
is fixed.

* bzrlib/tests/commands/test_branch.py:
(TestBranch.setUp): Don't add self.reset_hooks to cleanup,
install_hooks did it.

* bzrlib/builtins.py:
(_get_bundle_helper): New function. Factored out from merge and pull.
(cmd_pull.run, cmd_merge.run): Use _get_bundle_helper.
(_merge_helper): Add possible_transports as the last parameter.

* bzrlib/tests/transport_util.py: 
Renamed from bzrlib/tests/TransportUtil.py.  Switch from ftp to sftp
transport and server.

Show diffs side-by-side

added added

removed removed

Lines of Context:
595
595
            tree_to = None
596
596
            branch_to = Branch.open_containing(directory)[0]
597
597
 
598
 
        reader = None
599
 
        # The user may provide a bundle or branch as 'location' We first try to
600
 
        # identify a bundle, if it's not, we try to preserve connection used by
601
 
        # the transport to access the branch.
602
598
        if location is not None:
603
 
            url = urlutils.normalize_url(location)
604
 
            url, filename = urlutils.split(url, exclude_trailing_slash=False)
605
 
            location_transport = transport.get_transport(url)
606
 
            if filename:
607
 
                try:
608
 
                    read_bundle = bundle.read_mergeable_from_transport
609
 
                    # There may be redirections but we ignore the intermediate
610
 
                    # and final transports used
611
 
                    mergeable, t = read_bundle(location_transport, filename)
612
 
                except errors.NotABundle:
613
 
                    # Continue on considering this url a Branch but adjust the
614
 
                    # location_transport
615
 
                    location_transport = location_transport.clone(filename)
616
 
            else:
617
 
                # A directory was provided, location_transport is correct
618
 
                pass
 
599
            mergeable, location_transport = _get_bundle_helper(location)
619
600
 
620
601
        stored_loc = branch_to.get_parent()
621
602
        if location is None:
2672
2653
        other_transport = None
2673
2654
        other_revision_id = None
2674
2655
        possible_transports = []
2675
 
        # The user may provide a bundle or branch as 'branch' We first try to
2676
 
        # identify a bundle, if it's not, we try to preserve connection used by
2677
 
        # the transport to access the branch.
 
2656
 
2678
2657
        if branch is not None:
2679
 
            url = urlutils.normalize_url(branch)
2680
 
            url, filename = urlutils.split(url, exclude_trailing_slash=False)
2681
 
            other_transport = transport.get_transport(url)
2682
 
            if filename:
2683
 
                try:
2684
 
                    read_bundle = bundle.read_mergeable_from_transport
2685
 
                    # There may be redirections but we ignore the intermediate
2686
 
                    # and final transports used
2687
 
                    mergeable, t = read_bundle(other_transport, filename)
2688
 
                except errors.NotABundle:
2689
 
                    # Continue on considering this url a Branch but adjust the
2690
 
                    # other_transport
2691
 
                    other_transport = other_transport.clone(filename)
2692
 
                else:
2693
 
                    if revision is not None:
2694
 
                        raise errors.BzrCommandError('Cannot use -r with merge'
2695
 
                                                     ' directives or bundles')
2696
 
                    other_revision_id = mergeable.install_revisions(
2697
 
                        tree.branch.repository)
2698
 
                    revision = [RevisionSpec.from_string(
2699
 
                        'revid:' + other_revision_id)]
2700
 
                possible_transports.append(other_transport)
 
2658
            mergeable, other_transport = _get_bundle_helper(branch)
 
2659
            if mergeable:
 
2660
                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)]
 
2667
            possible_transports.append(other_transport)
2701
2668
 
2702
2669
        if revision is None \
2703
2670
                or len(revision) < 1 or revision[0].needs_branch():
2764
2731
        try:
2765
2732
            try:
2766
2733
                conflict_count = _merge_helper(
2767
 
                    other, base, possible_transports,
 
2734
                    other, base,
2768
2735
                    other_rev_id=other_revision_id,
2769
2736
                    check_clean=(not force),
2770
2737
                    merge_type=merge_type,
2773
2740
                    pull=pull,
2774
2741
                    this_dir=directory,
2775
2742
                    pb=pb, file_list=interesting_files,
2776
 
                    change_reporter=change_reporter)
 
2743
                    change_reporter=change_reporter,
 
2744
                    possible_transports=possible_transports)
2777
2745
            finally:
2778
2746
                pb.finished()
2779
2747
            if conflict_count != 0:
3052
3020
                                             " or specified.")
3053
3021
            display_url = urlutils.unescape_for_display(parent,
3054
3022
                                                        self.outf.encoding)
3055
 
            self.outf.write("Using last location: " + display_url + '\n')
 
3023
            self.outf.write("Using last location: " + display_url + "\n")
3056
3024
 
3057
3025
        remote_branch = Branch.open(other_branch)
3058
3026
        if remote_branch.base == local_branch.base:
3753
3721
 
3754
3722
 
3755
3723
# command-line interpretation helper for merge-related commands
3756
 
def _merge_helper(other_revision, base_revision, possible_transports=None,
 
3724
def _merge_helper(other_revision, base_revision,
3757
3725
                  check_clean=True, ignore_zero=False,
3758
3726
                  this_dir=None, backup_files=False,
3759
3727
                  merge_type=None,
3761
3729
                  pull=False,
3762
3730
                  pb=DummyProgress(),
3763
3731
                  change_reporter=None,
3764
 
                  other_rev_id=None):
 
3732
                  other_rev_id=None,
 
3733
                  possible_transports=None):
3765
3734
    """Merge changes into a tree.
3766
3735
 
3767
3736
    base_revision
3871
3840
        cur_transport.ensure_base()
3872
3841
 
3873
3842
 
 
3843
def _get_bundle_helper(location):
 
3844
    """Get a bundle if 'location' points to one.
 
3845
 
 
3846
    Try try to identify a bundle and returns its mergeable form. If it's not,
 
3847
    we return the tried transport anyway so that it can reused to access the
 
3848
    branch
 
3849
 
 
3850
    :param location: can point to a bundle or a branch.
 
3851
 
 
3852
    :return: mergeable, transport
 
3853
    """
 
3854
    mergeable = None
 
3855
    url = urlutils.normalize_url(location)
 
3856
    url, filename = urlutils.split(url, exclude_trailing_slash=False)
 
3857
    location_transport = transport.get_transport(url)
 
3858
    if filename:
 
3859
        try:
 
3860
            # There may be redirections but we ignore the intermediate
 
3861
            # and final transports used
 
3862
            read = bundle.read_mergeable_from_transport
 
3863
            mergeable, t = read(location_transport, filename)
 
3864
        except errors.NotABundle:
 
3865
            # Continue on considering this url a Branch but adjust the
 
3866
            # location_transport
 
3867
            location_transport = location_transport.clone(filename)
 
3868
    return mergeable, location_transport
 
3869
 
 
3870
 
3874
3871
# Compatibility
3875
3872
merge = _merge_helper
3876
3873