17
17
"""Logic to create commit templates."""
19
from __future__ import absolute_import
21
from ... import bugtracker, osutils
21
from ... import bugtracker, osutils, patiencediff
24
24
_BUG_MATCH = re.compile(r'lp:(\d+)')
56
56
return self.message
57
57
if found_old_path is None:
60
60
self.commit.builder.repository.iter_files_bytes(
61
[(found_entry.file_id, found_entry.revision, None)]))
62
content = b''.join(new_chunks).decode('utf-8')
61
[(found_entry.file_id, found_entry.revision, None)]))[0]
62
content = ''.join(new_chunks)
63
63
return self.merge_message(content)
65
65
# Get a diff. XXX Is this hookable? I thought it was, can't find it
66
# though.... add DiffTree.diff_factories. Sadly thats not at the
66
# though.... add DiffTree.diff_factories. Sadly thats not at the
67
67
# right level: we want to identify the changed lines, not have the
68
# final diff: because we want to grab the sections for regions
68
# final diff: because we want to grab the sections for regions
69
69
# changed in new version of the file. So for now a direct diff
70
70
# using patiencediff is done.
71
old_revision = self.commit.basis_tree.get_file_revision(old_path)
71
old_revision = self.commit.basis_tree.get_file_revision(
72
old_path, found_entry.file_id)
72
73
needed = [(found_entry.file_id, found_entry.revision, 'new'),
73
74
(found_entry.file_id, old_revision, 'old')]
74
75
contents = self.commit.builder.repository.iter_files_bytes(needed)
76
77
for name, chunks in contents:
77
lines[name] = osutils.chunks_to_lines(list(chunks))
78
lines[name] = osutils.chunks_to_lines(chunks)
79
80
sequence_matcher = patiencediff.PatienceSequenceMatcher(
80
81
None, lines['old'], new)
86
87
if tag == 'delete':
88
new_lines.extend([l.decode('utf-8') for l in new[j1:j2]])
89
new_lines.extend(new[j1:j2])
89
90
if not self.commit.revprops.get('bugs'):
90
91
# TODO: Allow the user to configure the bug tracker to use
91
92
# rather than hardcoding Launchpad.
95
96
bugids.extend(_BUG_MATCH.findall(line))
96
97
self.commit.revprops['bugs'] = \
97
98
bugtracker.encode_fixes_bug_urls(
98
[(bt.get_bug_url(bugid), bugtracker.FIXED)
99
[bt.get_bug_url(bugid) for bugid in bugids])
100
100
return self.merge_message(''.join(new_lines))
102
102
def merge_message(self, new_message):