/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/annotate.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-04 00:16:27 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304001627-v6u7o6pf97tukhek
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
    )
39
39
""")
40
40
from . import (
41
 
    errors,
42
41
    osutils,
43
42
    )
44
43
from .config import (
54
53
 
55
54
 
56
55
def annotate_file_tree(tree, path, to_file, verbose=False, full=False,
57
 
    show_ids=False, branch=None, file_id=None):
58
 
    """Annotate file_id in a tree.
 
56
                       show_ids=False, branch=None):
 
57
    """Annotate path in a tree.
59
58
 
60
59
    The tree should already be read_locked() when annotate_file_tree is called.
61
60
 
66
65
        reasonable text width.
67
66
    :param full: XXXX Not sure what this does.
68
67
    :param show_ids: Show revision ids in the annotation output.
69
 
    :param file_id: The file_id to annotate (must match file path)
70
68
    :param branch: Branch to use for revision revno lookups
71
69
    """
72
70
    if branch is None:
76
74
 
77
75
    encoding = osutils.get_terminal_encoding()
78
76
    # Handle the show_ids case
79
 
    annotations = list(tree.annotate_iter(path, file_id))
 
77
    annotations = list(tree.annotate_iter(path))
80
78
    if show_ids:
81
79
        return _show_id_annotations(annotations, to_file, full, encoding)
82
80
 
95
93
        current_rev.timezone = osutils.local_time_offset()
96
94
    else:
97
95
        current_rev = None
98
 
    annotation = list(_expand_annotations(annotations, branch,
99
 
        current_rev))
 
96
    annotation = list(_expand_annotations(
 
97
        annotations, branch, current_rev))
100
98
    _print_annotations(annotation, verbose, to_file, full, encoding)
101
99
 
102
100
 
109
107
    :param full: XXXX Not sure what this does.
110
108
    """
111
109
    if len(annotation) == 0:
112
 
        max_origin_len = max_revno_len = max_revid_len = 0
 
110
        max_origin_len = max_revno_len = 0
113
111
    else:
114
112
        max_origin_len = max(len(x[1]) for x in annotation)
115
113
        max_revno_len = max(len(x[0]) for x in annotation)
116
 
        max_revid_len = max(len(x[3]) for x in annotation)
117
114
    if not verbose:
118
115
        max_revno_len = min(max_revno_len, 12)
119
116
    max_revno_len = max(max_revno_len, 3)
126
123
                                       max_origin_len, author, date_str)
127
124
        else:
128
125
            if len(revno_str) > max_revno_len:
129
 
                revno_str = revno_str[:max_revno_len-1] + '>'
 
126
                revno_str = revno_str[:max_revno_len - 1] + '>'
130
127
            anno = "%-*s %-7s " % (max_revno_len, revno_str, author[:7])
131
128
        if anno.lstrip() == "" and full:
132
129
            anno = prevanno
147
144
            this = origin
148
145
        else:
149
146
            this = b''
150
 
        to_file.write('%*s | %s' % (max_origin_len, this.decode('utf-8'),
151
 
            text.decode(encoding)))
 
147
        to_file.write('%*s | %s' % (
 
148
            max_origin_len, this.decode('utf-8'), text.decode(encoding)))
152
149
        last_rev_id = origin
153
150
    return
154
151
 
175
172
        #      Once KnownGraph gets an 'add_node()' function, we can use
176
173
        #      VF.get_known_graph_ancestry().
177
174
        graph = repository.get_graph()
178
 
        revision_graph = dict(((key, value) for key, value in
179
 
            graph.iter_ancestry(current_rev.parent_ids) if value is not None))
 
175
        revision_graph = {
 
176
            key: value for key, value in
 
177
            graph.iter_ancestry(current_rev.parent_ids) if value is not None}
180
178
        revision_graph = _strip_NULL_ghosts(revision_graph)
181
179
        revision_graph[last_revision] = current_rev.parent_ids
182
180
        merge_sorted_revisions = tsort.merge_sort(
184
182
            last_revision,
185
183
            None,
186
184
            generate_revno=True)
187
 
        revision_id_to_revno = dict((rev_id, revno)
 
185
        revision_id_to_revno = {
 
186
            rev_id: revno
188
187
            for seq_num, rev_id, depth, revno, end_of_merge in
189
 
                merge_sorted_revisions)
 
188
            merge_sorted_revisions}
190
189
    else:
191
190
        # TODO(jelmer): Only look up the revision ids that we need (i.e. those
192
191
        # in revision_ids). Possibly add a HPSS call that can look those up
199
198
            "%d?" % (branch.revno() + 1),)
200
199
        revisions[CURRENT_REVISION] = current_rev
201
200
    revisions.update(
202
 
            entry for entry in
203
 
            repository.iter_revisions(revision_ids)
204
 
            if entry[1] is not None)
 
201
        entry for entry in
 
202
        repository.iter_revisions(revision_ids)
 
203
        if entry[1] is not None)
205
204
    for origin, text in annotations:
206
205
        text = text.rstrip(b'\r\n')
207
206
        if origin == last_origin:
211
210
            if origin not in revisions:
212
211
                (revno_str, author, date_str) = ('?', '?', '?')
213
212
            else:
214
 
                revno_str = '.'.join(str(i) for i in
215
 
                                            revision_id_to_revno[origin])
 
213
                revno_str = '.'.join(
 
214
                    str(i) for i in revision_id_to_revno[origin])
216
215
            rev = revisions[origin]
217
216
            tz = rev.timezone or 0
218
217
            date_str = time.strftime('%Y%m%d',
283
282
    new_cur = 0
284
283
    if matching_blocks is None:
285
284
        plain_parent_lines = [l for r, l in parent_lines]
286
 
        matcher = patiencediff.PatienceSequenceMatcher(None,
287
 
            plain_parent_lines, new_lines)
 
285
        matcher = patiencediff.PatienceSequenceMatcher(
 
286
            None, plain_parent_lines, new_lines)
288
287
        matching_blocks = matcher.get_matching_blocks()
289
288
    lines = []
290
289
    for i, j, n in matching_blocks:
291
290
        for line in new_lines[new_cur:j]:
292
291
            lines.append((new_revision_id, line))
293
 
        lines.extend(parent_lines[i:i+n])
 
292
        lines.extend(parent_lines[i:i + n])
294
293
        new_cur = j + n
295
294
    return lines
296
295
 
302
301
 
303
302
_break_annotation_tie = None
304
303
 
 
304
 
305
305
def _old_break_annotation_tie(annotated_lines):
306
306
    """Chose an attribution between several possible ones.
307
307
 
358
358
    for right_idx, child_idx, match_len in match_blocks:
359
359
        # All the lines that don't match are just passed along
360
360
        if child_idx > last_child_idx:
361
 
            output_extend(child_lines[start_child + last_child_idx
362
 
                                      :start_child + child_idx])
 
361
            output_extend(child_lines[start_child + last_child_idx:
 
362
                                      start_child + child_idx])
363
363
        for offset in range(match_len):
364
 
            left = child_lines[start_child+child_idx+offset]
365
 
            right = right_lines[start_right+right_idx+offset]
 
364
            left = child_lines[start_child + child_idx + offset]
 
365
            right = right_lines[start_right + right_idx + offset]
366
366
            if left[0] == right[0]:
367
367
                # The annotations match, just return the left one
368
368
                output_append(left)
412
412
    # be the bulk of the lines, and they will need no further processing.
413
413
    lines = []
414
414
    lines_extend = lines.extend
415
 
    last_right_idx = 0 # The line just after the last match from the right side
 
415
    # The line just after the last match from the right side
 
416
    last_right_idx = 0
416
417
    last_left_idx = 0
417
418
    matching_left_and_right = _get_matching_blocks(right_parent_lines,
418
419
                                                   annotated_lines)
443
444
    from breezy._annotator_pyx import Annotator
444
445
except ImportError as e:
445
446
    osutils.failed_to_load_extension(e)
446
 
    from breezy._annotator_py import Annotator
 
447
    from breezy._annotator_py import Annotator  # noqa: F401