/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: Jelmer Vernooij
  • Date: 2018-11-18 18:23:32 UTC
  • mto: This revision was merged to the branch mainline in revision 7197.
  • Revision ID: jelmer@jelmer.uk-20181118182332-viz1qvqese2mo9i6
Fix some more Bazaar references.

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():
89
 
                if parent_keys is None: # No graph versionedfile
 
96
            for key, parent_keys in viewitems(next_parent_map):
 
97
                if parent_keys is None:  # No graph versionedfile
90
98
                    parent_keys = ()
91
99
                    next_parent_map[key] = ()
92
100
                self._update_needed_children(key, parent_keys)
93
101
                needed_keys.update([key for key in parent_keys
94
 
                                         if key not in parent_map])
 
102
                                    if key not in parent_map])
95
103
            parent_map.update(next_parent_map)
96
 
            # _heads_provider does some graph caching, so it is only valid while
97
 
            # self._parent_map hasn't changed
 
104
            # _heads_provider does some graph caching, so it is only valid
 
105
            # while self._parent_map hasn't changed
98
106
            self._heads_provider = None
99
107
        return vf_keys_needed, ann_keys_needed
100
108
 
110
118
        keys, ann_keys = self._get_needed_keys(key)
111
119
        if pb is not None:
112
120
            pb.update('getting stream', 0, len(keys))
113
 
        stream  = self._vf.get_record_stream(keys, 'topological', True)
 
121
        stream = self._vf.get_record_stream(keys, 'topological', True)
114
122
        for idx, record in enumerate(stream):
115
123
            if pb is not None:
116
124
                pb.update('extracting', 0, len(keys))
140
148
        parent_lines = self._text_cache[parent_key]
141
149
        parent_annotations = self._annotations_cache[parent_key]
142
150
        # PatienceSequenceMatcher should probably be part of Policy
143
 
        matcher = patiencediff.PatienceSequenceMatcher(None,
144
 
            parent_lines, text)
 
151
        matcher = patiencediff.PatienceSequenceMatcher(
 
152
            None, parent_lines, text)
145
153
        matching_blocks = matcher.get_matching_blocks()
146
154
        return parent_annotations, matching_blocks
147
155
 
149
157
        """Reannotate this text relative to its first parent."""
150
158
        (parent_annotations,
151
159
         matching_blocks) = self._get_parent_annotations_and_matches(
152
 
                                key, lines, parent_key)
 
160
             key, lines, parent_key)
153
161
 
154
162
        for parent_idx, lines_idx, match_len in matching_blocks:
155
163
            # For all matching regions we copy across the parent annotations
161
169
        """Reannotate this text relative to a second (or more) parent."""
162
170
        (parent_annotations,
163
171
         matching_blocks) = self._get_parent_annotations_and_matches(
164
 
                                key, lines, parent_key)
 
172
             key, lines, parent_key)
165
173
 
166
174
        last_ann = None
167
175
        last_parent = None
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:
258
 
            for text_key, text, num_lines in self._get_needed_texts(key, pb=pb):
 
264
        with ui.ui_factory.nested_progress_bar() as pb:
 
265
            for text_key, text, num_lines in self._get_needed_texts(
 
266
                    key, pb=pb):
259
267
                self._annotate_one(text_key, text, num_lines)
260
 
        finally:
261
 
            pb.finished()
262
268
        try:
263
269
            annotations = self._annotations_cache[key]
264
270
        except KeyError:
277
283
            # Backwards compatibility, break up the heads into pairs and
278
284
            # resolve the result
279
285
            next_head = iter(the_heads)
280
 
            head = next_head.next()
 
286
            head = next(next_head)
281
287
            for possible_head in next_head:
282
288
                annotated_lines = ((head, line), (possible_head, line))
283
289
                head = tiebreaker(annotated_lines)[0]
301
307
            else:
302
308
                the_heads = heads(annotation)
303
309
                if len(the_heads) == 1:
304
 
                    for head in the_heads: break # get the item out of the set
 
310
                    for head in the_heads:
 
311
                        break  # get the item out of the set
305
312
                else:
306
313
                    head = self._resolve_annotation_tie(the_heads, line,
307
314
                                                        custom_tiebreaker)