/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to brzlib/push.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""UI helper for the push command."""
18
18
 
19
 
from . import (
20
 
    branch as _mod_branch,
 
19
from __future__ import absolute_import
 
20
 
 
21
from brzlib import (
21
22
    controldir,
22
23
    errors,
23
24
    revision as _mod_revision,
24
25
    transport,
25
26
    )
26
 
from .trace import (
 
27
from brzlib.trace import (
27
28
    note,
28
29
    warning,
29
30
    )
30
 
from .i18n import gettext
 
31
from brzlib.i18n import gettext
31
32
 
32
33
 
33
34
class PushResult(object):
50
51
        if self.branch_push_result is None:
51
52
            if self.stacked_on is not None:
52
53
                note(gettext('Created new stacked branch referring to %s.') %
53
 
                     self.stacked_on)
 
54
                    self.stacked_on)
54
55
            else:
55
56
                note(gettext('Created new branch.'))
56
57
        else:
58
59
 
59
60
 
60
61
def _show_push_branch(br_from, revision_id, location, to_file, verbose=False,
61
 
                      overwrite=False, remember=False, stacked_on=None, create_prefix=False,
62
 
                      use_existing_dir=False, no_tree=False, lossy=False):
 
62
    overwrite=False, remember=False, stacked_on=None, create_prefix=False,
 
63
    use_existing_dir=False, no_tree=False):
63
64
    """Push a branch to a location.
64
65
 
65
66
    :param br_from: the source branch
76
77
    :param create_prefix: if True, create the necessary parent directories
77
78
        at the destination if they don't already exist
78
79
    :param use_existing_dir: if True, proceed even if the destination
79
 
        directory exists without a current control directory in it
80
 
    :param lossy: Allow lossy push
 
80
        directory exists without a current .bzr directory in it
81
81
    """
82
 
    to_transport = transport.get_transport(location, purpose='write')
 
82
    to_transport = transport.get_transport(location)
83
83
    try:
84
84
        dir_to = controldir.ControlDir.open_from_transport(to_transport)
85
85
    except errors.NotBranchError:
89
89
    if dir_to is None:
90
90
        try:
91
91
            br_to = br_from.create_clone_on_transport(to_transport,
92
 
                                                      revision_id=revision_id, stacked_on=stacked_on,
93
 
                                                      create_prefix=create_prefix, use_existing_dir=use_existing_dir,
94
 
                                                      no_tree=no_tree)
95
 
        except errors.AlreadyControlDirError:
 
92
                revision_id=revision_id, stacked_on=stacked_on,
 
93
                create_prefix=create_prefix, use_existing_dir=use_existing_dir,
 
94
                no_tree=no_tree)
 
95
        except errors.AlreadyControlDirError, err:
96
96
            raise errors.BzrCommandError(gettext(
97
97
                "Target directory %s already contains a .bzr directory, "
98
98
                "but it is not valid.") % (location,))
99
 
        except errors.FileExists:
 
99
        except errors.FileExists, err:
100
100
            if not use_existing_dir:
101
101
                raise errors.BzrCommandError(gettext("Target directory %s"
102
 
                                                     " already exists, but does not have a .bzr"
103
 
                                                     " directory. Supply --use-existing-dir to push"
104
 
                                                     " there anyway.") % location)
 
102
                     " already exists, but does not have a .bzr"
 
103
                     " directory. Supply --use-existing-dir to push"
 
104
                     " there anyway.") % location)
105
105
            # This shouldn't occur, but if it does the FileExists error will be
106
106
            # more informative than an UnboundLocalError for br_to.
107
107
            raise
108
108
        except errors.NoSuchFile:
109
109
            if not create_prefix:
110
110
                raise errors.BzrCommandError(gettext("Parent directory of %s"
111
 
                                                     " does not exist."
112
 
                                                     "\nYou may supply --create-prefix to create all"
113
 
                                                     " leading parent directories.")
114
 
                                             % location)
 
111
                    " does not exist."
 
112
                    "\nYou may supply --create-prefix to create all"
 
113
                    " leading parent directories.")
 
114
                    % location)
115
115
            # This shouldn't occur (because create_prefix is true, so
116
116
            # create_clone_on_transport should be catching NoSuchFile and
117
117
            # creating the missing directories) but if it does the original
120
120
            raise
121
121
        except errors.TooManyRedirections:
122
122
            raise errors.BzrCommandError(gettext("Too many redirections trying "
123
 
                                                 "to make %s.") % location)
 
123
                                         "to make %s.") % location)
124
124
        push_result = PushResult()
125
125
        # TODO: Some more useful message about what was copied
126
126
        try:
127
127
            push_result.stacked_on = br_to.get_stacked_on_url()
128
 
        except (_mod_branch.UnstackableBranchFormat,
 
128
        except (errors.UnstackableBranchFormat,
129
129
                errors.UnstackableRepositoryFormat,
130
130
                errors.NotStacked):
131
131
            push_result.stacked_on = None
134
134
        push_result.old_revno = 0
135
135
        # Remembers if asked explicitly or no previous location is set
136
136
        if (remember
137
 
                or (remember is None and br_from.get_push_location() is None)):
 
137
            or (remember is None and br_from.get_push_location() is None)):
138
138
            # FIXME: Should be done only if we succeed ? -- vila 2012-01-18
139
139
            br_from.set_push_location(br_to.base)
140
140
    else:
142
142
            warning("Ignoring request for a stacked branch as repository "
143
143
                    "already exists at the destination location.")
144
144
        try:
145
 
            push_result = dir_to.push_branch(br_from, revision_id, overwrite,
146
 
                                             remember, create_prefix, lossy=lossy)
 
145
            push_result = dir_to.push_branch(br_from, revision_id, overwrite, 
 
146
                remember, create_prefix)
147
147
        except errors.DivergedBranches:
148
148
            raise errors.BzrCommandError(gettext('These branches have diverged.'
149
 
                                                 '  See "brz help diverged-branches"'
150
 
                                                 ' for more information.'))
151
 
        except errors.NoRoundtrippingSupport as e:
152
 
            raise errors.BzrCommandError(
153
 
                gettext("It is not possible to losslessly "
154
 
                        "push to %s. You may want to use --lossy.") %
155
 
                e.target_branch.mapping.vcs.abbreviation)
 
149
                                    '  See "bzr help diverged-branches"'
 
150
                                    ' for more information.'))
 
151
        except errors.NoRoundtrippingSupport, e:
 
152
            raise errors.BzrCommandError(gettext("It is not possible to losslessly "
 
153
                "push to %s. You may want to use dpush instead.") % 
 
154
                    e.target_branch.mapping.vcs.abbreviation)
156
155
        except errors.NoRepositoryPresent:
157
156
            # we have a controldir but no branch or repository
158
157
            # XXX: Figure out what to do other than complain.
159
158
            raise errors.BzrCommandError(gettext("At %s you have a valid .bzr"
160
 
                                                 " control directory, but not a branch or repository. This"
161
 
                                                 " is an unsupported configuration. Please move the target"
162
 
                                                 " directory out of the way and try again.") % location)
163
 
        if push_result.workingtree_updated is False:
164
 
            warning("This transport does not update the working "
165
 
                    "tree of: %s. See 'brz help working-trees' for "
 
159
                " control directory, but not a branch or repository. This"
 
160
                " is an unsupported configuration. Please move the target"
 
161
                " directory out of the way and try again.") % location)
 
162
        if push_result.workingtree_updated == False:
 
163
            warning("This transport does not update the working " 
 
164
                    "tree of: %s. See 'bzr help working-trees' for "
166
165
                    "more information." % push_result.target_branch.base)
167
166
    push_result.report(to_file)
168
167
    if verbose:
169
168
        br_to = push_result.target_branch
170
 
        with br_to.lock_read():
171
 
            from .log import show_branch_change
172
 
            show_branch_change(br_to, to_file, push_result.old_revno,
 
169
        br_to.lock_read()
 
170
        try:
 
171
            from brzlib.log import show_branch_change
 
172
            show_branch_change(br_to, to_file, push_result.old_revno, 
173
173
                               push_result.old_revid)
 
174
        finally:
 
175
            br_to.unlock()
 
176
 
 
177