~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: Aaron Bentley
  • Date: 2007-07-24 11:44:40 UTC
  • mto: This revision was merged to the branch mainline in revision 2699.
  • Revision ID: aaron.bentley@utoronto.ca-20070724114440-c0cc1qqequkw6qru
Use matching blocks from mpdiff for knit delta creation

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
import bzrlib
73
73
from bzrlib import (
74
74
    cache_utf8,
 
75
    diff,
75
76
    errors,
76
77
    osutils,
77
78
    patiencediff,
628
629
    __contains__ = has_version
629
630
 
630
631
    def _merge_annotations(self, content, parents, parent_texts={},
631
 
                           delta=None, annotated=None):
 
632
                           delta=None, annotated=None,
 
633
                           left_matching_blocks=None):
632
634
        """Merge annotations for content.  This is done by comparing
633
635
        the annotations based on changed to the text.
634
636
        """
636
638
            delta_seq = None
637
639
            for parent_id in parents:
638
640
                merge_content = self._get_content(parent_id, parent_texts)
639
 
                seq = patiencediff.PatienceSequenceMatcher(
640
 
                                   None, merge_content.text(), content.text())
 
641
                if (parent_id == parents[0] and
 
642
                    left_matching_blocks is not None):
 
643
                    seq = diff._PrematchedMatcher(left_matching_blocks)
 
644
                else:
 
645
                    seq = patiencediff.PatienceSequenceMatcher(
 
646
                        None, merge_content.text(), content.text())
641
647
                if delta_seq is None:
642
648
                    # setup a delta seq to reuse.
643
649
                    delta_seq = seq
716
722
        self._check_add(version_id, lines)
717
723
        return self._add(version_id, lines[:], parents, self.delta, parent_texts)
718
724
 
719
 
    def _add_lines(self, version_id, parents, lines, parent_texts):
 
725
    def _add_lines(self, version_id, parents, lines, parent_texts,
 
726
                   left_matching_blocks=None):
720
727
        """See VersionedFile.add_lines."""
721
728
        self._check_add(version_id, lines)
722
729
        self._check_versions_present(parents)
723
 
        return self._add(version_id, lines[:], parents, self.delta, parent_texts)
 
730
        return self._add(version_id, lines[:], parents, self.delta,
 
731
                         parent_texts, left_matching_blocks)
724
732
 
725
733
    def _check_add(self, version_id, lines):
726
734
        """check that version_id and lines are safe to add."""
734
742
        self._check_lines_not_unicode(lines)
735
743
        self._check_lines_are_lines(lines)
736
744
 
737
 
    def _add(self, version_id, lines, parents, delta, parent_texts):
 
745
    def _add(self, version_id, lines, parents, delta, parent_texts,
 
746
             left_matching_blocks=None):
738
747
        """Add a set of lines on top of version specified by parents.
739
748
 
740
749
        If delta is true, compress the text as a line-delta against
784
793
        lines = self.factory.make(lines, version_id)
785
794
        if delta or (self.factory.annotated and len(present_parents) > 0):
786
795
            # Merge annotations from parent texts if so is needed.
787
 
            delta_hunks = self._merge_annotations(lines, present_parents, parent_texts,
788
 
                                                  delta, self.factory.annotated)
 
796
            delta_hunks = self._merge_annotations(lines, present_parents,
 
797
                parent_texts, delta, self.factory.annotated,
 
798
                left_matching_blocks)
789
799
 
790
800
        if delta:
791
801
            options.append('line-delta')