~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge_directive.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-17 18:13:57 UTC
  • mfrom: (5268.7.29 transport-segments)
  • Revision ID: pqm@pqm.ubuntu.com-20110817181357-y5q5eth1hk8bl3om
(jelmer) Allow specifying the colocated branch to use in the branch URL,
 and retrieving the branch name using ControlDir._get_selected_branch.
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007-2011 Canonical Ltd
2
2
#
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
18
18
from StringIO import StringIO
19
19
import re
20
20
 
 
21
from bzrlib import lazy_import
 
22
lazy_import.lazy_import(globals(), """
21
23
from bzrlib import (
22
24
    branch as _mod_branch,
23
25
    diff,
 
26
    email_message,
24
27
    errors,
25
28
    gpg,
26
29
    hooks,
34
37
from bzrlib.bundle import (
35
38
    serializer as bundle_serializer,
36
39
    )
37
 
from bzrlib.email_message import EmailMessage
 
40
""")
38
41
 
39
42
 
40
43
class MergeRequestBodyParams(object):
56
59
    """Hooks for MergeDirective classes."""
57
60
 
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))
65
 
 
66
 
 
67
 
class _BaseMergeDirective(object):
 
67
            " provided to the next.", (1, 15, 0))
 
68
 
 
69
 
 
70
class BaseMergeDirective(object):
 
71
    """A request to perform a merge into a branch.
 
72
 
 
73
    This is the base class that all merge directive implementations 
 
74
    should derive from.
 
75
 
 
76
    :cvar multiple_output_files: Whether or not this merge directive 
 
77
        stores a set of revisions in more than one file
 
78
    """
68
79
 
69
80
    hooks = MergeDirectiveHooks()
70
81
 
 
82
    multiple_output_files = False
 
83
 
71
84
    def __init__(self, revision_id, testament_sha1, time, timezone,
72
85
                 target_branch, patch=None, source_branch=None, message=None,
73
86
                 bundle=None):
92
105
        self.source_branch = source_branch
93
106
        self.message = message
94
107
 
 
108
    def to_lines(self):
 
109
        """Serialize as a list of lines
 
110
 
 
111
        :return: a list of lines
 
112
        """
 
113
        raise NotImplementedError(self.to_lines)
 
114
 
 
115
    def to_files(self):
 
116
        """Serialize as a set of files.
 
117
 
 
118
        :return: List of tuples with filename and contents as lines
 
119
        """
 
120
        raise NotImplementedError(self.to_files)
 
121
 
 
122
    def get_raw_bundle(self):
 
123
        """Return the bundle for this merge directive.
 
124
 
 
125
        :return: bundle text or None if there is no bundle
 
126
        """
 
127
        return None
 
128
 
95
129
    def _to_lines(self, base_revision=False):
96
130
        """Serialize as a list of lines
97
131
 
111
145
        lines.append('# \n')
112
146
        return lines
113
147
 
 
148
    def write_to_directory(self, path):
 
149
        """Write this merge directive to a series of files in a directory.
 
150
 
 
151
        :param path: Filesystem path to write to
 
152
        """
 
153
        raise NotImplementedError(self.write_to_directory)
 
154
 
114
155
    @classmethod
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)
226
267
        else:
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,
 
270
            body)
229
271
        return message
230
272
 
231
273
    def install_revisions(self, target_repo):
303
345
                                          basename, body)
304
346
 
305
347
 
306
 
class MergeDirective(_BaseMergeDirective):
 
348
class MergeDirective(BaseMergeDirective):
307
349
 
308
350
    """A request to perform a merge into a branch.
309
351
 
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
340
382
        """
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'
429
471
 
430
472
 
431
 
class MergeDirective2(_BaseMergeDirective):
 
473
class MergeDirective2(BaseMergeDirective):
432
474
 
433
475
    _format_string = 'Bazaar merge directive format 2 (Bazaar 0.90)'
434
476
 
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