/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 breezy/_annotator_py.py

  • Committer: Martin
  • Date: 2018-11-16 16:38:22 UTC
  • mto: This revision was merged to the branch mainline in revision 7172.
  • Revision ID: gzlist@googlemail.com-20181116163822-yg1h1cdng6w7w9kn
Make --profile-imports work on Python 3

Also tweak heading to line up correctly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009 Canonical Ltd
 
1
# Copyright (C) 2009, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
16
16
 
17
17
"""Functionality for doing annotations in the 'optimal' way"""
18
18
 
19
 
from bzrlib.lazy_import import lazy_import
 
19
from __future__ import absolute_import
 
20
 
 
21
from .lazy_import import lazy_import
20
22
lazy_import(globals(), """
21
 
from bzrlib import annotate # Must be lazy to avoid circular importing
 
23
from breezy import (
 
24
    annotate, # Must be lazy to avoid circular importing
 
25
    graph as _mod_graph,
 
26
    patiencediff,
 
27
    )
22
28
""")
23
 
from bzrlib import (
 
29
from . import (
24
30
    errors,
25
 
    graph as _mod_graph,
26
31
    osutils,
27
 
    patiencediff,
28
32
    ui,
29
33
    )
 
34
from .sixish import (
 
35
    range,
 
36
    viewitems,
 
37
    )
30
38
 
31
39
 
32
40
class Annotator(object):
66
74
        self._num_needed_children[key] = 1
67
75
        vf_keys_needed = set()
68
76
        ann_keys_needed = set()
69
 
        needed_keys = set([key])
 
77
        needed_keys = {key}
70
78
        while needed_keys:
71
79
            parent_lookup = []
72
80
            next_parent_map = {}
85
93
                    vf_keys_needed.add(key)
86
94
            needed_keys = set()
87
95
            next_parent_map.update(self._vf.get_parent_map(parent_lookup))
88
 
            for key, parent_keys in next_parent_map.iteritems():
 
96
            for key, parent_keys in viewitems(next_parent_map):
89
97
                if parent_keys is None: # No graph versionedfile
90
98
                    parent_keys = ()
91
99
                    next_parent_map[key] = ()
179
187
            par_sub = parent_annotations[parent_idx:parent_idx + match_len]
180
188
            if ann_sub == par_sub:
181
189
                continue
182
 
            for idx in xrange(match_len):
 
190
            for idx in range(match_len):
183
191
                ann = ann_sub[idx]
184
192
                par_ann = par_sub[idx]
185
193
                ann_idx = lines_idx + idx
253
261
                        each key is a possible source for the given line.
254
262
            lines the text of "key" as a list of lines
255
263
        """
256
 
        pb = ui.ui_factory.nested_progress_bar()
257
 
        try:
 
264
        with ui.ui_factory.nested_progress_bar() as pb:
258
265
            for text_key, text, num_lines in self._get_needed_texts(key, pb=pb):
259
266
                self._annotate_one(text_key, text, num_lines)
260
 
        finally:
261
 
            pb.finished()
262
267
        try:
263
268
            annotations = self._annotations_cache[key]
264
269
        except KeyError:
277
282
            # Backwards compatibility, break up the heads into pairs and
278
283
            # resolve the result
279
284
            next_head = iter(the_heads)
280
 
            head = next_head.next()
 
285
            head = next(next_head)
281
286
            for possible_head in next_head:
282
287
                annotated_lines = ((head, line), (possible_head, line))
283
288
                head = tiebreaker(annotated_lines)[0]