/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/plugins/commitfromnews/committemplate.py

  • Committer: Jelmer Vernooij
  • Date: 2018-02-18 21:42:57 UTC
  • mto: This revision was merged to the branch mainline in revision 6859.
  • Revision ID: jelmer@jelmer.uk-20180218214257-jpevutp1wa30tz3v
Update TODO to reference Breezy, not Bazaar.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Logic to create commit templates."""
18
18
 
19
 
import patiencediff
 
19
from __future__ import absolute_import
20
20
 
21
 
from ... import bugtracker, osutils
 
21
from ... import bugtracker, osutils, patiencediff
22
22
import re
23
23
 
24
24
_BUG_MATCH = re.compile(r'lp:(\d+)')
56
56
            return self.message
57
57
        if found_old_path is None:
58
58
            # New file
59
 
            _, new_chunks = next(
 
59
            _, new_chunks = list(
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)
64
64
        else:
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)
75
76
            lines = {}
76
77
            for name, chunks in contents:
77
 
                lines[name] = osutils.chunks_to_lines(list(chunks))
 
78
                lines[name] = osutils.chunks_to_lines(chunks)
78
79
            new = lines['new']
79
80
            sequence_matcher = patiencediff.PatienceSequenceMatcher(
80
81
                None, lines['old'], new)
85
86
                    continue
86
87
                if tag == 'delete':
87
88
                    continue
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
 
                         for bugid in bugids])
 
99
                        [bt.get_bug_url(bugid) for bugid in bugids])
100
100
            return self.merge_message(''.join(new_lines))
101
101
 
102
102
    def merge_message(self, new_message):