/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/annotate.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-12-17 19:55:27 UTC
  • mfrom: (1551.9.21 Aaron's mergeable stuff)
  • Revision ID: pqm@pqm.ubuntu.com-20061217195527-29196a8633600671
Add Tree.annotate_iter

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
from bzrlib import (
32
32
    errors,
 
33
    patiencediff,
33
34
    tsort,
34
35
    )
35
36
from bzrlib.config import extract_email_address
131
132
            except errors.NoEmailInUsername:
132
133
                pass        # use the whole name
133
134
        yield (revno_str, author, date_str, origin, text)
 
135
 
 
136
 
 
137
def reannotate(parents_lines, new_lines, new_revision_id):
 
138
    """Create a new annotated version from new lines and parent annotations.
 
139
    
 
140
    :param parents_lines: List of annotated lines for all parents
 
141
    :param new_lines: The un-annotated new lines
 
142
    :param new_revision_id: The revision-id to associate with new lines
 
143
        (will often be CURRENT_REVISION)
 
144
    """
 
145
    if len(parents_lines) == 1:
 
146
        for data in _reannotate(parents_lines[0], new_lines, new_revision_id):
 
147
            yield data
 
148
    else:
 
149
        reannotations = [list(_reannotate(p, new_lines, new_revision_id)) for
 
150
                         p in parents_lines]
 
151
        for annos in zip(*reannotations):
 
152
            origins = set(a for a, l in annos)
 
153
            line = annos[0][1]
 
154
            if len(origins) == 1:
 
155
                yield iter(origins).next(), line
 
156
            elif len(origins) == 2 and new_revision_id in origins:
 
157
                yield (x for x in origins if x != new_revision_id).next(), line
 
158
            else:
 
159
                yield new_revision_id, line
 
160
 
 
161
 
 
162
def _reannotate(parent_lines, new_lines, new_revision_id):
 
163
    plain_parent_lines = [l for r, l in parent_lines]
 
164
    matcher = patiencediff.PatienceSequenceMatcher(None, plain_parent_lines,
 
165
                                                   new_lines)
 
166
    new_cur = 0
 
167
    for i, j, n in matcher.get_matching_blocks():
 
168
        for line in new_lines[new_cur:j]:
 
169
            yield new_revision_id, line
 
170
        for data in parent_lines[i:i+n]:
 
171
            yield data
 
172
        new_cur = j + n