~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge_directive.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-03-25 00:02:51 UTC
  • mfrom: (5106.1.1 version-bump)
  • Revision ID: pqm@pqm.ubuntu.com-20100325000251-bwsv5c5d3l9x3lnn
(Jelmer) Bump API version for 2.2.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2011 Canonical Ltd
 
1
# Copyright (C) 2007-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from __future__ import absolute_import
18
17
 
19
18
from StringIO import StringIO
20
19
import re
21
20
 
22
 
from bzrlib import lazy_import
23
 
lazy_import.lazy_import(globals(), """
24
21
from bzrlib import (
25
22
    branch as _mod_branch,
26
23
    diff,
27
 
    email_message,
28
24
    errors,
29
25
    gpg,
30
26
    hooks,
38
34
from bzrlib.bundle import (
39
35
    serializer as bundle_serializer,
40
36
    )
41
 
""")
 
37
from bzrlib.email_message import EmailMessage
42
38
 
43
39
 
44
40
class MergeRequestBodyParams(object):
60
56
    """Hooks for MergeDirective classes."""
61
57
 
62
58
    def __init__(self):
63
 
        hooks.Hooks.__init__(self, "bzrlib.merge_directive", "BaseMergeDirective.hooks")
64
 
        self.add_hook('merge_request_body',
 
59
        hooks.Hooks.__init__(self)
 
60
        self.create_hook(hooks.HookPoint('merge_request_body',
65
61
            "Called with a MergeRequestBodyParams when a body is needed for"
66
62
            " a merge request.  Callbacks must return a body.  If more"
67
63
            " than one callback is registered, the output of one callback is"
68
 
            " provided to the next.", (1, 15, 0))
 
64
            " provided to the next.", (1, 15, 0), False))
69
65
 
70
66
 
71
67
class BaseMergeDirective(object):
83
79
    multiple_output_files = False
84
80
 
85
81
    def __init__(self, revision_id, testament_sha1, time, timezone,
86
 
                 target_branch, patch=None, source_branch=None,
87
 
                 message=None, bundle=None):
 
82
                 target_branch, patch=None, source_branch=None, message=None,
 
83
                 bundle=None):
88
84
        """Constructor.
89
85
 
90
86
        :param revision_id: The revision to merge
92
88
            merge.
93
89
        :param time: The current POSIX timestamp time
94
90
        :param timezone: The timezone offset
95
 
        :param target_branch: Location of branch to apply the merge to
 
91
        :param target_branch: The branch to apply the merge to
96
92
        :param patch: The text of a diff or bundle
97
93
        :param source_branch: A public location to merge the revision from
98
94
        :param message: The message to use when committing this merge
166
162
        :param target_branch: The url of the branch to merge into
167
163
        :param patch_type: 'bundle', 'diff' or None, depending on the type of
168
164
            patch desired.
169
 
        :param local_target_branch: the submit branch, either itself or a local copy
170
 
        :param public_branch: location of a public branch containing
171
 
            the target revision.
 
165
        :param local_target_branch: a local copy of the target branch
 
166
        :param public_branch: location of a public branch containing the target
 
167
            revision.
172
168
        :param message: Message to use when committing the merge
173
169
        :return: The merge directive
174
170
 
182
178
        if revision_id == _mod_revision.NULL_REVISION:
183
179
            t_revision_id = None
184
180
        t = testament.StrictTestament3.from_revision(repository, t_revision_id)
185
 
        if local_target_branch is None:
186
 
            submit_branch = _mod_branch.Branch.open(target_branch)
187
 
        else:
188
 
            submit_branch = local_target_branch
 
181
        submit_branch = _mod_branch.Branch.open(target_branch)
189
182
        if submit_branch.get_public_branch() is not None:
190
183
            target_branch = submit_branch.get_public_branch()
191
184
        if patch_type is None:
248
241
        :param branch: The source branch, to get the signing strategy
249
242
        :return: a string
250
243
        """
251
 
        my_gpg = gpg.GPGStrategy(branch.get_config_stack())
 
244
        my_gpg = gpg.GPGStrategy(branch.get_config())
252
245
        return my_gpg.sign(''.join(self.to_lines()))
253
246
 
254
247
    def to_email(self, mail_to, branch, sign=False):
260
253
        :param sign: If True, gpg-sign the email
261
254
        :return: an email message
262
255
        """
263
 
        mail_from = branch.get_config_stack().get('email')
 
256
        mail_from = branch.get_config().username()
264
257
        if self.message is not None:
265
258
            subject = self.message
266
259
        else:
270
263
            body = self.to_signed(branch)
271
264
        else:
272
265
            body = ''.join(self.to_lines())
273
 
        message = email_message.EmailMessage(mail_from, mail_to, subject,
274
 
            body)
 
266
        message = EmailMessage(mail_from, mail_to, subject, body)
275
267
        return message
276
268
 
277
269
    def install_revisions(self, target_repo):
377
369
            merge.
378
370
        :param time: The current POSIX timestamp time
379
371
        :param timezone: The timezone offset
380
 
        :param target_branch: Location of the branch to apply the merge to
 
372
        :param target_branch: The branch to apply the merge to
381
373
        :param patch: The text of a diff or bundle
382
374
        :param patch_type: None, "diff" or "bundle", depending on the contents
383
375
            of patch
571
563
        :param target_branch: The url of the branch to merge into
572
564
        :param include_patch: If true, include a preview patch
573
565
        :param include_bundle: If true, include a bundle
574
 
        :param local_target_branch: the target branch, either itself or a local copy
575
 
        :param public_branch: location of a public branch containing
576
 
            the target revision.
 
566
        :param local_target_branch: a local copy of the target branch
 
567
        :param public_branch: location of a public branch containing the target
 
568
            revision.
577
569
        :param message: Message to use when committing the merge
578
570
        :return: The merge directive
579
571
 
592
584
                t_revision_id = None
593
585
            t = testament.StrictTestament3.from_revision(repository,
594
586
                t_revision_id)
595
 
            if local_target_branch is None:
596
 
                submit_branch = _mod_branch.Branch.open(target_branch)
597
 
            else:
598
 
                submit_branch = local_target_branch
 
587
            submit_branch = _mod_branch.Branch.open(target_branch)
599
588
            submit_branch.lock_read()
600
589
            locked.append(submit_branch)
601
590
            if submit_branch.get_public_branch() is not None: