/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-11 04:08:32 UTC
  • mto: (7143.16.20 even-more-cleanups)
  • mto: This revision was merged to the branch mainline in revision 7175.
  • Revision ID: jelmer@jelmer.uk-20181111040832-nsljjynzzwmznf3h
Run autopep8.

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