~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/upgrade.py

Remove shutil dependency in upgrade - create a delete_tree method for transports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
import os
70
70
import tempfile
71
71
import sys
72
 
import shutil
73
72
from stat import *
74
73
 
75
74
from bzrlib.atomicfile import AtomicFile
104
103
            raise UpgradeReadonly
105
104
        if not self._open_branch():
106
105
            return
107
 
        note('starting upgrade of %s', os.path.abspath(self.base))
 
106
        note('starting upgrade of %s', self.base)
108
107
        self._backup_control_dir()
109
108
        self.pb = ui_factory.progress_bar()
110
109
        if isinstance(self.old_format, BzrBranchFormat4):
137
136
                          pathjoin(prefix_dir, filename))
138
137
        self._set_new_format(BZR_BRANCH_FORMAT_6)
139
138
 
140
 
 
141
139
    def _convert_to_weaves(self):
142
140
        note('note: upgrade may be faster if all store files are ungzipped first')
143
141
        if not os.path.isdir(self.base + '/.bzr/weaves'):
163
161
            self.pb.update('converting revision', i, len(to_import))
164
162
            self._convert_one_rev(rev_id)
165
163
        self.pb.clear()
 
164
        self._write_all_weaves()
 
165
        self._write_all_revs()
166
166
        note('upgraded to weaves:')
167
167
        note('  %6d revisions and inventories' % len(self.revisions))
168
168
        note('  %6d revisions not present' % len(self.absent_revisions))
169
169
        note('  %6d texts' % self.text_count)
170
 
        self._write_all_weaves()
171
 
        self._write_all_revs()
172
 
        self._cleanup_spare_files()
 
170
        self._cleanup_spare_files_after_format4()
173
171
        self._set_new_format(BZR_BRANCH_FORMAT_5)
174
172
 
175
 
 
176
173
    def _open_branch(self):
177
174
        self.branch = Branch.open_downlevel(self.base)
178
175
        self.old_format = self.branch._branch_format
185
182
                           self.branch._branch_format)
186
183
        return True
187
184
 
188
 
 
189
185
    def _set_new_format(self, format):
190
186
        self.branch.put_controlfile('branch-format', format)
191
187
 
192
 
 
193
 
    def _cleanup_spare_files(self):
 
188
    def _cleanup_spare_files_after_format4(self):
 
189
        transport = self.transport.clone('.bzr')
194
190
        for n in 'merged-patches', 'pending-merged-patches':
195
 
            p = self.branch.controlfilename(n)
196
 
            if not os.path.exists(p):
197
 
                continue
198
 
            ## assert os.path.getsize(p) == 0
199
 
            os.remove(p)
200
 
        shutil.rmtree(self.base + '/.bzr/inventory-store')
201
 
        shutil.rmtree(self.base + '/.bzr/text-store')
 
191
            try:
 
192
                ## assert os.path.getsize(p) == 0
 
193
                transport.delete(n)
 
194
            except NoSuchFile:
 
195
                pass
 
196
        transport.delete_tree('inventory-store')
 
197
        transport.delete_tree('text-store')
202
198
 
203
199
    def _backup_control_dir(self):
204
200
        note('making backup of tree history')
245
241
 
246
242
    def _write_all_revs(self):
247
243
        """Write all revisions out in new form."""
248
 
        shutil.rmtree(self.base + '/.bzr/revision-store')
249
 
        os.mkdir(self.base + '/.bzr/revision-store')
 
244
        transport = self.transport.clone('.bzr')
 
245
        transport.delete_tree('revision-store')
 
246
        transport.mkdir('revision-store')
250
247
        try:
251
248
            for i, rev_id in enumerate(self.converted_revs):
252
249
                self.pb.update('write revision', i, len(self.converted_revs))