/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: 2018-11-16 23:15:15 UTC
  • mfrom: (7180 work)
  • mto: This revision was merged to the branch mainline in revision 7183.
  • Revision ID: jelmer@jelmer.uk-20181116231515-zqd2yn6kj8lfydyp
Merge trunk.

Show diffs side-by-side

added added

removed removed

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