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

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""brz upgrade logic."""
 
17
"""bzr upgrade logic."""
18
18
 
19
19
from __future__ import absolute_import
20
20
 
21
 
from . import (
 
21
from bzrlib import (
22
22
    errors,
23
23
    trace,
24
24
    ui,
25
25
    urlutils,
26
26
    )
27
 
from .controldir import (
 
27
from bzrlib.controldir import (
28
28
    ControlDir,
29
29
    format_registry,
30
30
    )
31
 
from .i18n import gettext
32
 
from .bzr.remote import RemoteBzrDir
 
31
from bzrlib.i18n import gettext
 
32
from bzrlib.remote import RemoteBzrDir
33
33
 
34
34
 
35
35
class Convert(object):
53
53
            raise AssertionError(
54
54
                "either the url or control_dir parameter must be set.")
55
55
        if control_dir is not None:
56
 
            self.controldir = control_dir
 
56
            self.bzrdir = control_dir
57
57
        else:
58
 
            self.controldir = ControlDir.open_unsupported(url)
59
 
        if isinstance(self.controldir, RemoteBzrDir):
60
 
            self.controldir._ensure_real()
61
 
            self.controldir = self.controldir._real_bzrdir
62
 
        if self.controldir.root_transport.is_readonly():
 
58
            self.bzrdir = ControlDir.open_unsupported(url)
 
59
        if isinstance(self.bzrdir, RemoteBzrDir):
 
60
            self.bzrdir._ensure_real()
 
61
            self.bzrdir = self.bzrdir._real_bzrdir
 
62
        if self.bzrdir.root_transport.is_readonly():
63
63
            raise errors.UpgradeReadonly
64
 
        self.transport = self.controldir.root_transport
 
64
        self.transport = self.bzrdir.root_transport
65
65
        ui.ui_factory.suppressed_warnings.add(warning_id)
66
66
        try:
67
67
            self.convert()
71
71
 
72
72
    def convert(self):
73
73
        try:
74
 
            branch = self.controldir.open_branch()
75
 
            if branch.user_url != self.controldir.user_url:
 
74
            branch = self.bzrdir.open_branch()
 
75
            if branch.user_url != self.bzrdir.user_url:
76
76
                ui.ui_factory.note(gettext(
77
77
                    'This is a checkout. The branch (%s) needs to be upgraded'
78
78
                    ' separately.') % (urlutils.unescape_for_display(
84
84
            pass
85
85
        if self.format is None:
86
86
            try:
87
 
                rich_root = self.controldir.find_repository()._format.rich_root_data
 
87
                rich_root = self.bzrdir.find_repository()._format.rich_root_data
88
88
            except errors.NoRepositoryPresent:
89
89
                rich_root = False # assume no rich roots
90
90
            if rich_root:
91
91
                format_name = "default-rich-root"
92
92
            else:
93
93
                format_name = "default"
94
 
            format = format_registry.make_controldir(format_name)
 
94
            format = format_registry.make_bzrdir(format_name)
95
95
        else:
96
96
            format = self.format
97
 
        if not self.controldir.needs_format_conversion(format):
98
 
            raise errors.UpToDateFormat(self.controldir._format)
99
 
        if not self.controldir.can_convert_format():
 
97
        if not self.bzrdir.needs_format_conversion(format):
 
98
            raise errors.UpToDateFormat(self.bzrdir._format)
 
99
        if not self.bzrdir.can_convert_format():
100
100
            raise errors.BzrError(gettext("cannot upgrade from bzrdir format %s") %
101
 
                           self.controldir._format)
102
 
        self.controldir.check_conversion_target(format)
 
101
                           self.bzrdir._format)
 
102
        self.bzrdir.check_conversion_target(format)
103
103
        ui.ui_factory.note(gettext('starting upgrade of %s') % 
104
104
            urlutils.unescape_for_display(self.transport.base, 'utf-8'))
105
105
 
106
 
        self.backup_oldpath, self.backup_newpath = self.controldir.backup_bzrdir()
107
 
        while self.controldir.needs_format_conversion(format):
108
 
            converter = self.controldir._format.get_converter(format)
109
 
            self.controldir = converter.convert(self.controldir, None)
 
106
        self.backup_oldpath, self.backup_newpath = self.bzrdir.backup_bzrdir()
 
107
        while self.bzrdir.needs_format_conversion(format):
 
108
            converter = self.bzrdir._format.get_converter(format)
 
109
            self.bzrdir = converter.convert(self.bzrdir, None)
110
110
        ui.ui_factory.note(gettext('finished'))
111
111
 
112
112
    def clean_up(self):
116
116
        """
117
117
        transport = self.transport
118
118
        backup_relpath = transport.relpath(self.backup_newpath)
119
 
        with ui.ui_factory.nested_progress_bar() as child_pb:
120
 
            child_pb.update(gettext('Deleting backup.bzr'))
 
119
        child_pb = ui.ui_factory.nested_progress_bar()
 
120
        child_pb.update(gettext('Deleting backup.bzr'))
 
121
        try:
121
122
            transport.delete_tree(backup_relpath)
 
123
        finally:
 
124
            child_pb.finished()
122
125
 
123
126
 
124
127
def upgrade(url, format=None, clean_up=False, dry_run=False):
127
130
    This routine wraps the smart_upgrade() routine with a nicer UI.
128
131
    In particular, it ensures all URLs can be opened before starting
129
132
    and reports a summary at the end if more than one upgrade was attempted.
130
 
    This routine is useful for command line tools. Other breezy clients
 
133
    This routine is useful for command line tools. Other bzrlib clients
131
134
    probably ought to use smart_upgrade() instead.
132
135
 
133
136
    :param url: a URL of the locations to upgrade.
205
208
        ui.ui_factory.note(gettext('Found %d dependent branches - upgrading ...')
206
209
                           % (len(dependents),))
207
210
        # Convert dependent branches
208
 
        branch_cdirs = [b.controldir for b in dependents]
 
211
        branch_cdirs = [b.bzrdir for b in dependents]
209
212
        successes, problems = _convert_items(branch_cdirs, format, clean_up,
210
213
            dry_run, label="branch")
211
214
        attempted.extend(branch_cdirs)
269
272
    """
270
273
    succeeded = []
271
274
    exceptions = []
272
 
    with ui.ui_factory.nested_progress_bar() as child_pb:
273
 
        child_pb.update(gettext('Upgrading bzrdirs'), 0, len(items))
274
 
        for i, control_dir in enumerate(items):
275
 
            # Do the conversion
276
 
            location = control_dir.root_transport.base
277
 
            bzr_object, bzr_label = _get_object_and_label(control_dir)
278
 
            type_label = label or bzr_label
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'),))
 
275
    child_pb = ui.ui_factory.nested_progress_bar()
 
276
    child_pb.update(gettext('Upgrading bzrdirs'), 0, len(items))
 
277
    for i, control_dir in enumerate(items):
 
278
        # Do the conversion
 
279
        location = control_dir.root_transport.base
 
280
        bzr_object, bzr_label = _get_object_and_label(control_dir)
 
281
        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'),))
 
285
        try:
 
286
            if not dry_run:
 
287
                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
        except Exception, ex:
 
293
            trace.warning('conversion error: %s' % ex)
 
294
            exceptions.append(ex)
 
295
            continue
 
296
 
 
297
        # Do any required post processing
 
298
        succeeded.append(control_dir)
 
299
        if clean_up:
282
300
            try:
 
301
                ui.ui_factory.note(gettext('Removing backup ...'))
283
302
                if not dry_run:
284
 
                    cv = Convert(control_dir=control_dir, format=format)
285
 
            except errors.UpToDateFormat as ex:
286
 
                ui.ui_factory.note(str(ex))
287
 
                succeeded.append(control_dir)
288
 
                continue
289
 
            except Exception as ex:
290
 
                trace.warning('conversion error: %s' % ex)
 
303
                    cv.clean_up()
 
304
            except Exception, ex:
 
305
                trace.warning(gettext('failed to clean-up {0}: {1}') % (location, ex))
291
306
                exceptions.append(ex)
292
 
                continue
293
307
 
294
 
            # Do any required post processing
295
 
            succeeded.append(control_dir)
296
 
            if clean_up:
297
 
                try:
298
 
                    ui.ui_factory.note(gettext('Removing backup ...'))
299
 
                    if not dry_run:
300
 
                        cv.clean_up()
301
 
                except Exception as ex:
302
 
                    trace.warning(gettext('failed to clean-up {0}: {1}') % (location, ex))
303
 
                    exceptions.append(ex)
 
308
    child_pb.finished()
304
309
 
305
310
    # Return the result
306
311
    return succeeded, exceptions