~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/upgrade.py

  • Committer: Aaron Bentley
  • Date: 2005-10-03 19:50:36 UTC
  • mfrom: (1399)
  • mto: (1185.25.1)
  • mto: This revision was merged to the branch mainline in revision 1419.
  • Revision ID: abentley@panoramicfeedback.com-20051003195036-28dbd56f0e852b08
Merged latest from Robert Collins

Show diffs side-by-side

added added

removed removed

Lines of Context:
160
160
 
161
161
 
162
162
    def _set_new_format(self):
163
 
        f = self.branch.controlfile('branch-format', 'wb')
164
 
        try:
165
 
            f.write(BZR_BRANCH_FORMAT_5)
166
 
        finally:
167
 
            f.close()
 
163
        self.branch.put_controlfile('branch-format', BZR_BRANCH_FORMAT_5)
168
164
 
169
165
 
170
166
    def _cleanup_spare_files(self):
191
187
    def _convert_working_inv(self):
192
188
        branch = self.branch
193
189
        inv = serializer_v4.read_inventory(branch.controlfile('inventory', 'rb'))
194
 
        serializer_v5.write_inventory(inv, branch.controlfile('inventory', 'wb'))
 
190
        new_inv_xml = serializer_v5.write_inventory_to_string(inv)
 
191
        branch.put_controlfile('inventory', new_inv_xml)
195
192
 
196
193
 
197
194
 
287
284
                ie = inv[file_id]
288
285
                if ie.kind == 'root_directory':
289
286
                    continue
290
 
                assert hasattr(ie, 'name_version'), \
291
 
                    'no name_version on {%s} in {%s}' % \
 
287
                assert hasattr(ie, 'revision'), \
 
288
                    'no revision on {%s} in {%s}' % \
292
289
                    (file_id, rev.revision_id)
293
 
                if ie.kind == 'file':
294
 
                    assert hasattr(ie, 'text_version')
295
290
 
296
291
        new_inv_xml = serializer_v5.write_inventory_to_string(inv)
297
292
        new_inv_sha1 = sha_string(new_inv_xml)
328
323
        parent_invs = map(self._load_updated_inventory, rev.parent_ids)
329
324
        for file_id in inv:
330
325
            ie = inv[file_id]
331
 
            self._set_name_version(rev, ie, parent_invs)
 
326
            self._set_revision(rev, ie, parent_invs)
332
327
            if ie.kind != 'file':
333
328
                continue
334
329
            self._convert_file_version(rev, ie, parent_invs)
335
330
 
336
331
 
337
 
    def _set_name_version(self, rev, ie, parent_invs):
 
332
    def _set_revision(self, rev, ie, parent_invs):
338
333
        """Set name version for a file.
339
334
 
340
335
        Done in a slightly lazy way: if the file is renamed or in a merge revision
344
339
        if ie.kind == 'root_directory':
345
340
            return
346
341
        if len(parent_invs) != 1:
347
 
            ie.name_version = rev.revision_id
 
342
            ie.revision = rev.revision_id
348
343
        else:
349
344
            old_inv = parent_invs[0]
350
345
            if not old_inv.has_id(file_id):
351
 
                ie.name_version = rev.revision_id
 
346
                ie.revision = rev.revision_id
352
347
            else:
353
348
                old_ie = old_inv[file_id]
354
349
                if (old_ie.parent_id != ie.parent_id
355
350
                    or old_ie.name != ie.name):
356
 
                    ie.name_version = rev.revision_id
 
351
                    ie.revision = rev.revision_id
357
352
                else:
358
 
                    ie.name_version = old_ie.name_version
 
353
                    ie.revision = old_ie.revision
359
354
 
360
355
 
361
356
 
376
371
        for parent_inv in parent_invs:
377
372
            if parent_inv.has_id(file_id):
378
373
                parent_ie = parent_inv[file_id]
379
 
                old_text_version = parent_ie.text_version
380
 
                assert old_text_version in self.converted_revs 
381
 
                if old_text_version not in file_parents:
382
 
                    file_parents.append(old_text_version)
 
374
                old_revision = parent_ie.revision
 
375
                # if this fails, its a ghost ?
 
376
                assert old_revision in self.converted_revs 
 
377
                if old_revision not in file_parents:
 
378
                    file_parents.append(old_revision)
383
379
                if parent_ie.text_sha1 != ie.text_sha1:
384
380
                    text_changed = True
385
381
        if len(file_parents) != 1 or text_changed:
387
383
            assert sha_strings(file_lines) == ie.text_sha1
388
384
            assert sum(map(len, file_lines)) == ie.text_size
389
385
            w.add(rev_id, file_parents, file_lines, ie.text_sha1)
390
 
            ie.text_version = rev_id
 
386
            ie.revision = rev_id
391
387
            self.text_count += 1
392
388
            ##mutter('import text {%s} of {%s}',
393
389
            ##       ie.text_id, file_id)
394
390
        else:
395
391
            ##mutter('text of {%s} unchanged from parent', file_id)
396
 
            ie.text_version = file_parents[0]
 
392
            ie.revision = file_parents[0]
397
393
        del ie.text_id
398
394
 
399
395