~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/upgrade.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-17 18:13:57 UTC
  • mfrom: (5268.7.29 transport-segments)
  • Revision ID: pqm@pqm.ubuntu.com-20110817181357-y5q5eth1hk8bl3om
(jelmer) Allow specifying the colocated branch to use in the branch URL,
 and retrieving the branch name using ControlDir._get_selected_branch.
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""bzr upgrade logic."""
18
18
 
19
 
from __future__ import absolute_import
20
19
 
21
20
from bzrlib import (
22
21
    errors,
23
22
    trace,
24
23
    ui,
25
 
    urlutils,
26
24
    )
27
 
from bzrlib.controldir import (
28
 
    ControlDir,
 
25
from bzrlib.bzrdir import (
 
26
    BzrDir,
29
27
    format_registry,
30
28
    )
31
 
from bzrlib.i18n import gettext
32
29
from bzrlib.remote import RemoteBzrDir
33
30
 
34
31
 
55
52
        if control_dir is not None:
56
53
            self.bzrdir = control_dir
57
54
        else:
58
 
            self.bzrdir = ControlDir.open_unsupported(url)
 
55
            self.bzrdir = BzrDir.open_unsupported(url)
59
56
        if isinstance(self.bzrdir, RemoteBzrDir):
60
57
            self.bzrdir._ensure_real()
61
58
            self.bzrdir = self.bzrdir._real_bzrdir
73
70
        try:
74
71
            branch = self.bzrdir.open_branch()
75
72
            if branch.user_url != self.bzrdir.user_url:
76
 
                ui.ui_factory.note(gettext(
 
73
                ui.ui_factory.note(
77
74
                    'This is a checkout. The branch (%s) needs to be upgraded'
78
 
                    ' separately.') % (urlutils.unescape_for_display(
79
 
                        branch.user_url, 'utf-8')))
 
75
                    ' separately.' % (branch.user_url,))
80
76
            del branch
81
77
        except (errors.NotBranchError, errors.IncompatibleRepositories):
82
78
            # might not be a format we can open without upgrading; see e.g.
97
93
        if not self.bzrdir.needs_format_conversion(format):
98
94
            raise errors.UpToDateFormat(self.bzrdir._format)
99
95
        if not self.bzrdir.can_convert_format():
100
 
            raise errors.BzrError(gettext("cannot upgrade from bzrdir format %s") %
 
96
            raise errors.BzrError("cannot upgrade from bzrdir format %s" %
101
97
                           self.bzrdir._format)
102
98
        self.bzrdir.check_conversion_target(format)
103
 
        ui.ui_factory.note(gettext('starting upgrade of %s') % 
104
 
            urlutils.unescape_for_display(self.transport.base, 'utf-8'))
 
99
        ui.ui_factory.note('starting upgrade of %s' % self.transport.base)
105
100
 
106
101
        self.backup_oldpath, self.backup_newpath = self.bzrdir.backup_bzrdir()
107
102
        while self.bzrdir.needs_format_conversion(format):
108
103
            converter = self.bzrdir._format.get_converter(format)
109
104
            self.bzrdir = converter.convert(self.bzrdir, None)
110
 
        ui.ui_factory.note(gettext('finished'))
 
105
        ui.ui_factory.note('finished')
111
106
 
112
107
    def clean_up(self):
113
108
        """Clean-up after a conversion.
117
112
        transport = self.transport
118
113
        backup_relpath = transport.relpath(self.backup_newpath)
119
114
        child_pb = ui.ui_factory.nested_progress_bar()
120
 
        child_pb.update(gettext('Deleting backup.bzr'))
 
115
        child_pb.update('Deleting backup.bzr')
121
116
        try:
122
117
            transport.delete_tree(backup_relpath)
123
118
        finally:
140
135
    :param dry_run: show what would happen but don't actually do any upgrades
141
136
    :return: the list of exceptions encountered
142
137
    """
143
 
    control_dirs = [ControlDir.open_unsupported(url)]
 
138
    control_dirs = [BzrDir.open_unsupported(url)]
144
139
    attempted, succeeded, exceptions = smart_upgrade(control_dirs,
145
140
        format, clean_up=clean_up, dry_run=dry_run)
146
141
    if len(attempted) > 1:
148
143
        succeeded_count = len(succeeded)
149
144
        failed_count = attempted_count - succeeded_count
150
145
        ui.ui_factory.note(
151
 
            gettext('\nSUMMARY: {0} upgrades attempted, {1} succeeded,'\
152
 
                    ' {2} failed').format(
153
 
                     attempted_count, succeeded_count, failed_count))
 
146
            '\nSUMMARY: %d upgrades attempted, %d succeeded, %d failed'
 
147
            % (attempted_count, succeeded_count, failed_count))
154
148
    return exceptions
155
149
 
156
150
 
205
199
    succeeded, exceptions = _convert_items([control_dir], format, clean_up,
206
200
                                           dry_run)
207
201
    if succeeded and dependents:
208
 
        ui.ui_factory.note(gettext('Found %d dependent branches - upgrading ...')
 
202
        ui.ui_factory.note('Found %d dependent branches - upgrading ...'
209
203
                           % (len(dependents),))
210
204
        # Convert dependent branches
211
205
        branch_cdirs = [b.bzrdir for b in dependents]
273
267
    succeeded = []
274
268
    exceptions = []
275
269
    child_pb = ui.ui_factory.nested_progress_bar()
276
 
    child_pb.update(gettext('Upgrading bzrdirs'), 0, len(items))
 
270
    child_pb.update('Upgrading bzrdirs', 0, len(items))
277
271
    for i, control_dir in enumerate(items):
278
272
        # Do the conversion
279
273
        location = control_dir.root_transport.base
280
274
        bzr_object, bzr_label = _get_object_and_label(control_dir)
281
275
        type_label = label or bzr_label
282
 
        child_pb.update(gettext("Upgrading %s") % (type_label), i+1, len(items))
283
 
        ui.ui_factory.note(gettext('Upgrading {0} {1} ...').format(type_label, 
284
 
            urlutils.unescape_for_display(location, 'utf-8'),))
 
276
        child_pb.update("Upgrading %s" % (type_label), i+1, len(items))
 
277
        ui.ui_factory.note('Upgrading %s %s ...' % (type_label, location,))
285
278
        try:
286
279
            if not dry_run:
287
280
                cv = Convert(control_dir=control_dir, format=format)
288
 
        except errors.UpToDateFormat, ex:
289
 
            ui.ui_factory.note(str(ex))
290
 
            succeeded.append(control_dir)
291
 
            continue
292
281
        except Exception, ex:
293
282
            trace.warning('conversion error: %s' % ex)
294
283
            exceptions.append(ex)
298
287
        succeeded.append(control_dir)
299
288
        if clean_up:
300
289
            try:
301
 
                ui.ui_factory.note(gettext('Removing backup ...'))
 
290
                ui.ui_factory.note('Removing backup ...')
302
291
                if not dry_run:
303
292
                    cv.clean_up()
304
293
            except Exception, ex:
305
 
                trace.warning(gettext('failed to clean-up {0}: {1}') % (location, ex))
 
294
                trace.warning('failed to clean-up %s: %s' % (location, ex))
306
295
                exceptions.append(ex)
307
296
 
308
297
    child_pb.finished()