~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/upgrade.py

first cut at merge from integration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
import sys
72
72
from stat import *
73
73
 
74
 
from bzrlib.branch import Branch, find_branch
 
74
import bzrlib
 
75
from bzrlib.branch import Branch
75
76
from bzrlib.branch import BZR_BRANCH_FORMAT_5, BZR_BRANCH_FORMAT_6
76
77
from bzrlib.branch import BzrBranchFormat, BzrBranchFormat4, BzrBranchFormat5, BzrBranchFormat6
77
78
from bzrlib.errors import NoSuchFile, UpgradeReadonly
78
79
import bzrlib.hashcache as hashcache
 
80
from bzrlib.lockable_files import LockableFiles
79
81
from bzrlib.osutils import sha_strings, sha_string, pathjoin, abspath
80
82
from bzrlib.ui import ui_factory
81
83
from bzrlib.store.text import TextStore
99
101
        self.text_count = 0
100
102
        self.revisions = {}
101
103
        self.transport = transport
102
 
        self.convert()
103
 
 
104
 
    def convert(self):
105
104
        if self.transport.is_readonly():
106
105
            raise UpgradeReadonly
 
106
        self.control_files = LockableFiles(transport.clone(bzrlib.BZRDIR), 'branch-lock')
 
107
        # Lock the branch (soon to be meta dir) to prevent anyone racing with us
 
108
        # This is currently windows incompatible, it will deadlock. When the upgrade
 
109
        # logic becomes format specific, then we can have the format know how to pass this
 
110
        # on. Also note that we probably have an 'upgrade meta' which upgrades the constituent
 
111
        # parts.
 
112
        print "FIXME: control files reuse" 
 
113
        self.control_files.lock_write()
 
114
        try:
 
115
            self.convert()
 
116
        finally:
 
117
            self.control_files.unlock()
 
118
 
 
119
    def convert(self):
107
120
        if not self._open_branch():
108
121
            return
109
122
        note('starting upgrade of %s', self.base)
200
213
        return True
201
214
 
202
215
    def _set_new_format(self, format):
203
 
        self.branch.put_controlfile('branch-format', format)
 
216
        self.branch.control_files.put_utf8('branch-format', format)
204
217
 
205
218
    def _cleanup_spare_files_after_format4(self):
206
219
        transport = self.transport.clone('.bzr')
 
220
        print "FIXME working tree upgrade foo."
207
221
        for n in 'merged-patches', 'pending-merged-patches':
208
222
            try:
209
223
                ## assert os.path.getsize(p) == 0
224
238
 
225
239
    def _convert_working_inv(self):
226
240
        branch = self.branch
227
 
        inv = serializer_v4.read_inventory(branch.controlfile('inventory', 'rb'))
 
241
        inv = serializer_v4.read_inventory(branch.control_files.get('inventory'))
228
242
        new_inv_xml = serializer_v5.write_inventory_to_string(inv)
229
 
        branch.put_controlfile('inventory', new_inv_xml)
 
243
        print "fixme inventory is a working tree change."
 
244
        branch.control_files.put('inventory', new_inv_xml)
230
245
 
231
246
    def _write_all_weaves(self):
232
247
        bzr_transport = self.transport.clone('.bzr')
274
289
        self.pb.update('loading revision',
275
290
                       len(self.revisions),
276
291
                       len(self.known_revisions))
277
 
        if not self.branch.revision_store.has_id(rev_id):
 
292
        if not self.branch.repository.revision_store.has_id(rev_id):
278
293
            self.pb.clear()
279
294
            note('revision {%s} not present in branch; '
280
295
                 'will be converted as a ghost',
281
296
                 rev_id)
282
297
            self.absent_revisions.add(rev_id)
283
298
        else:
284
 
            rev_xml = self.branch.revision_store.get(rev_id).read()
 
299
            rev_xml = self.branch.repository.revision_store.get(rev_id).read()
285
300
            rev = serializer_v4.read_revision_from_string(rev_xml)
286
301
            for parent_id in rev.parent_ids:
287
302
                self.known_revisions.add(parent_id)
291
306
 
292
307
    def _load_old_inventory(self, rev_id):
293
308
        assert rev_id not in self.converted_revs
294
 
        old_inv_xml = self.branch.inventory_store.get(rev_id).read()
 
309
        old_inv_xml = self.branch.repository.inventory_store.get(rev_id).read()
295
310
        inv = serializer_v4.read_inventory_from_string(old_inv_xml)
296
311
        rev = self.revisions[rev_id]
297
312
        if rev.inventory_sha1:
386
401
                return
387
402
        parent_indexes = map(w.lookup, previous_revisions)
388
403
        if ie.has_text():
389
 
            file_lines = self.branch.text_store.get(ie.text_id).readlines()
 
404
            text = self.branch.repository.text_store.get(ie.text_id)
 
405
            file_lines = text.readlines()
390
406
            assert sha_strings(file_lines) == ie.text_sha1
391
407
            assert sum(map(len, file_lines)) == ie.text_size
392
408
            w.add(rev_id, parent_indexes, file_lines, ie.text_sha1)