1
# Copyright (C) 2007-2011 Canonical Ltd
1
# Copyright (C) 2007 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
37
34
from bzrlib.bundle import (
38
35
serializer as bundle_serializer,
37
from bzrlib.email_message import EmailMessage
43
40
class MergeRequestBodyParams(object):
59
56
"""Hooks for MergeDirective classes."""
61
58
def __init__(self):
62
hooks.Hooks.__init__(self, "bzrlib.merge_directive", "BaseMergeDirective.hooks")
63
self.add_hook('merge_request_body',
59
hooks.Hooks.__init__(self)
60
self.create_hook(hooks.HookPoint('merge_request_body',
64
61
"Called with a MergeRequestBodyParams when a body is needed for"
65
62
" a merge request. Callbacks must return a body. If more"
66
63
" than one callback is registered, the output of one callback is"
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
64
" provided to the next.", (1, 15, 0), False))
67
class _BaseMergeDirective(object):
80
69
hooks = MergeDirectiveHooks()
82
multiple_output_files = False
84
71
def __init__(self, revision_id, testament_sha1, time, timezone,
85
72
target_branch, patch=None, source_branch=None, message=None,
105
92
self.source_branch = source_branch
106
93
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
129
95
def _to_lines(self, base_revision=False):
130
96
"""Serialize as a list of lines
145
111
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)
156
115
def from_objects(klass, repository, revision_id, time, timezone,
157
116
target_branch, patch_type='bundle',
266
225
body = self.to_signed(branch)
268
227
body = ''.join(self.to_lines())
269
message = email_message.EmailMessage(mail_from, mail_to, subject,
228
message = EmailMessage(mail_from, mail_to, subject, body)
273
231
def install_revisions(self, target_repo):
380
338
:param source_branch: A public location to merge the revision from
381
339
:param message: The message to use when committing this merge
383
BaseMergeDirective.__init__(self, revision_id, testament_sha1, time,
341
_BaseMergeDirective.__init__(self, revision_id, testament_sha1, time,
384
342
timezone, target_branch, patch, source_branch, message)
385
343
if patch_type not in (None, 'diff', 'bundle'):
386
344
raise ValueError(patch_type)
470
428
return None, self.revision_id, 'inapplicable'
473
class MergeDirective2(BaseMergeDirective):
431
class MergeDirective2(_BaseMergeDirective):
475
433
_format_string = 'Bazaar merge directive format 2 (Bazaar 0.90)'
479
437
bundle=None, base_revision_id=None):
480
438
if source_branch is None and bundle is None:
481
439
raise errors.NoMergeSource()
482
BaseMergeDirective.__init__(self, revision_id, testament_sha1, time,
440
_BaseMergeDirective.__init__(self, revision_id, testament_sha1, time,
483
441
timezone, target_branch, patch, source_branch, message)
484
442
self.bundle = bundle
485
443
self.base_revision_id = base_revision_id