/breezy/unstable

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy/unstable

« back to all changes in this revision

Viewing changes to breezy/merge_directive.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-24 01:39:33 UTC
  • mfrom: (3815.3776.6)
  • Revision ID: jelmer@jelmer.uk-20170524013933-ir4y4tqtrsiz2ka2
New upstream snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
from __future__ import absolute_import
18
18
 
19
 
from StringIO import StringIO
20
19
import re
21
20
 
22
 
from bzrlib import lazy_import
 
21
from . import lazy_import
23
22
lazy_import.lazy_import(globals(), """
24
 
from bzrlib import (
 
23
from breezy import (
25
24
    branch as _mod_branch,
26
25
    diff,
27
26
    email_message,
35
34
    timestamp,
36
35
    trace,
37
36
    )
38
 
from bzrlib.bundle import (
 
37
from breezy.bundle import (
39
38
    serializer as bundle_serializer,
40
39
    )
41
40
""")
 
41
from .sixish import (
 
42
    BytesIO,
 
43
    )
42
44
 
43
45
 
44
46
class MergeRequestBodyParams(object):
60
62
    """Hooks for MergeDirective classes."""
61
63
 
62
64
    def __init__(self):
63
 
        hooks.Hooks.__init__(self, "bzrlib.merge_directive", "BaseMergeDirective.hooks")
 
65
        hooks.Hooks.__init__(self, "breezy.merge_directive", "BaseMergeDirective.hooks")
64
66
        self.add_hook('merge_request_body',
65
67
            "Called with a MergeRequestBodyParams when a body is needed for"
66
68
            " a merge request.  Callbacks must return a body.  If more"
231
233
    def _generate_diff(repository, revision_id, ancestor_id):
232
234
        tree_1 = repository.revision_tree(ancestor_id)
233
235
        tree_2 = repository.revision_tree(revision_id)
234
 
        s = StringIO()
 
236
        s = BytesIO()
235
237
        diff.show_diff_trees(tree_1, tree_2, s, old_label='', new_label='')
236
238
        return s.getvalue()
237
239
 
238
240
    @staticmethod
239
241
    def _generate_bundle(repository, revision_id, ancestor_id):
240
 
        s = StringIO()
 
242
        s = BytesIO()
241
243
        bundle_serializer.write_bundle(repository, revision_id,
242
244
                                       ancestor_id, s)
243
245
        return s.getvalue()
279
281
        if not target_repo.has_revision(self.revision_id):
280
282
            if self.patch_type == 'bundle':
281
283
                info = bundle_serializer.read_bundle(
282
 
                    StringIO(self.get_raw_bundle()))
 
284
                    BytesIO(self.get_raw_bundle()))
283
285
                # We don't use the bundle's target revision, because
284
286
                # MergeDirective.revision_id is authoritative.
285
287
                try:
435
437
        else:
436
438
            patch = ''.join(patch_lines)
437
439
            try:
438
 
                bundle_serializer.read_bundle(StringIO(patch))
 
440
                bundle_serializer.read_bundle(BytesIO(patch))
439
441
            except (errors.NotABundle, errors.BundleNotSupported,
440
442
                    errors.BadBundle):
441
443
                patch_type = 'diff'
461
463
 
462
464
    @staticmethod
463
465
    def _generate_bundle(repository, revision_id, ancestor_id):
464
 
        s = StringIO()
 
466
        s = BytesIO()
465
467
        bundle_serializer.write_bundle(repository, revision_id,
466
468
                                       ancestor_id, s, '0.9')
467
469
        return s.getvalue()