~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

Teach Knit repositories how to handle ghosts without corrupting at all.

Show diffs side-by-side

added added

removed removed

Lines of Context:
456
456
 
457
457
        Any versions not present will be converted into ghosts.
458
458
        """
 
459
        ghostless_parents = []
459
460
        ghosts = []
460
461
        for parent in parents:
461
462
            if not self.has_version(parent):
462
463
                ghosts.append(parent)
 
464
            else:
 
465
                ghostless_parents.append(parent)
463
466
 
464
 
        if delta and not len(parents)-len(ghosts):
 
467
        if delta and not len(ghostless_parents):
465
468
            delta = False
466
469
 
467
470
        digest = sha_strings(lines)
472
475
                lines[-1] = lines[-1] + '\n'
473
476
 
474
477
        lines = self.factory.make(lines, len(self._index))
475
 
        if self.factory.annotated and len(parents)-len(ghosts) > 0:
 
478
        if self.factory.annotated and len(ghostless_parents) > 0:
476
479
            # Merge annotations from parent texts if so is needed.
477
 
            self._merge_annotations(lines, parents)
 
480
            self._merge_annotations(lines, ghostless_parents)
478
481
 
479
 
        if len(parents)-len(ghosts) and delta:
 
482
        if len(ghostless_parents) and delta:
480
483
            # To speed the extract of texts the delta chain is limited
481
484
            # to a fixed number of deltas.  This should minimize both
482
485
            # I/O and the time spend applying deltas.
483
486
            count = 0
484
 
            delta_parents = [parent for parent in parents if not parent in ghosts]
485
 
            first_parent = delta_parents[0]
 
487
            delta_parents = ghostless_parents
486
488
            while count < 25:
487
489
                parent = delta_parents[0]
488
490
                method = self._index.get_method(parent)
495
497
 
496
498
        if delta:
497
499
            options.append('line-delta')
498
 
            content = self._get_content(first_parent)
 
500
            content = self._get_content(ghostless_parents[0])
499
501
            delta_hunks = content.line_delta(lines)
500
502
            store_lines = self.factory.lower_line_delta(delta_hunks)
501
503
        else:
733
735
            if value.startswith('.'):
734
736
                result.append(value[1:])
735
737
            else:
 
738
                assert isinstance(value, str)
736
739
                result.append(self._history[int(value)])
737
740
        return result
738
741
 
749
752
        pending = set(versions)
750
753
        while len(pending):
751
754
            version = pending.pop()
752
 
#            try:
753
755
            parents = self._cache[version][4]
754
 
#            except KeyError:
755
 
#                # ghost, elide it.
756
 
#                pass
757
 
#            else:
758
756
            # got the parents ok
759
757
            # trim ghosts
760
758
            parents = [parent for parent in parents if parent in self._cache]
807
805
            if version in self._cache:
808
806
                result_list.append(str(self._history.index(version)))
809
807
            else:
810
 
                result_list.append('.' + version)
 
808
                result_list.append('.' + version.encode('utf-8'))
811
809
        return ' '.join(result_list)
812
810
 
813
811
    def add_version(self, version_id, options, pos, size, parents):