~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/upgrade.py

  • Committer: Martin Pool
  • Date: 2006-01-30 06:23:50 UTC
  • mfrom: (1534.1.17 integration)
  • Revision ID: mbp@sourcefrog.net-20060130062350-d6f25277ddcdfd79
[merge] robert's integration of much recent work

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
import sys
72
72
import shutil
73
73
 
74
 
from bzrlib.branch import Branch, find_branch
 
74
from bzrlib.branch import Branch
75
75
from bzrlib.branch import BZR_BRANCH_FORMAT_5, BZR_BRANCH_FORMAT_6
76
76
import bzrlib.hashcache as hashcache
77
77
from bzrlib.weave import Weave
107
107
        self.pb = ui_factory.progress_bar()
108
108
        if self.old_format == 4:
109
109
            note('starting upgrade from format 4 to 5')
110
 
            self._convert_to_weaves()
 
110
            self.branch.lock_write()
 
111
            try:
 
112
                self._convert_to_weaves()
 
113
            finally:
 
114
                self.branch.unlock()
111
115
            self._open_branch()
112
116
        if self.old_format == 5:
113
117
            note('starting upgrade from format 5 to 6')
114
 
            self._convert_to_prefixed()
 
118
            self.branch.lock_write()
 
119
            try:
 
120
                self._convert_to_prefixed()
 
121
            finally:
 
122
                self.branch.unlock()
115
123
            self._open_branch()
116
124
        cache = hashcache.HashCache(abspath(self.base))
117
125
        cache.clear()
144
152
        self.inv_weave = Weave('inventory')
145
153
        # holds in-memory weaves for all files
146
154
        self.text_weaves = {}
147
 
        os.remove(self.branch.controlfilename('branch-format'))
 
155
        os.remove(self.branch.control_files.controlfilename('branch-format'))
148
156
        self._convert_working_inv()
149
157
        rev_history = self.branch.revision_history()
150
158
        # to_read is a stack holding the revisions we still need to process;
183
191
                           self.branch._branch_format)
184
192
        return True
185
193
 
186
 
 
187
194
    def _set_new_format(self, format):
188
 
        self.branch.put_controlfile('branch-format', format)
189
 
 
 
195
        self.branch.control_files.put_utf8('branch-format', format)
190
196
 
191
197
    def _cleanup_spare_files(self):
192
198
        for n in 'merged-patches', 'pending-merged-patches':
193
 
            p = self.branch.controlfilename(n)
 
199
            p = self.branch.control_files.controlfilename(n)
194
200
            if not os.path.exists(p):
195
201
                continue
196
202
            ## assert os.path.getsize(p) == 0
198
204
        shutil.rmtree(self.base + '/.bzr/inventory-store')
199
205
        shutil.rmtree(self.base + '/.bzr/text-store')
200
206
 
201
 
 
202
207
    def _backup_control_dir(self):
203
208
        orig = self.base + '/.bzr'
204
209
        backup = orig + '.backup'
208
213
        note('if conversion fails, you can move this directory back to .bzr')
209
214
        note('if it succeeds, you can remove this directory if you wish')
210
215
 
211
 
 
212
216
    def _convert_working_inv(self):
213
217
        branch = self.branch
214
 
        inv = serializer_v4.read_inventory(branch.controlfile('inventory', 'rb'))
 
218
        inv = serializer_v4.read_inventory(branch.control_files.get('inventory'))
215
219
        new_inv_xml = serializer_v5.write_inventory_to_string(inv)
216
 
        branch.put_controlfile('inventory', new_inv_xml)
217
 
 
218
 
 
 
220
        branch.control_files.put('inventory', new_inv_xml)
219
221
 
220
222
    def _write_all_weaves(self):
221
223
        write_a_weave(self.inv_weave, self.base + '/.bzr/inventory.weave')
253
255
        self.pb.update('loading revision',
254
256
                       len(self.revisions),
255
257
                       len(self.known_revisions))
256
 
        if not self.branch.revision_store.has_id(rev_id):
 
258
        if not self.branch.repository.revision_store.has_id(rev_id):
257
259
            self.pb.clear()
258
260
            note('revision {%s} not present in branch; '
259
261
                 'will be converted as a ghost',
260
262
                 rev_id)
261
263
            self.absent_revisions.add(rev_id)
262
264
        else:
263
 
            rev_xml = self.branch.revision_store.get(rev_id).read()
 
265
            rev_xml = self.branch.repository.revision_store.get(rev_id).read()
264
266
            rev = serializer_v4.read_revision_from_string(rev_xml)
265
267
            for parent_id in rev.parent_ids:
266
268
                self.known_revisions.add(parent_id)
270
272
 
271
273
    def _load_old_inventory(self, rev_id):
272
274
        assert rev_id not in self.converted_revs
273
 
        old_inv_xml = self.branch.inventory_store.get(rev_id).read()
 
275
        old_inv_xml = self.branch.repository.inventory_store.get(rev_id).read()
274
276
        inv = serializer_v4.read_inventory_from_string(old_inv_xml)
275
277
        rev = self.revisions[rev_id]
276
278
        if rev.inventory_sha1:
365
367
                return
366
368
        parent_indexes = map(w.lookup, previous_revisions)
367
369
        if ie.has_text():
368
 
            file_lines = self.branch.text_store.get(ie.text_id).readlines()
 
370
            text = self.branch.repository.text_store.get(ie.text_id)
 
371
            file_lines = text.readlines()
369
372
            assert sha_strings(file_lines) == ie.text_sha1
370
373
            assert sum(map(len, file_lines)) == ie.text_size
371
374
            w.add(rev_id, parent_indexes, file_lines, ie.text_sha1)