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

  • Committer: Jelmer Vernooij
  • Date: 2019-03-05 07:32:38 UTC
  • mto: (7290.1.21 work)
  • mto: This revision was merged to the branch mainline in revision 7311.
  • Revision ID: jelmer@jelmer.uk-20190305073238-zlqn981opwnqsmzi
Add appveyor configuration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
18
 
17
19
import base64
18
 
import contextlib
19
 
from io import BytesIO
20
20
import re
21
21
 
22
22
from . import lazy_import
25
25
    branch as _mod_branch,
26
26
    diff,
27
27
    email_message,
 
28
    errors,
28
29
    gpg,
29
30
    hooks,
30
31
    registry,
36
37
from breezy.bzr import (
37
38
    testament,
38
39
    )
39
 
from breezy.bzr.bundle import (
 
40
from breezy.bundle import (
40
41
    serializer as bundle_serializer,
41
42
    )
42
43
""")
43
 
from . import (
44
 
    errors,
 
44
from .sixish import (
 
45
    BytesIO,
45
46
    )
46
47
 
47
48
 
48
 
class IllegalMergeDirectivePayload(errors.BzrError):
49
 
    """A merge directive contained something other than a patch or bundle"""
50
 
 
51
 
    _fmt = "Bad merge directive payload %(start)r"
52
 
 
53
 
    def __init__(self, start):
54
 
        errors.BzrError(self)
55
 
        self.start = start
56
 
 
57
 
 
58
49
class MergeRequestBodyParams(object):
59
50
    """Parameter object for the merge_request_body hook."""
60
51
 
552
543
                if start.startswith(b'# Begin bundle'):
553
544
                    bundle = b''.join(line_iter)
554
545
                else:
555
 
                    raise IllegalMergeDirectivePayload(start)
 
546
                    raise errors.IllegalMergeDirectivePayload(start)
556
547
        time, timezone = timestamp.parse_patch_date(stanza.get('timestamp'))
557
548
        kwargs = {}
558
549
        for key in ('revision_id', 'testament_sha1', 'target_branch',
605
596
        If the message is not supplied, the message from revision_id will be
606
597
        used for the commit.
607
598
        """
608
 
        with contextlib.ExitStack() as exit_stack:
609
 
            exit_stack.enter_context(repository.lock_write())
 
599
        locked = []
 
600
        try:
 
601
            repository.lock_write()
 
602
            locked.append(repository)
610
603
            t_revision_id = revision_id
611
604
            if revision_id == b'null:':
612
605
                t_revision_id = None
616
609
                submit_branch = _mod_branch.Branch.open(target_branch)
617
610
            else:
618
611
                submit_branch = local_target_branch
619
 
            exit_stack.enter_context(submit_branch.lock_read())
 
612
            submit_branch.lock_read()
 
613
            locked.append(submit_branch)
620
614
            if submit_branch.get_public_branch() is not None:
621
615
                target_branch = submit_branch.get_public_branch()
622
616
            submit_revision_id = submit_branch.last_revision()
642
636
 
643
637
            if public_branch is not None and not include_bundle:
644
638
                public_branch_obj = _mod_branch.Branch.open(public_branch)
645
 
                exit_stack.enter_context(public_branch_obj.lock_read())
 
639
                public_branch_obj.lock_read()
 
640
                locked.append(public_branch_obj)
646
641
                if not public_branch_obj.repository.has_revision(
647
642
                        revision_id):
648
643
                    raise errors.PublicBranchOutOfDate(public_branch,
649
644
                                                       revision_id)
650
645
            testament_sha1 = t.as_sha1()
 
646
        finally:
 
647
            for entry in reversed(locked):
 
648
                entry.unlock()
651
649
        return klass(revision_id, testament_sha1, time, timezone,
652
650
                     target_branch, patch, public_branch, message, bundle,
653
651
                     base_revision_id)