~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge_directive.py

  • Committer: Jelmer Vernooij
  • Date: 2011-12-16 16:40:10 UTC
  • mto: This revision was merged to the branch mainline in revision 6391.
  • Revision ID: jelmer@samba.org-20111216164010-z3hy00xrnclnkf7a
Update tests.

Show diffs side-by-side

added added

removed removed

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