/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 bzrlib/merge_directive.py

  • Committer: Vincent Ladeuil
  • Date: 2012-01-18 14:09:19 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120118140919-rlvdrhpc0nq1lbwi
Change set/remove to require a lock for the branch config files.

This means that tests (or any plugin for that matter) do not requires an
explicit lock on the branch anymore to change a single option. This also
means the optimisation becomes "opt-in" and as such won't be as
spectacular as it may be and/or harder to get right (nothing fails
anymore).

This reduces the diff by ~300 lines.

Code/tests that were updating more than one config option is still taking
a lock to at least avoid some IOs and demonstrate the benefits through
the decreased number of hpss calls.

The duplication between BranchStack and BranchOnlyStack will be removed
once the same sharing is in place for local config files, at which point
the Stack class itself may be able to host the changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 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
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from __future__ import absolute_import
17
18
 
18
19
from StringIO import StringIO
19
20
import re
20
21
 
 
22
from bzrlib import lazy_import
 
23
lazy_import.lazy_import(globals(), """
21
24
from bzrlib import (
22
25
    branch as _mod_branch,
23
26
    diff,
 
27
    email_message,
24
28
    errors,
25
29
    gpg,
26
30
    hooks,
34
38
from bzrlib.bundle import (
35
39
    serializer as bundle_serializer,
36
40
    )
37
 
from bzrlib.email_message import EmailMessage
 
41
""")
38
42
 
39
43
 
40
44
class MergeRequestBodyParams(object):
56
60
    """Hooks for MergeDirective classes."""
57
61
 
58
62
    def __init__(self):
59
 
        hooks.Hooks.__init__(self)
60
 
        self.create_hook(hooks.HookPoint('merge_request_body',
 
63
        hooks.Hooks.__init__(self, "bzrlib.merge_directive", "BaseMergeDirective.hooks")
 
64
        self.add_hook('merge_request_body',
61
65
            "Called with a MergeRequestBodyParams when a body is needed for"
62
66
            " a merge request.  Callbacks must return a body.  If more"
63
67
            " than one callback is registered, the output of one callback is"
64
 
            " provided to the next.", (1, 15, 0), False))
 
68
            " provided to the next.", (1, 15, 0))
65
69
 
66
70
 
67
71
class BaseMergeDirective(object):
79
83
    multiple_output_files = False
80
84
 
81
85
    def __init__(self, revision_id, testament_sha1, time, timezone,
82
 
                 target_branch, patch=None, source_branch=None, message=None,
83
 
                 bundle=None):
 
86
                 target_branch, patch=None, source_branch=None,
 
87
                 message=None, bundle=None):
84
88
        """Constructor.
85
89
 
86
90
        :param revision_id: The revision to merge
88
92
            merge.
89
93
        :param time: The current POSIX timestamp time
90
94
        :param timezone: The timezone offset
91
 
        :param target_branch: The branch to apply the merge to
 
95
        :param target_branch: Location of branch to apply the merge to
92
96
        :param patch: The text of a diff or bundle
93
97
        :param source_branch: A public location to merge the revision from
94
98
        :param message: The message to use when committing this merge
162
166
        :param target_branch: The url of the branch to merge into
163
167
        :param patch_type: 'bundle', 'diff' or None, depending on the type of
164
168
            patch desired.
165
 
        :param local_target_branch: a local copy of the target branch
166
 
        :param public_branch: location of a public branch containing the target
167
 
            revision.
 
169
        :param local_target_branch: the submit branch, either itself or a local copy
 
170
        :param public_branch: location of a public branch containing
 
171
            the target revision.
168
172
        :param message: Message to use when committing the merge
169
173
        :return: The merge directive
170
174
 
178
182
        if revision_id == _mod_revision.NULL_REVISION:
179
183
            t_revision_id = None
180
184
        t = testament.StrictTestament3.from_revision(repository, t_revision_id)
181
 
        submit_branch = _mod_branch.Branch.open(target_branch)
 
185
        if local_target_branch is None:
 
186
            submit_branch = _mod_branch.Branch.open(target_branch)
 
187
        else:
 
188
            submit_branch = local_target_branch
182
189
        if submit_branch.get_public_branch() is not None:
183
190
            target_branch = submit_branch.get_public_branch()
184
191
        if patch_type is None:
241
248
        :param branch: The source branch, to get the signing strategy
242
249
        :return: a string
243
250
        """
244
 
        my_gpg = gpg.GPGStrategy(branch.get_config())
 
251
        my_gpg = gpg.GPGStrategy(branch.get_config_stack())
245
252
        return my_gpg.sign(''.join(self.to_lines()))
246
253
 
247
254
    def to_email(self, mail_to, branch, sign=False):
263
270
            body = self.to_signed(branch)
264
271
        else:
265
272
            body = ''.join(self.to_lines())
266
 
        message = EmailMessage(mail_from, mail_to, subject, body)
 
273
        message = email_message.EmailMessage(mail_from, mail_to, subject,
 
274
            body)
267
275
        return message
268
276
 
269
277
    def install_revisions(self, target_repo):
369
377
            merge.
370
378
        :param time: The current POSIX timestamp time
371
379
        :param timezone: The timezone offset
372
 
        :param target_branch: The branch to apply the merge to
 
380
        :param target_branch: Location of the branch to apply the merge to
373
381
        :param patch: The text of a diff or bundle
374
382
        :param patch_type: None, "diff" or "bundle", depending on the contents
375
383
            of patch
563
571
        :param target_branch: The url of the branch to merge into
564
572
        :param include_patch: If true, include a preview patch
565
573
        :param include_bundle: If true, include a bundle
566
 
        :param local_target_branch: a local copy of the target branch
567
 
        :param public_branch: location of a public branch containing the target
568
 
            revision.
 
574
        :param local_target_branch: the target branch, either itself or a local copy
 
575
        :param public_branch: location of a public branch containing
 
576
            the target revision.
569
577
        :param message: Message to use when committing the merge
570
578
        :return: The merge directive
571
579
 
584
592
                t_revision_id = None
585
593
            t = testament.StrictTestament3.from_revision(repository,
586
594
                t_revision_id)
587
 
            submit_branch = _mod_branch.Branch.open(target_branch)
 
595
            if local_target_branch is None:
 
596
                submit_branch = _mod_branch.Branch.open(target_branch)
 
597
            else:
 
598
                submit_branch = local_target_branch
588
599
            submit_branch.lock_read()
589
600
            locked.append(submit_branch)
590
601
            if submit_branch.get_public_branch() is not None: