/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 breezy/upgrade.py

  • Committer: Jelmer Vernooij
  • Date: 2018-06-14 17:59:16 UTC
  • mto: This revision was merged to the branch mainline in revision 7065.
  • Revision ID: jelmer@jelmer.uk-20180614175916-a2e2xh5k533guq1x
Move breezy.plugins.git to breezy.git.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""brz upgrade logic."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
from . import (
20
22
    errors,
21
23
    trace,
84
86
            try:
85
87
                rich_root = self.controldir.find_repository()._format.rich_root_data
86
88
            except errors.NoRepositoryPresent:
87
 
                rich_root = False  # assume no rich roots
 
89
                rich_root = False # assume no rich roots
88
90
            if rich_root:
89
91
                format_name = "default-rich-root"
90
92
            else:
96
98
            raise errors.UpToDateFormat(self.controldir._format)
97
99
        if not self.controldir.can_convert_format():
98
100
            raise errors.BzrError(gettext("cannot upgrade from bzrdir format %s") %
99
 
                                  self.controldir._format)
 
101
                           self.controldir._format)
100
102
        self.controldir.check_conversion_target(format)
101
 
        ui.ui_factory.note(gettext('starting upgrade of %s') %
102
 
                           urlutils.unescape_for_display(self.transport.base, 'utf-8'))
 
103
        ui.ui_factory.note(gettext('starting upgrade of %s') % 
 
104
            urlutils.unescape_for_display(self.transport.base, 'utf-8'))
103
105
 
104
106
        self.backup_oldpath, self.backup_newpath = self.controldir.backup_bzrdir()
105
107
        while self.controldir.needs_format_conversion(format):
121
123
 
122
124
def upgrade(url, format=None, clean_up=False, dry_run=False):
123
125
    """Upgrade locations to format.
124
 
 
 
126
 
125
127
    This routine wraps the smart_upgrade() routine with a nicer UI.
126
128
    In particular, it ensures all URLs can be opened before starting
127
129
    and reports a summary at the end if more than one upgrade was attempted.
137
139
    """
138
140
    control_dirs = [ControlDir.open_unsupported(url)]
139
141
    attempted, succeeded, exceptions = smart_upgrade(control_dirs,
140
 
                                                     format, clean_up=clean_up, dry_run=dry_run)
 
142
        format, clean_up=clean_up, dry_run=dry_run)
141
143
    if len(attempted) > 1:
142
144
        attempted_count = len(attempted)
143
145
        succeeded_count = len(succeeded)
144
146
        failed_count = attempted_count - succeeded_count
145
147
        ui.ui_factory.note(
146
 
            gettext('\nSUMMARY: {0} upgrades attempted, {1} succeeded,'
 
148
            gettext('\nSUMMARY: {0} upgrades attempted, {1} succeeded,'\
147
149
                    ' {2} failed').format(
148
 
                attempted_count, succeeded_count, failed_count))
 
150
                     attempted_count, succeeded_count, failed_count))
149
151
    return exceptions
150
152
 
151
153
 
152
154
def smart_upgrade(control_dirs, format, clean_up=False,
153
 
                  dry_run=False):
 
155
    dry_run=False):
154
156
    """Convert control directories to a new format intelligently.
155
157
 
156
158
    If the control directory is a shared repository, dependent branches
169
171
    all_exceptions = []
170
172
    for control_dir in control_dirs:
171
173
        attempted, succeeded, exceptions = _smart_upgrade_one(control_dir,
172
 
                                                              format, clean_up=clean_up, dry_run=dry_run)
 
174
            format, clean_up=clean_up, dry_run=dry_run)
173
175
        all_attempted.extend(attempted)
174
176
        all_succeeded.extend(succeeded)
175
177
        all_exceptions.extend(exceptions)
177
179
 
178
180
 
179
181
def _smart_upgrade_one(control_dir, format, clean_up=False,
180
 
                       dry_run=False):
 
182
    dry_run=False):
181
183
    """Convert a control directory to a new format intelligently.
182
184
 
183
185
    See smart_upgrade for parameter details.
193
195
        # The URL is a repository. If it successfully upgrades,
194
196
        # then upgrade the dependent branches as well.
195
197
        if repo.is_shared():
196
 
            dependents = list(repo.find_branches(using=True))
 
198
            dependents = repo.find_branches(using=True)
197
199
 
198
200
    # Do the conversions
199
201
    attempted = [control_dir]
205
207
        # Convert dependent branches
206
208
        branch_cdirs = [b.controldir for b in dependents]
207
209
        successes, problems = _convert_items(branch_cdirs, format, clean_up,
208
 
                                             dry_run, label="branch")
 
210
            dry_run, label="branch")
209
211
        attempted.extend(branch_cdirs)
210
212
        succeeded.extend(successes)
211
213
        exceptions.extend(problems)
218
220
# - raising AssertionError is rude and may not be necessary
219
221
# - no tests
220
222
# - the only caller uses only the label
221
 
 
222
 
 
223
223
def _get_object_and_label(control_dir):
224
224
    """Return the primary object and type label for a control directory.
225
225
 
258
258
 
259
259
def _convert_items(items, format, clean_up, dry_run, label=None):
260
260
    """Convert a sequence of control directories to the given format.
261
 
 
 
261
 
262
262
    :param items: the control directories to upgrade
263
263
    :param format: the format to convert to or None for the best default
264
264
    :param clean-up: if True, the backup.bzr directory is removed if the
276
276
            location = control_dir.root_transport.base
277
277
            bzr_object, bzr_label = _get_object_and_label(control_dir)
278
278
            type_label = label or bzr_label
279
 
            child_pb.update(gettext("Upgrading %s") %
280
 
                            (type_label), i + 1, len(items))
281
 
            ui.ui_factory.note(gettext('Upgrading {0} {1} ...').format(type_label,
282
 
                                                                       urlutils.unescape_for_display(location, 'utf-8'),))
 
279
            child_pb.update(gettext("Upgrading %s") % (type_label), i+1, len(items))
 
280
            ui.ui_factory.note(gettext('Upgrading {0} {1} ...').format(type_label, 
 
281
                urlutils.unescape_for_display(location, 'utf-8'),))
283
282
            try:
284
283
                if not dry_run:
285
284
                    cv = Convert(control_dir=control_dir, format=format)
300
299
                    if not dry_run:
301
300
                        cv.clean_up()
302
301
                except Exception as ex:
303
 
                    trace.warning(
304
 
                        gettext('failed to clean-up {0}: {1}') % (location, ex))
 
302
                    trace.warning(gettext('failed to clean-up {0}: {1}') % (location, ex))
305
303
                    exceptions.append(ex)
306
304
 
307
305
    # Return the result