~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/push.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-04-09 20:23:07 UTC
  • mfrom: (4265.1.4 bbc-merge)
  • Revision ID: pqm@pqm.ubuntu.com-20090409202307-n0depb16qepoe21o
(jam) Change _fetch_uses_deltas = False for CHK repos until we can
        write a better fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
        directory exists without a current .bzr directory in it
80
80
    """
81
81
    to_transport = transport.get_transport(location)
 
82
    br_to = repository_to = dir_to = None
82
83
    try:
83
84
        dir_to = bzrdir.BzrDir.open_from_transport(to_transport)
84
85
    except errors.NotBranchError:
85
 
        # Didn't find anything
86
 
        dir_to = None
 
86
        pass # Didn't find anything
87
87
 
 
88
    push_result = PushResult()
88
89
    if dir_to is None:
 
90
        # The destination doesn't exist; create it.
 
91
        # XXX: Refactor the create_prefix/no_create_prefix code into a
 
92
        #      common helper function
 
93
 
 
94
        def make_directory(transport):
 
95
            transport.mkdir('.')
 
96
            return transport
 
97
 
 
98
        def redirected(transport, e, redirection_notice):
 
99
            note(redirection_notice)
 
100
            return transport._redirected_to(e.source, e.target)
 
101
 
89
102
        try:
90
 
            br_to = br_from.create_clone_on_transport(to_transport,
91
 
                revision_id=revision_id, stacked_on=stacked_on,
92
 
                create_prefix=create_prefix, use_existing_dir=use_existing_dir)
 
103
            to_transport = transport.do_catching_redirections(
 
104
                make_directory, to_transport, redirected)
93
105
        except errors.FileExists:
94
106
            if not use_existing_dir:
95
107
                raise errors.BzrCommandError("Target directory %s"
103
115
                    "\nYou may supply --create-prefix to create all"
104
116
                    " leading parent directories."
105
117
                    % location)
 
118
            builtins._create_prefix(to_transport)
106
119
        except errors.TooManyRedirections:
107
120
            raise errors.BzrCommandError("Too many redirections trying "
108
121
                                         "to make %s." % location)
109
 
        push_result = PushResult()
 
122
 
 
123
        # Now the target directory exists, but doesn't have a .bzr
 
124
        # directory. So we need to create it, along with any work to create
 
125
        # all of the dependent branches, etc.
 
126
        br_to = br_from.create_clone_on_transport(to_transport,
 
127
            revision_id=revision_id, stacked_on=stacked_on)
110
128
        # TODO: Some more useful message about what was copied
111
129
        try:
112
130
            push_result.stacked_on = br_to.get_stacked_on_url()
125
143
                    "already exists at the destination location.")
126
144
        try:
127
145
            push_result = dir_to.push_branch(br_from, revision_id, overwrite, 
128
 
                remember, create_prefix)
 
146
                remember)
129
147
        except errors.DivergedBranches:
130
148
            raise errors.BzrCommandError('These branches have diverged.'
131
 
                                    '  See "bzr help diverged-branches"'
132
 
                                    ' for more information.')
 
149
                                    '  Try using "merge" and then "push".')
133
150
        except errors.NoRepositoryPresent:
134
151
            # we have a bzrdir but no branch or repository
135
152
            # XXX: Figure out what to do other than complain.