~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-05-29 23:15:16 UTC
  • mfrom: (1711.2.25 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060529231516-cad98b5042ea75f3
(jam) Updates to PatienceDiff for performance, and other cleanups.

Show diffs side-by-side

added added

removed removed

Lines of Context:
120
120
        """Generate line-based delta from this content to new_lines."""
121
121
        new_texts = [text for origin, text in new_lines._lines]
122
122
        old_texts = [text for origin, text in self._lines]
123
 
        s = SequenceMatcher(None, old_texts, new_texts)
 
123
        s = KnitSequenceMatcher(None, old_texts, new_texts)
124
124
        for op in s.get_opcodes():
125
125
            if op[0] == 'equal':
126
126
                continue
427
427
            else:
428
428
                old_texts = []
429
429
            new_texts = new_content.text()
430
 
            delta_seq = SequenceMatcher(None, old_texts, new_texts)
 
430
            delta_seq = KnitSequenceMatcher(None, old_texts, new_texts)
431
431
            return parent, sha1, noeol, self._make_line_delta(delta_seq, new_content)
432
432
        else:
433
433
            delta = self.factory.parse_line_delta(data, version_idx)
481
481
            delta_seq = None
482
482
            for parent_id in parents:
483
483
                merge_content = self._get_content(parent_id, parent_texts)
484
 
                seq = SequenceMatcher(None, merge_content.text(), content.text())
 
484
                seq = KnitSequenceMatcher(None, merge_content.text(), content.text())
485
485
                if delta_seq is None:
486
486
                    # setup a delta seq to reuse.
487
487
                    delta_seq = seq
498
498
                reference_content = self._get_content(parents[0], parent_texts)
499
499
                new_texts = content.text()
500
500
                old_texts = reference_content.text()
501
 
                delta_seq = SequenceMatcher(None, old_texts, new_texts)
 
501
                delta_seq = KnitSequenceMatcher(None, old_texts, new_texts)
502
502
            return self._make_line_delta(delta_seq, content)
503
503
 
504
504
    def _make_line_delta(self, delta_seq, new_content):
861
861
        annotated_b = self.annotate(ver_b)
862
862
        plain_a = [t for (a, t) in annotated_a]
863
863
        plain_b = [t for (a, t) in annotated_b]
864
 
        blocks = SequenceMatcher(None, plain_a, plain_b).get_matching_blocks()
 
864
        blocks = KnitSequenceMatcher(None, plain_a, plain_b).get_matching_blocks()
865
865
        a_cur = 0
866
866
        b_cur = 0
867
867
        for ai, bi, l in blocks:
1603
1603
InterVersionedFile.register_optimiser(WeaveToKnit)
1604
1604
 
1605
1605
 
1606
 
class SequenceMatcher(difflib.SequenceMatcher):
 
1606
class KnitSequenceMatcher(difflib.SequenceMatcher):
1607
1607
    """Knit tuned sequence matcher.
1608
1608
 
1609
1609
    This is based on profiling of difflib which indicated some improvements