~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: John Arbash Meinel
  • Date: 2006-11-28 15:11:37 UTC
  • mto: This revision was merged to the branch mainline in revision 2152.
  • Revision ID: john@arbash-meinel.com-20061128151137-1f1z1a0qgdg3yas1
(Dmitry Vasiliev) Tune KnitContent and add tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
118
118
 
119
119
    def annotate_iter(self):
120
120
        """Yield tuples of (origin, text) for each content line."""
121
 
        for origin, text in self._lines:
122
 
            yield origin, text
 
121
        return iter(self._lines)
123
122
 
124
123
    def annotate(self):
125
124
        """Return a list of (origin, text) tuples."""
127
126
 
128
127
    def line_delta_iter(self, new_lines):
129
128
        """Generate line-based delta from this content to new_lines."""
130
 
        new_texts = [text for origin, text in new_lines._lines]
131
 
        old_texts = [text for origin, text in self._lines]
 
129
        new_texts = new_lines.text()
 
130
        old_texts = self.text()
132
131
        s = KnitSequenceMatcher(None, old_texts, new_texts)
133
 
        for op in s.get_opcodes():
134
 
            if op[0] == 'equal':
 
132
        for tag, i1, i2, j1, j2 in s.get_opcodes():
 
133
            if tag == 'equal':
135
134
                continue
136
 
            #     ofrom   oto   length        data
137
 
            yield (op[1], op[2], op[4]-op[3], new_lines._lines[op[3]:op[4]])
 
135
            # ofrom, oto, length, data
 
136
            yield i1, i2, j2 - j1, new_lines._lines[j1:j2]
138
137
 
139
138
    def line_delta(self, new_lines):
140
139
        return list(self.line_delta_iter(new_lines))