~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/upgrade.py

  • Committer: Martin Pool
  • Date: 2005-10-06 04:09:55 UTC
  • mfrom: (1413)
  • mto: (1185.13.3)
  • mto: This revision was merged to the branch mainline in revision 1417.
  • Revision ID: mbp@sourcefrog.net-20051006040955-36f27e5a8d5c977b
[merge] from robert

Show diffs side-by-side

added added

removed removed

Lines of Context:
323
323
        parent_invs = map(self._load_updated_inventory, present_parents)
324
324
        for file_id in inv:
325
325
            ie = inv[file_id]
326
 
            self._set_revision(rev, ie, parent_invs)
327
 
            if not ie.has_text():
328
 
                continue
329
326
            self._convert_file_version(rev, ie, parent_invs)
330
327
 
331
 
 
332
 
    def _set_revision(self, rev, ie, parent_invs):
333
 
        """Set name version for a file.
334
 
        """
335
 
        file_id = ie.file_id
336
 
        if ie.kind == 'root_directory':
337
 
            return
338
 
        if len(parent_invs) == 0:
339
 
            ie.revision = rev.revision_id
340
 
        else:
341
 
            matched_id = None
342
 
            for p_inv in parent_invs:
343
 
                if not p_inv.has_id(file_id):
344
 
                    ie.revision = rev.revision_id
345
 
                    break
346
 
                old_ie = p_inv[file_id]
347
 
                if (old_ie.parent_id != ie.parent_id
348
 
                    or old_ie.name != ie.name
349
 
                    or old_ie.text_sha1 != ie.text_sha1
350
 
                    or old_ie.text_size != ie.text_size):
351
 
                    ie.revision = rev.revision_id
352
 
                    break
353
 
                if matched_id is None:
354
 
                    matched_id = old_ie.revision
355
 
                elif matched_id != old_ie.revision:
356
 
                    ie.revision = rev.revision_id
357
 
                    break
358
 
            else:
359
 
                assert matched_id is not None
360
 
                ie.revision = matched_id
361
 
 
362
328
    def _convert_file_version(self, rev, ie, parent_invs):
363
329
        """Convert one version of one file.
364
330
 
365
331
        The file needs to be added into the weave if it is a merge
366
332
        of >=2 parents or if it's changed from its parent.
367
333
        """
 
334
        if ie.kind == 'root_directory':
 
335
            return
368
336
        file_id = ie.file_id
369
337
        rev_id = rev.revision_id
370
338
        w = self.text_weaves.get(file_id)
371
339
        if w is None:
372
340
            w = Weave(file_id)
373
341
            self.text_weaves[file_id] = w
374
 
        file_parents = []
375
342
        text_changed = False
376
 
        for parent_inv in parent_invs:
377
 
            if parent_inv.has_id(file_id):
378
 
                parent_ie = parent_inv[file_id]
379
 
                old_revision = parent_ie.revision
 
343
        previous_entries = ie.find_previous_heads(parent_invs, w)
 
344
        for old_revision in previous_entries:
380
345
                # if this fails, its a ghost ?
381
346
                assert old_revision in self.converted_revs 
382
 
                if old_revision not in file_parents:
383
 
                    file_parents.append(old_revision)
384
 
                if parent_ie.text_sha1 != ie.text_sha1:
385
 
                    text_changed = True
386
 
        if len(file_parents) != 1 or text_changed:
 
347
        self.snapshot_ie(previous_entries, ie, w, rev_id)
 
348
        del ie.text_id
 
349
        assert getattr(ie, 'revision', None) is not None
 
350
 
 
351
    def snapshot_ie(self, previous_revisions, ie, w, rev_id):
 
352
        # TODO: convert this logic, which is ~= snapshot to
 
353
        # a call to:. This needs the path figured out. rather than a work_tree
 
354
        # a v4 revision_tree can be given, or something that looks enough like
 
355
        # one to give the file content to the entry if it needs it.
 
356
        # and we need something that looks like a weave store for snapshot to 
 
357
        # save against.
 
358
        #ie.snapshot(rev, PATH, previous_revisions, REVISION_TREE, InMemoryWeaveStore(self.text_weaves))
 
359
        if len(previous_revisions) == 1:
 
360
            previous_ie = previous_revisions.values()[0]
 
361
            if ie._unchanged(previous_ie):
 
362
                ie.revision = previous_ie.revision
 
363
                return
 
364
        parent_indexes = map(w.lookup, previous_revisions)
 
365
        if ie.has_text():
387
366
            file_lines = self.branch.text_store[ie.text_id].readlines()
388
367
            assert sha_strings(file_lines) == ie.text_sha1
389
368
            assert sum(map(len, file_lines)) == ie.text_size
390
 
            w.add(rev_id, file_parents, file_lines, ie.text_sha1)
391
 
            ie.revision = rev_id
 
369
            w.add(rev_id, parent_indexes, file_lines, ie.text_sha1)
392
370
            self.text_count += 1
393
 
            ##mutter('import text {%s} of {%s}',
394
 
            ##       ie.text_id, file_id)
395
371
        else:
396
 
            ##mutter('text of {%s} unchanged from parent', file_id)
397
 
            ie.revision = file_parents[0]
398
 
        del ie.text_id
399
 
 
400
 
 
 
372
            w.add(rev_id, parent_indexes, [], None)
 
373
        ie.revision = rev_id
 
374
        ##mutter('import text {%s} of {%s}',
 
375
        ##       ie.text_id, file_id)
401
376
 
402
377
    def _make_order(self):
403
378
        """Return a suitable order for importing revisions.