~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_annotator_py.py

  • Committer: John Arbash Meinel
  • Date: 2009-07-08 17:09:03 UTC
  • mto: This revision was merged to the branch mainline in revision 4522.
  • Revision ID: john@arbash-meinel.com-20090708170903-nea7ru9bh2hdtf1w
Add support for compatibility with old '_break_annotation_tie' function.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Functionality for doing annotations in the 'optimal' way"""
18
18
 
 
19
from bzrlib.lazy_import import lazy_import
 
20
lazy_import(globals(), """
 
21
from bzrlib import annotate # Must be lazy to avoid circular importing
 
22
""")
19
23
from bzrlib import (
20
24
    errors,
21
25
    graph as _mod_graph,
266
270
            self._heads_provider = _mod_graph.KnownGraph(self._parent_map)
267
271
        return self._heads_provider
268
272
 
 
273
    def _resolve_annotation_tie(self, the_heads, line, tiebreaker):
 
274
        if tiebreaker is None:
 
275
            head = sorted(the_heads)[0]
 
276
        else:
 
277
            # Backwards compatibility, break up the heads into pairs and
 
278
            # resolve the result
 
279
            next_head = iter(the_heads)
 
280
            head = next_head.next()
 
281
            for possible_head in next_head:
 
282
                annotated_lines = ((head, line), (possible_head, line))
 
283
                head = tiebreaker(annotated_lines)[0]
 
284
        return head
 
285
 
269
286
    def annotate_flat(self, key):
270
287
        """Determine the single-best-revision to source for each line.
271
288
 
273
290
        :return: [(ann_key, line)]
274
291
            A list of tuples with a single annotation key for each line.
275
292
        """
 
293
        custom_tiebreaker = annotate._break_annotation_tie
276
294
        annotations, lines = self.annotate(key)
277
295
        assert len(annotations) == len(lines)
278
296
        out = []
280
298
        append = out.append
281
299
        for annotation, line in zip(annotations, lines):
282
300
            if len(annotation) == 1:
283
 
                append((annotation[0], line))
 
301
                head = annotation[0]
284
302
            else:
285
303
                the_heads = heads(annotation)
286
304
                if len(the_heads) == 1:
287
305
                    for head in the_heads: break # get the item out of the set
288
306
                else:
289
 
                    # We need to resolve the ambiguity, for now just pick the
290
 
                    # sorted smallest
291
 
                    head = sorted(the_heads)[0]
292
 
                append((head, line))
 
307
                    head = self._resolve_annotation_tie(the_heads, line,
 
308
                                                        custom_tiebreaker)
 
309
            append((head, line))
293
310
        return out