/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 bzrlib/push.py

  • Committer: John Ferlito
  • Date: 2009-09-02 04:31:45 UTC
  • mto: (4665.7.1 serve-init)
  • mto: This revision was merged to the branch mainline in revision 4913.
  • Revision ID: johnf@inodes.org-20090902043145-gxdsfw03ilcwbyn5
Add a debian init script for bzr --serve

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2012 Canonical Ltd
 
1
# Copyright (C) 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
16
16
 
17
17
"""UI helper for the push command."""
18
18
 
19
 
from . import (
20
 
    branch as _mod_branch,
21
 
    controldir,
 
19
from bzrlib import (
 
20
    builtins,
 
21
    branch,
 
22
    bzrdir,
22
23
    errors,
23
24
    revision as _mod_revision,
24
25
    transport,
25
26
    )
26
 
from .trace import (
 
27
from bzrlib.trace import (
27
28
    note,
28
29
    warning,
29
30
    )
30
 
from .i18n import gettext
31
31
 
32
32
 
33
33
class PushResult(object):
49
49
        """Write a human-readable description of the result."""
50
50
        if self.branch_push_result is None:
51
51
            if self.stacked_on is not None:
52
 
                note(gettext('Created new stacked branch referring to %s.') %
53
 
                     self.stacked_on)
 
52
                note('Created new stacked branch referring to %s.' %
 
53
                    self.stacked_on)
54
54
            else:
55
 
                note(gettext('Created new branch.'))
 
55
                note('Created new branch.')
56
56
        else:
57
57
            self.branch_push_result.report(to_file)
58
58
 
59
59
 
60
60
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):
 
61
    overwrite=False, remember=False, stacked_on=None, create_prefix=False,
 
62
    use_existing_dir=False):
63
63
    """Push a branch to a location.
64
64
 
65
65
    :param br_from: the source branch
67
67
    :param location: the url of the destination
68
68
    :param to_file: the output stream
69
69
    :param verbose: if True, display more output than normal
70
 
    :param overwrite: list of things to overwrite ("history", "tags")
71
 
        or boolean indicating for everything
 
70
    :param overwrite: if False, a current branch at the destination may not
 
71
        have diverged from the source, otherwise the push fails
72
72
    :param remember: if True, store the location as the push location for
73
73
        the source branch
74
74
    :param stacked_on: the url of the branch, if any, to stack on;
76
76
    :param create_prefix: if True, create the necessary parent directories
77
77
        at the destination if they don't already exist
78
78
    :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
 
79
        directory exists without a current .bzr directory in it
81
80
    """
82
 
    to_transport = transport.get_transport(location, purpose='write')
 
81
    to_transport = transport.get_transport(location)
83
82
    try:
84
 
        dir_to = controldir.ControlDir.open_from_transport(to_transport)
 
83
        dir_to = bzrdir.BzrDir.open_from_transport(to_transport)
85
84
    except errors.NotBranchError:
86
85
        # Didn't find anything
87
86
        dir_to = None
89
88
    if dir_to is None:
90
89
        try:
91
90
            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:
96
 
            raise errors.CommandError(gettext(
97
 
                "Target directory %s already contains a .bzr directory, "
98
 
                "but it is not valid.") % (location,))
 
91
                revision_id=revision_id, stacked_on=stacked_on,
 
92
                create_prefix=create_prefix, use_existing_dir=use_existing_dir)
99
93
        except errors.FileExists:
100
94
            if not use_existing_dir:
101
 
                raise errors.CommandError(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)
105
 
            # This shouldn't occur, but if it does the FileExists error will be
106
 
            # more informative than an UnboundLocalError for br_to.
107
 
            raise
 
95
                raise errors.BzrCommandError("Target directory %s"
 
96
                     " already exists, but does not have a valid .bzr"
 
97
                     " directory. Supply --use-existing-dir to push"
 
98
                     " there anyway." % location)
108
99
        except errors.NoSuchFile:
109
100
            if not create_prefix:
110
 
                raise errors.CommandError(gettext("Parent directory of %s"
111
 
                                                     " does not exist."
112
 
                                                     "\nYou may supply --create-prefix to create all"
113
 
                                                     " leading parent directories.")
114
 
                                             % location)
115
 
            # This shouldn't occur (because create_prefix is true, so
116
 
            # create_clone_on_transport should be catching NoSuchFile and
117
 
            # creating the missing directories) but if it does the original
118
 
            # NoSuchFile error will be more informative than an
119
 
            # UnboundLocalError for br_to.
120
 
            raise
 
101
                raise errors.BzrCommandError("Parent directory of %s"
 
102
                    " does not exist."
 
103
                    "\nYou may supply --create-prefix to create all"
 
104
                    " leading parent directories."
 
105
                    % location)
121
106
        except errors.TooManyRedirections:
122
 
            raise errors.CommandError(gettext("Too many redirections trying "
123
 
                                                 "to make %s.") % location)
 
107
            raise errors.BzrCommandError("Too many redirections trying "
 
108
                                         "to make %s." % location)
124
109
        push_result = PushResult()
125
110
        # TODO: Some more useful message about what was copied
126
111
        try:
127
112
            push_result.stacked_on = br_to.get_stacked_on_url()
128
 
        except (_mod_branch.UnstackableBranchFormat,
 
113
        except (errors.UnstackableBranchFormat,
129
114
                errors.UnstackableRepositoryFormat,
130
115
                errors.NotStacked):
131
116
            push_result.stacked_on = None
132
117
        push_result.target_branch = br_to
133
118
        push_result.old_revid = _mod_revision.NULL_REVISION
134
119
        push_result.old_revno = 0
135
 
        # Remembers if asked explicitly or no previous location is set
136
 
        if (remember
137
 
                or (remember is None and br_from.get_push_location() is None)):
138
 
            # FIXME: Should be done only if we succeed ? -- vila 2012-01-18
 
120
        if br_from.get_push_location() is None or remember:
139
121
            br_from.set_push_location(br_to.base)
140
122
    else:
141
123
        if stacked_on is not None:
142
124
            warning("Ignoring request for a stacked branch as repository "
143
125
                    "already exists at the destination location.")
144
126
        try:
145
 
            push_result = dir_to.push_branch(br_from, revision_id, overwrite,
146
 
                                             remember, create_prefix, lossy=lossy)
 
127
            push_result = dir_to.push_branch(br_from, revision_id, overwrite, 
 
128
                remember, create_prefix)
147
129
        except errors.DivergedBranches:
148
 
            raise errors.CommandError(gettext('These branches have diverged.'
149
 
                                                 '  See "brz help diverged-branches"'
150
 
                                                 ' for more information.'))
151
 
        except errors.NoRoundtrippingSupport as e:
152
 
            raise errors.CommandError(
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)
 
130
            raise errors.BzrCommandError('These branches have diverged.'
 
131
                                    '  See "bzr help diverged-branches"'
 
132
                                    ' for more information.')
156
133
        except errors.NoRepositoryPresent:
157
 
            # we have a controldir but no branch or repository
 
134
            # we have a bzrdir but no branch or repository
158
135
            # XXX: Figure out what to do other than complain.
159
 
            raise errors.CommandError(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 "
 
136
            raise errors.BzrCommandError("At %s you have a valid .bzr"
 
137
                " control directory, but not a branch or repository. This"
 
138
                " is an unsupported configuration. Please move the target"
 
139
                " directory out of the way and try again." % location)
 
140
        if push_result.workingtree_updated == False:
 
141
            warning("This transport does not update the working " 
 
142
                    "tree of: %s. See 'bzr help working-trees' for "
166
143
                    "more information." % push_result.target_branch.base)
167
144
    push_result.report(to_file)
168
145
    if verbose:
169
146
        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,
 
147
        br_to.lock_read()
 
148
        try:
 
149
            from bzrlib.log import show_branch_change
 
150
            show_branch_change(br_to, to_file, push_result.old_revno, 
173
151
                               push_result.old_revid)
 
152
        finally:
 
153
            br_to.unlock()
 
154
 
 
155