/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-06-02 02:35:46 UTC
  • mfrom: (7309 work)
  • mto: This revision was merged to the branch mainline in revision 7319.
  • Revision ID: jelmer@jelmer.uk-20190602023546-lqco868tnv26d8ow
merge trunk.

Show diffs side-by-side

added added

removed removed

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