/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: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

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 __future__ import absolute_import
20
 
 
21
19
from .lazy_import import lazy_import
22
20
lazy_import(globals(), """
 
21
 
 
22
import patiencediff
 
23
 
23
24
from breezy import (
24
25
    annotate, # Must be lazy to avoid circular importing
25
26
    graph as _mod_graph,
26
 
    patiencediff,
27
27
    )
28
28
""")
29
29
from . import (
31
31
    osutils,
32
32
    ui,
33
33
    )
34
 
from .sixish import (
35
 
    range,
36
 
    viewitems,
37
 
    )
38
34
 
39
35
 
40
36
class Annotator(object):
93
89
                    vf_keys_needed.add(key)
94
90
            needed_keys = set()
95
91
            next_parent_map.update(self._vf.get_parent_map(parent_lookup))
96
 
            for key, parent_keys in viewitems(next_parent_map):
97
 
                if parent_keys is None: # No graph versionedfile
 
92
            for key, parent_keys in next_parent_map.items():
 
93
                if parent_keys is None:  # No graph versionedfile
98
94
                    parent_keys = ()
99
95
                    next_parent_map[key] = ()
100
96
                self._update_needed_children(key, parent_keys)
101
97
                needed_keys.update([key for key in parent_keys
102
 
                                         if key not in parent_map])
 
98
                                    if key not in parent_map])
103
99
            parent_map.update(next_parent_map)
104
 
            # _heads_provider does some graph caching, so it is only valid while
105
 
            # self._parent_map hasn't changed
 
100
            # _heads_provider does some graph caching, so it is only valid
 
101
            # while self._parent_map hasn't changed
106
102
            self._heads_provider = None
107
103
        return vf_keys_needed, ann_keys_needed
108
104
 
118
114
        keys, ann_keys = self._get_needed_keys(key)
119
115
        if pb is not None:
120
116
            pb.update('getting stream', 0, len(keys))
121
 
        stream  = self._vf.get_record_stream(keys, 'topological', True)
 
117
        stream = self._vf.get_record_stream(keys, 'topological', True)
122
118
        for idx, record in enumerate(stream):
123
119
            if pb is not None:
124
120
                pb.update('extracting', 0, len(keys))
125
121
            if record.storage_kind == 'absent':
126
122
                raise errors.RevisionNotPresent(record.key, self._vf)
127
123
            this_key = record.key
128
 
            lines = osutils.chunks_to_lines(record.get_bytes_as('chunked'))
 
124
            lines = record.get_bytes_as('lines')
129
125
            num_lines = len(lines)
130
126
            self._text_cache[this_key] = lines
131
127
            yield this_key, lines, num_lines
148
144
        parent_lines = self._text_cache[parent_key]
149
145
        parent_annotations = self._annotations_cache[parent_key]
150
146
        # PatienceSequenceMatcher should probably be part of Policy
151
 
        matcher = patiencediff.PatienceSequenceMatcher(None,
152
 
            parent_lines, text)
 
147
        matcher = patiencediff.PatienceSequenceMatcher(
 
148
            None, parent_lines, text)
153
149
        matching_blocks = matcher.get_matching_blocks()
154
150
        return parent_annotations, matching_blocks
155
151
 
157
153
        """Reannotate this text relative to its first parent."""
158
154
        (parent_annotations,
159
155
         matching_blocks) = self._get_parent_annotations_and_matches(
160
 
                                key, lines, parent_key)
 
156
             key, lines, parent_key)
161
157
 
162
158
        for parent_idx, lines_idx, match_len in matching_blocks:
163
159
            # For all matching regions we copy across the parent annotations
169
165
        """Reannotate this text relative to a second (or more) parent."""
170
166
        (parent_annotations,
171
167
         matching_blocks) = self._get_parent_annotations_and_matches(
172
 
                                key, lines, parent_key)
 
168
             key, lines, parent_key)
173
169
 
174
170
        last_ann = None
175
171
        last_parent = None
261
257
                        each key is a possible source for the given line.
262
258
            lines the text of "key" as a list of lines
263
259
        """
264
 
        pb = ui.ui_factory.nested_progress_bar()
265
 
        try:
266
 
            for text_key, text, num_lines in self._get_needed_texts(key, pb=pb):
 
260
        with ui.ui_factory.nested_progress_bar() as pb:
 
261
            for text_key, text, num_lines in self._get_needed_texts(
 
262
                    key, pb=pb):
267
263
                self._annotate_one(text_key, text, num_lines)
268
 
        finally:
269
 
            pb.finished()
270
264
        try:
271
265
            annotations = self._annotations_cache[key]
272
266
        except KeyError:
309
303
            else:
310
304
                the_heads = heads(annotation)
311
305
                if len(the_heads) == 1:
312
 
                    for head in the_heads: break # get the item out of the set
 
306
                    for head in the_heads:
 
307
                        break  # get the item out of the set
313
308
                else:
314
309
                    head = self._resolve_annotation_tie(the_heads, line,
315
310
                                                        custom_tiebreaker)