/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 send.py

More work on roundtrip push support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    branch as _mod_branch,
27
27
    diff as _mod_diff,
28
28
    errors,
29
 
    merge_directive,
30
29
    osutils,
31
30
    revision as _mod_revision,
32
31
    )
33
32
 
 
33
try:
 
34
    from bzrlib.merge_directive import BaseMergeDirective
 
35
except ImportError:
 
36
    from bzrlib.merge_directive import (
 
37
        _BaseMergeDirective as BaseMergeDirective,
 
38
        )
 
39
 
34
40
from bzrlib.plugins.git import (
35
41
    version_info as bzr_git_version_info,
36
42
    )
68
74
                return path.encode(self.path_encoding, "replace")
69
75
        def get_file_mode(tree, path, kind, executable):
70
76
            if path is None:
71
 
                return None
 
77
                return 0
72
78
            return object_mode(kind, executable)
73
79
        def get_blob(present, tree, file_id):
74
 
            if present is not None:
 
80
            if present:
75
81
                return Blob.from_string(tree.get_file(file_id).read())
76
82
            else:
77
83
                return None
82
88
            # is, missing) in both trees are skipped as well.
83
89
            if parent == (None, None) or kind == (None, None):
84
90
                continue
85
 
            path_encoded = (get_encoded_path(paths[0]), 
 
91
            path_encoded = (get_encoded_path(paths[0]),
86
92
                            get_encoded_path(paths[1]))
87
 
            present = ((kind[0] is not None and versioned[0]),
88
 
                       (kind[1] is not None and versioned[1]))
 
93
            present = ((kind[0] not in (None, 'directory')),
 
94
                       (kind[1] not in (None, 'directory')))
 
95
            if not present[0] and not present[1]:
 
96
                continue
89
97
            contents = (get_blob(present[0], trees[0], file_id),
90
98
                        get_blob(present[1], trees[1], file_id))
91
99
            renamed = (parent[0], name[0]) != (parent[1], name[1])
92
 
            mode = (get_file_mode(trees[0], path_encoded[0], 
93
 
                                  kind[0], executable[0]), 
94
 
                    get_file_mode(trees[1], path_encoded[1], 
 
100
            mode = (get_file_mode(trees[0], path_encoded[0],
 
101
                                  kind[0], executable[0]),
 
102
                    get_file_mode(trees[1], path_encoded[1],
95
103
                                  kind[1], executable[1]))
96
 
            write_blob_diff(self.to_file, 
97
 
                (path_encoded[0], mode[0], contents[0]), 
 
104
            write_blob_diff(self.to_file,
 
105
                (path_encoded[0], mode[0], contents[0]),
98
106
                (path_encoded[1], mode[1], contents[1]))
99
107
            has_changes |= (changed_content or renamed)
100
108
        return has_changes
101
109
 
102
110
 
103
 
class GitMergeDirective(merge_directive._BaseMergeDirective):
 
111
class GitMergeDirective(BaseMergeDirective):
 
112
 
 
113
    multiple_output_files = True
 
114
 
 
115
    def __init__(self, revision_id, testament_sha1, time, timezone,
 
116
                 target_branch, source_branch=None, message=None,
 
117
                 patches=None):
 
118
        super(GitMergeDirective, self).__init__(revision_id=revision_id,
 
119
            testament_sha1=testament_sha1, time=time, timezone=timezone,
 
120
            target_branch=target_branch, patch=None,
 
121
            source_branch=source_branch, message=message, bundle=None)
 
122
        self.patches = patches
104
123
 
105
124
    def to_lines(self):
106
125
        return self.patch.splitlines(True)
107
126
 
 
127
    def to_files(self):
 
128
        return self.patches
 
129
 
108
130
    @classmethod
109
131
    def _generate_commit(cls, repository, revision_id, num, total):
110
132
        s = StringIO()
118
140
        tree_1 = repository.revision_tree(lhs_parent)
119
141
        tree_2 = repository.revision_tree(revision_id)
120
142
        contents = StringIO()
121
 
        differ = GitDiffTree.from_trees_options(tree_1, tree_2, 
 
143
        differ = GitDiffTree.from_trees_options(tree_1, tree_2,
122
144
                contents, 'utf8', None, 'a/', 'b/', None)
123
145
        differ.show_diff(None, None)
124
 
        write_commit_patch(s, commit, contents.getvalue(), (num, total), 
 
146
        write_commit_patch(s, commit, contents.getvalue(), (num, total),
125
147
                           version_tail)
126
 
        summary = "%04d-%s" % (num, get_summary(commit))
 
148
        summary = "%04d-%s.patch" % (num, get_summary(commit).rstrip("."))
127
149
        return summary, s.getvalue()
128
150
 
129
151
    @classmethod
140
162
            todo = graph.find_difference(submit_revision_id, revision_id)[1]
141
163
            total = len(todo)
142
164
            for i, revid in enumerate(graph.iter_topo_order(todo)):
143
 
                patches.append(cls._generate_commit(repository, revid, i+1, 
144
 
                                                    total))
 
165
                patches.append(cls._generate_commit(repository, revid, i+1,
 
166
                    total))
145
167
        finally:
146
168
            submit_branch.unlock()
147
 
        return cls(revision_id, None, time, timezone, target_branch, 
148
 
            "".join([patch for (summary, patch) in patches]), 
149
 
            None, public_branch, message)
150
 
 
151
 
 
152
 
def send_git(branch, revision_id, submit_branch, public_branch, no_patch, 
 
169
        return cls(revision_id, None, time, timezone,
 
170
            target_branch=target_branch, source_branch=public_branch,
 
171
            message=message, patches=patches)
 
172
 
 
173
 
 
174
def send_git(branch, revision_id, submit_branch, public_branch, no_patch,
153
175
             no_bundle, message, base_revision_id):
154
176
    if no_patch:
155
177
        raise errors.BzrCommandError("no patch not supported for git-am style patches")