~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge_directive.py

  • Committer: Martin Pool
  • Date: 2008-12-16 07:56:29 UTC
  • mto: (3882.7.11 progress)
  • mto: This revision was merged to the branch mainline in revision 3940.
  • Revision ID: mbp@sourcefrog.net-20081216075629-zhgjzxgoh32453tu
Choose the UIFactory class depending on the terminal capabilities

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
18
from StringIO import StringIO
23
23
    diff,
24
24
    errors,
25
25
    gpg,
26
 
    hooks,
27
26
    registry,
28
27
    revision as _mod_revision,
29
28
    rio,
30
29
    testament,
31
30
    timestamp,
32
 
    trace,
33
31
    )
34
32
from bzrlib.bundle import (
35
33
    serializer as bundle_serializer,
37
35
from bzrlib.email_message import EmailMessage
38
36
 
39
37
 
40
 
class MergeRequestBodyParams(object):
41
 
    """Parameter object for the merge_request_body hook."""
42
 
 
43
 
    def __init__(self, body, orig_body, directive, to, basename, subject,
44
 
                 branch, tree=None):
45
 
        self.body = body
46
 
        self.orig_body = orig_body
47
 
        self.directive = directive
48
 
        self.branch = branch
49
 
        self.tree = tree
50
 
        self.to = to
51
 
        self.basename = basename
52
 
        self.subject = subject
53
 
 
54
 
 
55
 
class MergeDirectiveHooks(hooks.Hooks):
56
 
    """Hooks for MergeDirective classes."""
57
 
 
58
 
    def __init__(self):
59
 
        hooks.Hooks.__init__(self)
60
 
        self.create_hook(hooks.HookPoint('merge_request_body',
61
 
            "Called with a MergeRequestBodyParams when a body is needed for"
62
 
            " a merge request.  Callbacks must return a body.  If more"
63
 
            " than one callback is registered, the output of one callback is"
64
 
            " provided to the next.", (1, 15, 0), False))
65
 
 
66
 
 
67
38
class _BaseMergeDirective(object):
68
39
 
69
 
    hooks = MergeDirectiveHooks()
70
 
 
71
40
    def __init__(self, revision_id, testament_sha1, time, timezone,
72
41
                 target_branch, patch=None, source_branch=None, message=None,
73
42
                 bundle=None):
271
240
                target_repo.fetch(source_branch.repository, self.revision_id)
272
241
        return self.revision_id
273
242
 
274
 
    def compose_merge_request(self, mail_client, to, body, branch, tree=None):
275
 
        """Compose a request to merge this directive.
276
 
 
277
 
        :param mail_client: The mail client to use for composing this request.
278
 
        :param to: The address to compose the request to.
279
 
        :param branch: The Branch that was used to produce this directive.
280
 
        :param tree: The Tree (if any) for the Branch used to produce this
281
 
            directive.
282
 
        """
283
 
        basename = self.get_disk_name(branch)
284
 
        subject = '[MERGE] '
285
 
        if self.message is not None:
286
 
            subject += self.message
287
 
        else:
288
 
            revision = branch.repository.get_revision(self.revision_id)
289
 
            subject += revision.get_summary()
290
 
        if getattr(mail_client, 'supports_body', False):
291
 
            orig_body = body
292
 
            for hook in self.hooks['merge_request_body']:
293
 
                params = MergeRequestBodyParams(body, orig_body, self,
294
 
                                                to, basename, subject, branch,
295
 
                                                tree)
296
 
                body = hook(params)
297
 
        elif len(self.hooks['merge_request_body']) > 0:
298
 
            trace.warning('Cannot run merge_request_body hooks because mail'
299
 
                          ' client %s does not support message bodies.',
300
 
                        mail_client.__class__.__name__)
301
 
        mail_client.compose_merge_request(to, subject,
302
 
                                          ''.join(self.to_lines()),
303
 
                                          basename, body)
304
 
 
305
243
 
306
244
class MergeDirective(_BaseMergeDirective):
307
245
 
628
566
_format_registry = MergeDirectiveFormatRegistry()
629
567
_format_registry.register(MergeDirective)
630
568
_format_registry.register(MergeDirective2)
631
 
# 0.19 never existed.  It got renamed to 0.90.  But by that point, there were
632
 
# already merge directives in the wild that used 0.19. Registering with the old
633
 
# format string to retain compatibility with those merge directives.
634
569
_format_registry.register(MergeDirective2,
635
570
                          'Bazaar merge directive format 2 (Bazaar 0.19)')