/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: 2017-07-23 19:18:44 UTC
  • mto: This revision was merged to the branch mainline in revision 6739.
  • Revision ID: jelmer@jelmer.uk-20170723191844-5me3az7xe3rnbheg
The 'commitfromnews' plugin is now bundled.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
from __future__ import absolute_import
20
20
 
21
 
from ... import bugtracker, errors, osutils, patiencediff
 
21
from ... import bugtracker, osutils, patiencediff
22
22
import re
23
23
 
24
24
_BUG_MATCH = re.compile(r'lp:(\d+)')
25
25
 
 
26
 
26
27
class CommitTemplate(object):
27
28
 
28
 
    def __init__(self, commit, message):
 
29
    def __init__(self, commit, message, filespec):
29
30
        """Create a commit template for commit with initial message message.
30
31
 
31
32
        :param commit: A Commit object for the in progress commit.
32
33
        :param message: The current message (which may be None).
 
34
        :param filespec: File specification list
33
35
        """
34
36
        self.commit = commit
35
37
        self.message = message
 
38
        self.filespec = filespec
36
39
 
37
40
    def make(self):
38
41
        """Make the template.
41
44
        returned unaltered. Otherwise the changes from NEWS are concatenated
42
45
        with whatever message was provided to __init__.
43
46
        """
44
 
        try:
45
 
            delta = self.commit.builder.get_basis_delta()
46
 
        except AssertionError:
47
 
            # Not 2a, someone can write a slow-format code path if they want
48
 
            # to.
49
 
            return self.messsage
 
47
        delta = self.commit.builder.get_basis_delta()
50
48
        found_old_path = None
51
49
        found_entry = None
52
50
        for old_path, new_path, fileid, entry in delta:
53
 
            if new_path == 'NEWS':
 
51
            if new_path in self.filespec:
54
52
                found_entry = entry
55
53
                found_old_path = old_path
56
54
                break
58
56
            return self.message
59
57
        if found_old_path is None:
60
58
            # New file
61
 
            _, new_chunks = list(self.commit.builder.repository.iter_files_bytes(
62
 
                [(found_entry.file_id, found_entry.revision, None)]))[0]
 
59
            _, new_chunks = list(
 
60
                self.commit.builder.repository.iter_files_bytes(
 
61
                    [(found_entry.file_id, found_entry.revision, None)]))[0]
63
62
            content = ''.join(new_chunks)
64
63
            return self.merge_message(content)
65
64
        else:
69
68
            # final diff: because we want to grab the sections for regions 
70
69
            # changed in new version of the file. So for now a direct diff
71
70
            # using patiencediff is done.
72
 
            old_revision = self.commit.basis_tree.get_file_revision(found_entry.file_id)
 
71
            old_revision = self.commit.basis_tree.get_file_revision(
 
72
                found_entry.file_id)
73
73
            needed = [(found_entry.file_id, found_entry.revision, 'new'),
74
74
                      (found_entry.file_id, old_revision, 'old')]
75
75
            contents = self.commit.builder.repository.iter_files_bytes(needed)
101
101
 
102
102
    def merge_message(self, new_message):
103
103
        """Merge new_message with self.message.
104
 
        
 
104
 
105
105
        :param new_message: A string message to merge with self.message.
106
106
        :return: A string with the merged messages.
107
107
        """