/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: 2019-06-02 02:35:46 UTC
  • mfrom: (7309 work)
  • mto: This revision was merged to the branch mainline in revision 7319.
  • Revision ID: jelmer@jelmer.uk-20190602023546-lqco868tnv26d8ow
merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
    registry,
32
32
    revision as _mod_revision,
33
33
    rio,
34
 
    testament,
35
34
    timestamp,
36
35
    trace,
37
36
    )
 
37
from breezy.bzr import (
 
38
    testament,
 
39
    )
38
40
from breezy.bundle import (
39
41
    serializer as bundle_serializer,
40
42
    )
63
65
    """Hooks for MergeDirective classes."""
64
66
 
65
67
    def __init__(self):
66
 
        hooks.Hooks.__init__(self, "breezy.merge_directive", "BaseMergeDirective.hooks")
67
 
        self.add_hook('merge_request_body',
 
68
        hooks.Hooks.__init__(self, "breezy.merge_directive",
 
69
                             "BaseMergeDirective.hooks")
 
70
        self.add_hook(
 
71
            'merge_request_body',
68
72
            "Called with a MergeRequestBodyParams when a body is needed for"
69
73
            " a merge request.  Callbacks must return a body.  If more"
70
74
            " than one callback is registered, the output of one callback is"
74
78
class BaseMergeDirective(object):
75
79
    """A request to perform a merge into a branch.
76
80
 
77
 
    This is the base class that all merge directive implementations 
 
81
    This is the base class that all merge directive implementations
78
82
    should derive from.
79
83
 
80
 
    :cvar multiple_output_files: Whether or not this merge directive 
 
84
    :cvar multiple_output_files: Whether or not this merge directive
81
85
        stores a set of revisions in more than one file
82
86
    """
83
87
 
158
162
 
159
163
    @classmethod
160
164
    def from_objects(klass, repository, revision_id, time, timezone,
161
 
                 target_branch, patch_type='bundle',
162
 
                 local_target_branch=None, public_branch=None, message=None):
 
165
                     target_branch, patch_type='bundle',
 
166
                     local_target_branch=None, public_branch=None, message=None):
163
167
        """Generate a merge directive from various objects
164
168
 
165
169
        :param repository: The repository containing the revision
202
206
                                                submit_revision_id)
203
207
            type_handler = {'bundle': klass._generate_bundle,
204
208
                            'diff': klass._generate_diff,
205
 
                            None: lambda x, y, z: None }
 
209
                            None: lambda x, y, z: None}
206
210
            patch = type_handler[patch_type](repository, revision_id,
207
211
                                             ancestor_id)
208
212
 
213
217
                                                   revision_id)
214
218
 
215
219
        return klass(revision_id, t.as_sha1(), time, timezone, target_branch,
216
 
            patch, patch_type, public_branch, message)
 
220
                     patch, patch_type, public_branch, message)
217
221
 
218
222
    def get_disk_name(self, branch):
219
223
        """Generate a suitable basename for storing this directive on disk
276
280
        else:
277
281
            body = b''.join(self.to_lines())
278
282
        message = email_message.EmailMessage(mail_from, mail_to, subject,
279
 
            body)
 
283
                                             body)
280
284
        return message
281
285
 
282
286
    def install_revisions(self, target_repo):
302
306
                                           info.real_revisions)
303
307
                    for revision in info.real_revisions:
304
308
                        for parent_id in revision.parent_ids:
305
 
                            if (parent_id not in bundle_revisions and
306
 
                                not target_repo.has_revision(parent_id)):
 
309
                            if (parent_id not in bundle_revisions
 
310
                                    and not target_repo.has_revision(parent_id)):
307
311
                                missing_revisions.append(parent_id)
308
312
                    # reverse missing revisions to try to get heads first
309
313
                    unique_missing = []
348
352
        elif len(self.hooks['merge_request_body']) > 0:
349
353
            trace.warning('Cannot run merge_request_body hooks because mail'
350
354
                          ' client %s does not support message bodies.',
351
 
                        mail_client.__class__.__name__)
 
355
                          mail_client.__class__.__name__)
352
356
        mail_client.compose_merge_request(to, subject,
353
357
                                          b''.join(self.to_lines()),
354
358
                                          basename, body)
390
394
        :param message: The message to use when committing this merge
391
395
        """
392
396
        BaseMergeDirective.__init__(self, revision_id, testament_sha1, time,
393
 
            timezone, target_branch, patch, source_branch, message)
 
397
                                    timezone, target_branch, patch, source_branch, message)
394
398
        if patch_type not in (None, 'diff', 'bundle'):
395
399
            raise ValueError(patch_type)
396
400
        if patch_type != 'bundle' and source_branch is None:
491
495
        if source_branch is None and bundle is None:
492
496
            raise errors.NoMergeSource()
493
497
        BaseMergeDirective.__init__(self, revision_id, testament_sha1, time,
494
 
            timezone, target_branch, patch, source_branch, message)
 
498
                                    timezone, target_branch, patch, source_branch, message)
495
499
        self.bundle = bundle
496
500
        self.base_revision_id = base_revision_id
497
501
 
568
572
 
569
573
    @classmethod
570
574
    def from_objects(klass, repository, revision_id, time, timezone,
571
 
                 target_branch, include_patch=True, include_bundle=True,
572
 
                 local_target_branch=None, public_branch=None, message=None,
573
 
                 base_revision_id=None):
 
575
                     target_branch, include_patch=True, include_bundle=True,
 
576
                     local_target_branch=None, public_branch=None, message=None,
 
577
                     base_revision_id=None):
574
578
        """Generate a merge directive from various objects
575
579
 
576
580
        :param repository: The repository containing the revision
600
604
            if revision_id == b'null:':
601
605
                t_revision_id = None
602
606
            t = testament.StrictTestament3.from_revision(repository,
603
 
                t_revision_id)
 
607
                                                         t_revision_id)
604
608
            if local_target_branch is None:
605
609
                submit_branch = _mod_branch.Branch.open(target_branch)
606
610
            else:
626
630
 
627
631
            if include_bundle:
628
632
                bundle = base64.b64encode(klass._generate_bundle(repository, revision_id,
629
 
                    ancestor_id))
 
633
                                                                 ancestor_id))
630
634
            else:
631
635
                bundle = None
632
636
 
635
639
                public_branch_obj.lock_read()
636
640
                locked.append(public_branch_obj)
637
641
                if not public_branch_obj.repository.has_revision(
638
 
                    revision_id):
 
642
                        revision_id):
639
643
                    raise errors.PublicBranchOutOfDate(public_branch,
640
644
                                                       revision_id)
641
645
            testament_sha1 = t.as_sha1()
643
647
            for entry in reversed(locked):
644
648
                entry.unlock()
645
649
        return klass(revision_id, testament_sha1, time, timezone,
646
 
            target_branch, patch, public_branch, message, bundle,
647
 
            base_revision_id)
 
650
                     target_branch, patch, public_branch, message, bundle,
 
651
                     base_revision_id)
648
652
 
649
653
    def _verify_patch(self, repository):
650
654
        calculated_patch = self._generate_diff(repository, self.revision_id,