~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/upgrade.py

Dirty merge of the mainline

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
84
84
from bzrlib.osutils import sha_strings, sha_string, pathjoin, abspath
85
85
 
86
86
 
 
87
# TODO: jam 20060108 Create a new branch format, and as part of upgrade
 
88
#       make sure that ancestry.weave is deleted (it is never used, but
 
89
#       used to be created)
 
90
 
 
91
 
87
92
class Convert(object):
88
93
    def __init__(self, base_dir):
89
94
        self.base = base_dir
102
107
        self.pb = ui_factory.progress_bar()
103
108
        if self.old_format == 4:
104
109
            note('starting upgrade from format 4 to 5')
105
 
            self._convert_to_weaves()
 
110
            self.branch.lock_write()
 
111
            try:
 
112
                self._convert_to_weaves()
 
113
            finally:
 
114
                self.branch.unlock()
106
115
            self._open_branch()
107
116
        if self.old_format == 5:
108
117
            note('starting upgrade from format 5 to 6')
109
 
            self._convert_to_prefixed()
 
118
            self.branch.lock_write()
 
119
            try:
 
120
                self._convert_to_prefixed()
 
121
            finally:
 
122
                self.branch.unlock()
110
123
            self._open_branch()
111
124
        cache = hashcache.HashCache(abspath(self.base))
112
125
        cache.clear()
139
152
        self.inv_weave = Weave('inventory')
140
153
        # holds in-memory weaves for all files
141
154
        self.text_weaves = {}
142
 
        os.remove(self.branch.controlfilename('branch-format'))
 
155
        os.remove(self.branch.control_files.controlfilename('branch-format'))
143
156
        self._convert_working_inv()
144
157
        rev_history = self.branch.revision_history()
145
158
        # to_read is a stack holding the revisions we still need to process;
178
191
                           self.branch._branch_format)
179
192
        return True
180
193
 
181
 
 
182
194
    def _set_new_format(self, format):
183
 
        self.branch.put_controlfile('branch-format', format)
184
 
 
 
195
        self.branch.control_files.put_utf8('branch-format', format)
185
196
 
186
197
    def _cleanup_spare_files(self):
187
198
        for n in 'merged-patches', 'pending-merged-patches':
188
 
            p = self.branch.controlfilename(n)
 
199
            p = self.branch.control_files.controlfilename(n)
189
200
            if not os.path.exists(p):
190
201
                continue
191
202
            ## assert os.path.getsize(p) == 0
193
204
        shutil.rmtree(self.base + '/.bzr/inventory-store')
194
205
        shutil.rmtree(self.base + '/.bzr/text-store')
195
206
 
196
 
 
197
207
    def _backup_control_dir(self):
198
208
        orig = self.base + '/.bzr'
199
209
        backup = orig + '.backup'
203
213
        note('if conversion fails, you can move this directory back to .bzr')
204
214
        note('if it succeeds, you can remove this directory if you wish')
205
215
 
206
 
 
207
216
    def _convert_working_inv(self):
208
217
        branch = self.branch
209
 
        inv = serializer_v4.read_inventory(branch.controlfile('inventory', 'rb'))
 
218
        inv = serializer_v4.read_inventory(branch.control_files.get('inventory'))
210
219
        new_inv_xml = serializer_v5.write_inventory_to_string(inv)
211
 
        branch.put_controlfile('inventory', new_inv_xml)
212
 
 
213
 
 
 
220
        branch.control_files.put('inventory', new_inv_xml)
214
221
 
215
222
    def _write_all_weaves(self):
216
223
        write_a_weave(self.inv_weave, self.base + '/.bzr/inventory.weave')
248
255
        self.pb.update('loading revision',
249
256
                       len(self.revisions),
250
257
                       len(self.known_revisions))
251
 
        if not self.branch.revision_store.has_id(rev_id):
 
258
        if not self.branch.repository.revision_store.has_id(rev_id):
252
259
            self.pb.clear()
253
260
            note('revision {%s} not present in branch; '
254
261
                 'will be converted as a ghost',
255
262
                 rev_id)
256
263
            self.absent_revisions.add(rev_id)
257
264
        else:
258
 
            rev_xml = self.branch.revision_store.get(rev_id).read()
 
265
            rev_xml = self.branch.repository.revision_store.get(rev_id).read()
259
266
            rev = serializer_v4.read_revision_from_string(rev_xml)
260
267
            for parent_id in rev.parent_ids:
261
268
                self.known_revisions.add(parent_id)
265
272
 
266
273
    def _load_old_inventory(self, rev_id):
267
274
        assert rev_id not in self.converted_revs
268
 
        old_inv_xml = self.branch.inventory_store.get(rev_id).read()
 
275
        old_inv_xml = self.branch.repository.inventory_store.get(rev_id).read()
269
276
        inv = serializer_v4.read_inventory_from_string(old_inv_xml)
270
277
        rev = self.revisions[rev_id]
271
278
        if rev.inventory_sha1:
360
367
                return
361
368
        parent_indexes = map(w.lookup, previous_revisions)
362
369
        if ie.has_text():
363
 
            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()
364
372
            assert sha_strings(file_lines) == ie.text_sha1
365
373
            assert sum(map(len, file_lines)) == ie.text_size
366
374
            w.add(rev_id, parent_indexes, file_lines, ie.text_sha1)