17
17
"""Merge logic for news_merge plugin."""
20
from bzrlib.plugins.news_merge.parser import simple_parse
20
from bzrlib.plugins.news_merge.parser import simple_parse_lines
21
21
from bzrlib import merge, merge3
24
magic_marker = '|NEWS-MERGE-MAGIC-MARKER|'
27
24
class NewsMerger(merge.ConfigurableFileMerger):
28
25
"""Merge bzr NEWS files."""
39
36
# Transform the different versions of the NEWS file into a bunch of
40
37
# text lines where each line matches one part of the overall
41
38
# structure, e.g. a heading or bullet.
43
return list(blocks_to_fakelines(simple_parse(''.join(lines))))
44
this_lines = munge(params.this_lines)
45
other_lines = munge(params.other_lines)
46
base_lines = munge(params.base_lines)
47
m3 = merge3.Merge3(base_lines, this_lines, other_lines)
39
this_lines = list(simple_parse_lines(params.this_lines))
40
other_lines = list(simple_parse_lines(params.other_lines))
41
base_lines = list(simple_parse_lines(params.base_lines))
42
m3 = merge3.Merge3(base_lines, this_lines, other_lines,
49
45
for group in m3.merge_groups():
50
46
if group[0] == 'conflict':
51
47
_, base, a, b = group
54
50
for line_set in [base, a, b]:
55
51
for line in line_set:
56
if not line.startswith('bullet'):
52
if line[0] != 'bullet':
57
53
# Something else :(
58
54
# Maybe the default merge can cope.
59
55
return 'not_applicable', None
70
66
final = sorted(final, key=sort_key)
71
result_lines.extend(final)
67
result_chunks.extend(final)
73
result_lines.extend(group[1])
69
result_chunks.extend(group[1])
74
70
# Transform the merged elements back into real blocks of lines.
75
return 'success', list(fakelines_to_blocks(result_lines))
78
def blocks_to_fakelines(blocks):
79
for kind, text in blocks:
80
yield '%s%s%s' % (kind, magic_marker, text)
83
def fakelines_to_blocks(fakelines):
84
fakelines = list(fakelines)
85
# Strip out the magic_marker, and reinstate the \n\n between blocks
86
for fakeline in fakelines[:-1]:
87
yield fakeline.split(magic_marker, 1)[1] + '\n\n'
88
# The final block doesn't have a trailing \n\n.
89
for fakeline in fakelines[-1:]:
90
yield fakeline.split(magic_marker, 1)[1]
94
return s.replace('`', '').lower()
71
result_lines = '\n\n'.join(chunk[1] for chunk in result_chunks)
72
return 'success', result_lines
76
return chunk[1].replace('`', '').lower()