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

  • Committer: Jelmer Vernooij
  • Date: 2017-06-10 00:21:41 UTC
  • mto: This revision was merged to the branch mainline in revision 6675.
  • Revision ID: jelmer@jelmer.uk-20170610002141-m1z5k7fs8laesa65
Fix import.

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
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
17
18
 
18
 
from StringIO import StringIO
19
19
import re
20
20
 
21
 
from bzrlib import (
 
21
from . import lazy_import
 
22
lazy_import.lazy_import(globals(), """
 
23
from breezy import (
22
24
    branch as _mod_branch,
23
25
    diff,
 
26
    email_message,
24
27
    errors,
25
28
    gpg,
26
29
    hooks,
31
34
    timestamp,
32
35
    trace,
33
36
    )
34
 
from bzrlib.bundle import (
 
37
from breezy.bundle import (
35
38
    serializer as bundle_serializer,
36
39
    )
37
 
from bzrlib.email_message import EmailMessage
 
40
""")
 
41
from .sixish import (
 
42
    BytesIO,
 
43
    )
38
44
 
39
45
 
40
46
class MergeRequestBodyParams(object):
56
62
    """Hooks for MergeDirective classes."""
57
63
 
58
64
    def __init__(self):
59
 
        hooks.Hooks.__init__(self)
60
 
        self.create_hook(hooks.HookPoint('merge_request_body',
 
65
        hooks.Hooks.__init__(self, "breezy.merge_directive", "BaseMergeDirective.hooks")
 
66
        self.add_hook('merge_request_body',
61
67
            "Called with a MergeRequestBodyParams when a body is needed for"
62
68
            " a merge request.  Callbacks must return a body.  If more"
63
69
            " than one callback is registered, the output of one callback is"
64
 
            " provided to the next.", (1, 15, 0), False))
 
70
            " provided to the next.", (1, 15, 0))
65
71
 
66
72
 
67
73
class BaseMergeDirective(object):
79
85
    multiple_output_files = False
80
86
 
81
87
    def __init__(self, revision_id, testament_sha1, time, timezone,
82
 
                 target_branch, patch=None, source_branch=None, message=None,
83
 
                 bundle=None):
 
88
                 target_branch, patch=None, source_branch=None,
 
89
                 message=None, bundle=None):
84
90
        """Constructor.
85
91
 
86
92
        :param revision_id: The revision to merge
88
94
            merge.
89
95
        :param time: The current POSIX timestamp time
90
96
        :param timezone: The timezone offset
91
 
        :param target_branch: The branch to apply the merge to
 
97
        :param target_branch: Location of branch to apply the merge to
92
98
        :param patch: The text of a diff or bundle
93
99
        :param source_branch: A public location to merge the revision from
94
100
        :param message: The message to use when committing this merge
162
168
        :param target_branch: The url of the branch to merge into
163
169
        :param patch_type: 'bundle', 'diff' or None, depending on the type of
164
170
            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.
 
171
        :param local_target_branch: the submit branch, either itself or a local copy
 
172
        :param public_branch: location of a public branch containing
 
173
            the target revision.
168
174
        :param message: Message to use when committing the merge
169
175
        :return: The merge directive
170
176
 
178
184
        if revision_id == _mod_revision.NULL_REVISION:
179
185
            t_revision_id = None
180
186
        t = testament.StrictTestament3.from_revision(repository, t_revision_id)
181
 
        submit_branch = _mod_branch.Branch.open(target_branch)
 
187
        if local_target_branch is None:
 
188
            submit_branch = _mod_branch.Branch.open(target_branch)
 
189
        else:
 
190
            submit_branch = local_target_branch
182
191
        if submit_branch.get_public_branch() is not None:
183
192
            target_branch = submit_branch.get_public_branch()
184
193
        if patch_type is None:
224
233
    def _generate_diff(repository, revision_id, ancestor_id):
225
234
        tree_1 = repository.revision_tree(ancestor_id)
226
235
        tree_2 = repository.revision_tree(revision_id)
227
 
        s = StringIO()
 
236
        s = BytesIO()
228
237
        diff.show_diff_trees(tree_1, tree_2, s, old_label='', new_label='')
229
238
        return s.getvalue()
230
239
 
231
240
    @staticmethod
232
241
    def _generate_bundle(repository, revision_id, ancestor_id):
233
 
        s = StringIO()
 
242
        s = BytesIO()
234
243
        bundle_serializer.write_bundle(repository, revision_id,
235
244
                                       ancestor_id, s)
236
245
        return s.getvalue()
241
250
        :param branch: The source branch, to get the signing strategy
242
251
        :return: a string
243
252
        """
244
 
        my_gpg = gpg.GPGStrategy(branch.get_config())
 
253
        my_gpg = gpg.GPGStrategy(branch.get_config_stack())
245
254
        return my_gpg.sign(''.join(self.to_lines()))
246
255
 
247
256
    def to_email(self, mail_to, branch, sign=False):
253
262
        :param sign: If True, gpg-sign the email
254
263
        :return: an email message
255
264
        """
256
 
        mail_from = branch.get_config().username()
 
265
        mail_from = branch.get_config_stack().get('email')
257
266
        if self.message is not None:
258
267
            subject = self.message
259
268
        else:
263
272
            body = self.to_signed(branch)
264
273
        else:
265
274
            body = ''.join(self.to_lines())
266
 
        message = EmailMessage(mail_from, mail_to, subject, body)
 
275
        message = email_message.EmailMessage(mail_from, mail_to, subject,
 
276
            body)
267
277
        return message
268
278
 
269
279
    def install_revisions(self, target_repo):
271
281
        if not target_repo.has_revision(self.revision_id):
272
282
            if self.patch_type == 'bundle':
273
283
                info = bundle_serializer.read_bundle(
274
 
                    StringIO(self.get_raw_bundle()))
 
284
                    BytesIO(self.get_raw_bundle()))
275
285
                # We don't use the bundle's target revision, because
276
286
                # MergeDirective.revision_id is authoritative.
277
287
                try:
369
379
            merge.
370
380
        :param time: The current POSIX timestamp time
371
381
        :param timezone: The timezone offset
372
 
        :param target_branch: The branch to apply the merge to
 
382
        :param target_branch: Location of the branch to apply the merge to
373
383
        :param patch: The text of a diff or bundle
374
384
        :param patch_type: None, "diff" or "bundle", depending on the contents
375
385
            of patch
427
437
        else:
428
438
            patch = ''.join(patch_lines)
429
439
            try:
430
 
                bundle_serializer.read_bundle(StringIO(patch))
 
440
                bundle_serializer.read_bundle(BytesIO(patch))
431
441
            except (errors.NotABundle, errors.BundleNotSupported,
432
442
                    errors.BadBundle):
433
443
                patch_type = 'diff'
453
463
 
454
464
    @staticmethod
455
465
    def _generate_bundle(repository, revision_id, ancestor_id):
456
 
        s = StringIO()
 
466
        s = BytesIO()
457
467
        bundle_serializer.write_bundle(repository, revision_id,
458
468
                                       ancestor_id, s, '0.9')
459
469
        return s.getvalue()
506
516
        patch = None
507
517
        bundle = None
508
518
        try:
509
 
            start = line_iter.next()
 
519
            start = next(line_iter)
510
520
        except StopIteration:
511
521
            pass
512
522
        else:
563
573
        :param target_branch: The url of the branch to merge into
564
574
        :param include_patch: If true, include a preview patch
565
575
        :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.
 
576
        :param local_target_branch: the target branch, either itself or a local copy
 
577
        :param public_branch: location of a public branch containing
 
578
            the target revision.
569
579
        :param message: Message to use when committing the merge
570
580
        :return: The merge directive
571
581
 
584
594
                t_revision_id = None
585
595
            t = testament.StrictTestament3.from_revision(repository,
586
596
                t_revision_id)
587
 
            submit_branch = _mod_branch.Branch.open(target_branch)
 
597
            if local_target_branch is None:
 
598
                submit_branch = _mod_branch.Branch.open(target_branch)
 
599
            else:
 
600
                submit_branch = local_target_branch
588
601
            submit_branch.lock_read()
589
602
            locked.append(submit_branch)
590
603
            if submit_branch.get_public_branch() is not None: