/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: Aaron Bentley
  • Date: 2007-03-01 04:14:36 UTC
  • mto: (2323.6.9 0.15-integration)
  • mto: This revision was merged to the branch mainline in revision 2330.
  • Revision ID: aaron.bentley@utoronto.ca-20070301041436-cyfzmqrtau2qs4fk
Get MergeDirective.from_objects working

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from StringIO import StringIO
2
2
 
3
3
from bzrlib import (
 
4
    branch as _mod_branch,
 
5
    diff,
4
6
    errors,
 
7
    revision as _mod_revision,
5
8
    rio,
 
9
    testament,
6
10
    )
7
11
from bzrlib.bundle import serializer as bundle_serializer
8
12
 
69
73
        return lines
70
74
 
71
75
    @classmethod
72
 
    def from_objects(klass, repository, revision_id, submit_location,
73
 
                 patch_type='bundle', local_submit_location=None,
74
 
                 public_location=None):
75
 
        if patch_type == 'bundle':
76
 
            patch = klass._generate_bundle(repository, revision_id,
77
 
                                           submit_location)
78
 
        elif patch_type == 'diff':
79
 
            patch = klass._generate_diff(repository, revision_id,
80
 
                                         submit_location)
 
76
    def from_objects(klass, repository, revision_id, time, timezone,
 
77
                 submit_location, patch_type='bundle',
 
78
                 local_submit_location=None, public_branch=None):
 
79
        if public_branch is not None:
 
80
            public_location = public_branch.base
 
81
            if not public_branch.repository.has_revision(revision_id):
 
82
                raise errors.PublicBranchOutOfDate(public_location,
 
83
                                                   revision_id)
 
84
            else:
 
85
                public_location = None
 
86
        t = testament.StrictTestament3.from_revision(repository, revision_id)
 
87
        if patch_type is None:
 
88
            patch = None
81
89
        else:
82
 
            patch = None
83
 
        return MergeDirective(revision_id, submit_location, patch, patch_type,
84
 
                              public_location)
 
90
            submit_branch = _mod_branch.Branch.open(submit_location)
 
91
            submit_revision_id = submit_branch.last_revision()
 
92
            repository.fetch(submit_branch.repository, submit_revision_id)
 
93
            ancestor_id = _mod_revision.common_ancestor(revision_id,
 
94
                                                        submit_revision_id,
 
95
                                                        repository)
 
96
            if patch_type == 'bundle':
 
97
                s = StringIO()
 
98
                bundle_serializer.write_bundle(repository, revision_id,
 
99
                                               ancestor_id, s)
 
100
                patch = s.getvalue()
 
101
            elif patch_type == 'diff':
 
102
                patch = klass._generate_diff(repository, revision_id,
 
103
                                             ancestor_id)
 
104
        return MergeDirective(revision_id, t.as_sha1(), time, timezone,
 
105
                              submit_location, patch, patch_type,
 
106
                              public_branch)
 
107
 
 
108
    @staticmethod
 
109
    def _generate_diff(repository, revision_id, ancestor_id):
 
110
        tree_1 = repository.revision_tree(ancestor_id)
 
111
        tree_2 = repository.revision_tree(revision_id)
 
112
        s = StringIO()
 
113
        diff.show_diff_trees(tree_1, tree_2, s)
 
114
        return s.getvalue()