~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/annotate.py

  • Committer: Aaron Bentley
  • Date: 2007-08-31 19:38:52 UTC
  • mto: This revision was merged to the branch mainline in revision 2777.
  • Revision ID: abentley@panoramicfeedback.com-20070831193852-6ip22sbw058yib5u
Clean up docs, test matching blocks for reannotate

Show diffs side-by-side

added added

removed removed

Lines of Context:
137
137
        yield (revno_str, author, date_str, origin, text)
138
138
 
139
139
 
140
 
def reannotate(parents_lines, new_lines, new_revision_id, blocks=None):
 
140
def reannotate(parents_lines, new_lines, new_revision_id,
 
141
               _left_matching_blocks=None):
141
142
    """Create a new annotated version from new lines and parent annotations.
142
143
    
143
144
    :param parents_lines: List of annotated lines for all parents
144
145
    :param new_lines: The un-annotated new lines
145
146
    :param new_revision_id: The revision-id to associate with new lines
146
147
        (will often be CURRENT_REVISION)
 
148
    :param left_matching_blocks: a hint about which areas are common
 
149
        between the text and its left-hand-parent.  The format is
 
150
        the SequenceMatcher.get_matching_blocks format.
147
151
    """
148
152
    if len(parents_lines) == 0:
149
153
        for line in new_lines:
150
154
            yield new_revision_id, line
151
155
    elif len(parents_lines) == 1:
152
156
        for data in _reannotate(parents_lines[0], new_lines, new_revision_id,
153
 
                                blocks):
 
157
                                _left_matching_blocks):
154
158
            yield data
155
159
    else:
156
 
        block_list = [blocks] + [None] * len(parents_lines)
 
160
        block_list = [_left_matching_blocks] + [None] * len(parents_lines)
157
161
        reannotations = [list(_reannotate(p, new_lines, new_revision_id, b))
158
162
                         for p, b in zip(parents_lines, block_list)]
159
163
        for annos in zip(*reannotations):
167
171
                yield new_revision_id, line
168
172
 
169
173
 
170
 
def _reannotate(parent_lines, new_lines, new_revision_id, blocks=None):
 
174
def _reannotate(parent_lines, new_lines, new_revision_id,
 
175
                matching_blocks=None):
171
176
    plain_parent_lines = [l for r, l in parent_lines]
172
177
    matcher = patiencediff.PatienceSequenceMatcher(None, plain_parent_lines,
173
178
                                                   new_lines)
174
179
    new_cur = 0
175
 
    if blocks is None:
176
 
        blocks = matcher.get_matching_blocks()
177
 
    for i, j, n in blocks:
 
180
    if matching_blocks is None:
 
181
        matching_blocks = matcher.get_matching_blocks()
 
182
    for i, j, n in matching_blocks:
178
183
        for line in new_lines[new_cur:j]:
179
184
            yield new_revision_id, line
180
185
        for data in parent_lines[i:i+n]: