1
# Copyright (C) 2007 Canonical Ltd
1
# Copyright (C) 2007-2011 Canonical Ltd
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
34
37
from bzrlib.bundle import (
35
38
serializer as bundle_serializer,
37
from bzrlib.email_message import EmailMessage
40
43
class MergeRequestBodyParams(object):
56
59
"""Hooks for MergeDirective classes."""
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
class _BaseMergeDirective(object):
67
" provided to the next.", (1, 15, 0))
70
class BaseMergeDirective(object):
71
"""A request to perform a merge into a branch.
73
This is the base class that all merge directive implementations
76
:cvar multiple_output_files: Whether or not this merge directive
77
stores a set of revisions in more than one file
69
80
hooks = MergeDirectiveHooks()
82
multiple_output_files = False
71
84
def __init__(self, revision_id, testament_sha1, time, timezone,
72
85
target_branch, patch=None, source_branch=None, message=None,
92
105
self.source_branch = source_branch
93
106
self.message = message
109
"""Serialize as a list of lines
111
:return: a list of lines
113
raise NotImplementedError(self.to_lines)
116
"""Serialize as a set of files.
118
:return: List of tuples with filename and contents as lines
120
raise NotImplementedError(self.to_files)
122
def get_raw_bundle(self):
123
"""Return the bundle for this merge directive.
125
:return: bundle text or None if there is no bundle
95
129
def _to_lines(self, base_revision=False):
96
130
"""Serialize as a list of lines
111
145
lines.append('# \n')
148
def write_to_directory(self, path):
149
"""Write this merge directive to a series of files in a directory.
151
:param path: Filesystem path to write to
153
raise NotImplementedError(self.write_to_directory)
115
156
def from_objects(klass, repository, revision_id, time, timezone,
116
157
target_branch, patch_type='bundle',
225
266
body = self.to_signed(branch)
227
268
body = ''.join(self.to_lines())
228
message = EmailMessage(mail_from, mail_to, subject, body)
269
message = email_message.EmailMessage(mail_from, mail_to, subject,
231
273
def install_revisions(self, target_repo):
338
380
:param source_branch: A public location to merge the revision from
339
381
:param message: The message to use when committing this merge
341
_BaseMergeDirective.__init__(self, revision_id, testament_sha1, time,
383
BaseMergeDirective.__init__(self, revision_id, testament_sha1, time,
342
384
timezone, target_branch, patch, source_branch, message)
343
385
if patch_type not in (None, 'diff', 'bundle'):
344
386
raise ValueError(patch_type)
428
470
return None, self.revision_id, 'inapplicable'
431
class MergeDirective2(_BaseMergeDirective):
473
class MergeDirective2(BaseMergeDirective):
433
475
_format_string = 'Bazaar merge directive format 2 (Bazaar 0.90)'
437
479
bundle=None, base_revision_id=None):
438
480
if source_branch is None and bundle is None:
439
481
raise errors.NoMergeSource()
440
_BaseMergeDirective.__init__(self, revision_id, testament_sha1, time,
482
BaseMergeDirective.__init__(self, revision_id, testament_sha1, time,
441
483
timezone, target_branch, patch, source_branch, message)
442
484
self.bundle = bundle
443
485
self.base_revision_id = base_revision_id