/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 bzrlib/merge_directive.py

  • Committer: Aaron Bentley
  • Date: 2007-03-09 06:39:54 UTC
  • mto: (2323.6.9 0.15-integration)
  • mto: This revision was merged to the branch mainline in revision 2330.
  • Revision ID: aaron.bentley@utoronto.ca-20070309063954-kla33k312hc97fkg
Add docs for MergeDirective and RIO-patch functions

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
class MergeDirective(object):
35
35
 
 
36
    """A request to perform a merge into a branch.
 
37
 
 
38
    Designed to be serialized and mailed.  It provides all the information
 
39
    needed to perform a merge automatically, by providing at minimum a revision
 
40
    bundle or the location of a branch.
 
41
 
 
42
    The serialization format is robust against certain common forms of
 
43
    deterioration caused by mailing.
 
44
 
 
45
    The format is also designed to be patch-compatible.  If the directive
 
46
    includes a diff or revision bundle, it should be possible to apply it
 
47
    directly using the standard patch program.
 
48
    """
 
49
 
36
50
    _format_string = 'Bazaar merge directive format experimental-1'
37
51
 
38
52
    def __init__(self, revision_id, testament_sha1, time, timezone,
39
53
                 target_branch, patch=None, patch_type=None,
40
54
                 source_branch=None, message=None):
 
55
        """Constructor.
 
56
 
 
57
        :param revision_id: The revision to merge
 
58
        :param testament_sha1: The sha1 of the testament of the revision to
 
59
            merge.
 
60
        :param time: The current POSIX timestamp time
 
61
        :param timezone: The timezone offset
 
62
        :param target_branch: The branch to apply the merge to
 
63
        :param patch: The text of a diff or bundle
 
64
        :param patch_type: None, "diff" or "bundle", depending on the contents
 
65
            of patch
 
66
        :param source_branch: A public location to merge the revision from
 
67
        :param message: The message to use when committing this merge
 
68
        """
41
69
        assert patch_type in (None, 'diff', 'bundle')
42
70
        if patch_type != 'bundle' and source_branch is None:
43
71
            raise errors.NoMergeSource()
55
83
 
56
84
    @classmethod
57
85
    def from_lines(klass, lines):
 
86
        """Deserialize a MergeRequest from an iterable of lines
 
87
 
 
88
        :param lines: An iterable of lines
 
89
        :return: a MergeRequest
 
90
        """
58
91
        assert lines[0].startswith('# ' + klass._format_string + '\n')
59
92
        line_iter = iter(lines[1:])
60
93
        stanza = rio.read_patch_stanza(line_iter)
81
114
                              patch_type=patch_type, patch=patch, **kwargs)
82
115
 
83
116
    def to_lines(self):
 
117
        """Serialize as a list of lines
 
118
 
 
119
        :return: a list of lines
 
120
        """
84
121
        time_str = timestamp.format_patch_date(self.time, self.timezone)
85
122
        stanza = rio.Stanza(revision_id=self.revision_id, timestamp=time_str,
86
123
                            target_branch=self.target_branch,
96
133
        return lines
97
134
 
98
135
    def to_signed(self, branch):
 
136
        """Serialize as a signed string.
 
137
 
 
138
        :param branch: The source branch, to get the signing strategy
 
139
        :return: a string
 
140
        """
99
141
        my_gpg = gpg.GPGStrategy(branch.get_config())
100
142
        return my_gpg.sign(''.join(self.to_lines()))
101
143
 
102
144
    def to_email(self, mail_to, branch, sign=False):
 
145
        """Serialize as an email message.
 
146
 
 
147
        :param mail_to: The address to mail the message to
 
148
        :param branch: The source branch, to get the signing strategy and
 
149
            source email address
 
150
        :param sign: If True, gpg-sign the email
 
151
        :return: an email message
 
152
        """
103
153
        mail_from = branch.get_config().username()
104
154
        message = Message.Message()
105
155
        message['To'] = mail_to
120
170
    def from_objects(klass, repository, revision_id, time, timezone,
121
171
                 target_branch, patch_type='bundle',
122
172
                 local_target_branch=None, public_branch=None, message=None):
 
173
        """Generate a merge directive from various objects
 
174
 
 
175
        :param repository: The repository containing the revision
 
176
        :param revision_id: The revision to merge
 
177
        :param time: The POSIX timestamp of the date the request was issued.
 
178
        :param timezone: The timezone of the request
 
179
        :param target_branch: The url of the branch to merge into
 
180
        :param patch_type: 'bundle', 'diff' or None, depending on the type of
 
181
            patch desired.
 
182
        :param local_target_branch: a local copy of the target branch
 
183
        :param public_branch: location of a public branch containing the target
 
184
            revision.
 
185
        :param message: Message to use when committing the merge
 
186
        :return: The merge directive
 
187
 
 
188
        The public branch is always used if supplied.  If the patch_type is
 
189
        not 'bundle', the public branch must be supplied, and will be verified.
 
190
 
 
191
        If the message is not supplied, the message from revision_id will be
 
192
        used for the commit.
 
193
        """
123
194
        t = testament.StrictTestament3.from_revision(repository, revision_id)
124
195
        if patch_type is None:
125
196
            patch = None