/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: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

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
 
from bzrlib.lazy_import import lazy_import
 
19
from .lazy_import import lazy_import
22
20
lazy_import(globals(), """
23
 
from bzrlib import (
 
21
 
 
22
import patiencediff
 
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
 
from bzrlib import (
 
29
from . import (
30
30
    errors,
31
31
    osutils,
32
32
    ui,
70
70
        self._num_needed_children[key] = 1
71
71
        vf_keys_needed = set()
72
72
        ann_keys_needed = set()
73
 
        needed_keys = set([key])
 
73
        needed_keys = {key}
74
74
        while needed_keys:
75
75
            parent_lookup = []
76
76
            next_parent_map = {}
89
89
                    vf_keys_needed.add(key)
90
90
            needed_keys = set()
91
91
            next_parent_map.update(self._vf.get_parent_map(parent_lookup))
92
 
            for key, parent_keys in next_parent_map.iteritems():
93
 
                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
94
94
                    parent_keys = ()
95
95
                    next_parent_map[key] = ()
96
96
                self._update_needed_children(key, parent_keys)
97
97
                needed_keys.update([key for key in parent_keys
98
 
                                         if key not in parent_map])
 
98
                                    if key not in parent_map])
99
99
            parent_map.update(next_parent_map)
100
 
            # _heads_provider does some graph caching, so it is only valid while
101
 
            # 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
102
102
            self._heads_provider = None
103
103
        return vf_keys_needed, ann_keys_needed
104
104
 
114
114
        keys, ann_keys = self._get_needed_keys(key)
115
115
        if pb is not None:
116
116
            pb.update('getting stream', 0, len(keys))
117
 
        stream  = self._vf.get_record_stream(keys, 'topological', True)
 
117
        stream = self._vf.get_record_stream(keys, 'topological', True)
118
118
        for idx, record in enumerate(stream):
119
119
            if pb is not None:
120
120
                pb.update('extracting', 0, len(keys))
121
121
            if record.storage_kind == 'absent':
122
122
                raise errors.RevisionNotPresent(record.key, self._vf)
123
123
            this_key = record.key
124
 
            lines = osutils.chunks_to_lines(record.get_bytes_as('chunked'))
 
124
            lines = record.get_bytes_as('lines')
125
125
            num_lines = len(lines)
126
126
            self._text_cache[this_key] = lines
127
127
            yield this_key, lines, num_lines
144
144
        parent_lines = self._text_cache[parent_key]
145
145
        parent_annotations = self._annotations_cache[parent_key]
146
146
        # PatienceSequenceMatcher should probably be part of Policy
147
 
        matcher = patiencediff.PatienceSequenceMatcher(None,
148
 
            parent_lines, text)
 
147
        matcher = patiencediff.PatienceSequenceMatcher(
 
148
            None, parent_lines, text)
149
149
        matching_blocks = matcher.get_matching_blocks()
150
150
        return parent_annotations, matching_blocks
151
151
 
153
153
        """Reannotate this text relative to its first parent."""
154
154
        (parent_annotations,
155
155
         matching_blocks) = self._get_parent_annotations_and_matches(
156
 
                                key, lines, parent_key)
 
156
             key, lines, parent_key)
157
157
 
158
158
        for parent_idx, lines_idx, match_len in matching_blocks:
159
159
            # For all matching regions we copy across the parent annotations
165
165
        """Reannotate this text relative to a second (or more) parent."""
166
166
        (parent_annotations,
167
167
         matching_blocks) = self._get_parent_annotations_and_matches(
168
 
                                key, lines, parent_key)
 
168
             key, lines, parent_key)
169
169
 
170
170
        last_ann = None
171
171
        last_parent = None
183
183
            par_sub = parent_annotations[parent_idx:parent_idx + match_len]
184
184
            if ann_sub == par_sub:
185
185
                continue
186
 
            for idx in xrange(match_len):
 
186
            for idx in range(match_len):
187
187
                ann = ann_sub[idx]
188
188
                par_ann = par_sub[idx]
189
189
                ann_idx = lines_idx + idx
257
257
                        each key is a possible source for the given line.
258
258
            lines the text of "key" as a list of lines
259
259
        """
260
 
        pb = ui.ui_factory.nested_progress_bar()
261
 
        try:
262
 
            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):
263
263
                self._annotate_one(text_key, text, num_lines)
264
 
        finally:
265
 
            pb.finished()
266
264
        try:
267
265
            annotations = self._annotations_cache[key]
268
266
        except KeyError:
281
279
            # Backwards compatibility, break up the heads into pairs and
282
280
            # resolve the result
283
281
            next_head = iter(the_heads)
284
 
            head = next_head.next()
 
282
            head = next(next_head)
285
283
            for possible_head in next_head:
286
284
                annotated_lines = ((head, line), (possible_head, line))
287
285
                head = tiebreaker(annotated_lines)[0]
305
303
            else:
306
304
                the_heads = heads(annotation)
307
305
                if len(the_heads) == 1:
308
 
                    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
309
308
                else:
310
309
                    head = self._resolve_annotation_tie(the_heads, line,
311
310
                                                        custom_tiebreaker)