~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: Aaron Bentley
  • Date: 2007-06-19 13:17:05 UTC
  • mto: (2520.5.2 bzr.mpbundle)
  • mto: This revision was merged to the branch mainline in revision 2631.
  • Revision ID: abentley@panoramicfeedback.com-20070619131705-tkigpvx0xhpefs9t
Support getting blocks from knit deltas with no final EOL

Show diffs side-by-side

added added

removed removed

Lines of Context:
154
154
        return KnitContent(self._lines[:])
155
155
 
156
156
    @staticmethod
157
 
    def get_line_delta_blocks(knit_delta, source_lines, target_lines):
 
157
    def get_line_delta_blocks(knit_delta, source, target):
158
158
        """Extract SequenceMatcher.get_matching_blocks() from a knit delta"""
159
 
        target_len = len(target_lines)
 
159
        target_len = len(target)
160
160
        s_pos = 0
161
161
        t_pos = 0
162
162
        for s_begin, s_end, t_len, new_text in knit_delta:
163
163
            true_n = s_begin - s_pos
164
164
            n = true_n
165
165
            if n > 0:
166
 
                if source_lines[s_pos + n -1] != target_lines[t_pos + n -1]:
 
166
                # knit deltas do not provide reliable info about whether the
 
167
                # last line of a file matches, due to eol handling.
 
168
                if source[s_pos + n -1] != target[t_pos + n -1]:
167
169
                    n-=1
168
170
                if n > 0:
169
171
                    yield s_pos, t_pos, n
170
172
            t_pos += t_len + true_n
171
173
            s_pos = s_end
172
 
        if t_pos < target_len:
173
 
            yield s_pos, t_pos, target_len - t_pos
 
174
        n = target_len - t_pos
 
175
        if n > 0:
 
176
            if source[s_pos + n -1] != target[t_pos + n -1]:
 
177
                n-=1
 
178
            if n > 0:
 
179
                yield s_pos, t_pos, n
174
180
        yield s_pos + (target_len - t_pos), target_len, 0
175
181
 
176
182