/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

Add helper function, always set encoding to utf-8.

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,
29
30
    osutils,
30
31
    revision as _mod_revision,
31
32
    )
32
33
 
33
 
try:
34
 
    from bzrlib.merge_directive import BaseMergeDirective
35
 
except ImportError:
36
 
    from bzrlib.merge_directive import (
37
 
        _BaseMergeDirective as BaseMergeDirective,
38
 
        )
39
 
 
40
34
from bzrlib.plugins.git import (
41
35
    version_info as bzr_git_version_info,
42
36
    )
74
68
                return path.encode(self.path_encoding, "replace")
75
69
        def get_file_mode(tree, path, kind, executable):
76
70
            if path is None:
77
 
                return 0
 
71
                return None
78
72
            return object_mode(kind, executable)
79
73
        def get_blob(present, tree, file_id):
80
 
            if present:
 
74
            if present is not None:
81
75
                return Blob.from_string(tree.get_file(file_id).read())
82
76
            else:
83
77
                return None
90
84
                continue
91
85
            path_encoded = (get_encoded_path(paths[0]),
92
86
                            get_encoded_path(paths[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
 
87
            present = ((kind[0] is not None and versioned[0]),
 
88
                       (kind[1] is not None and versioned[1]))
97
89
            contents = (get_blob(present[0], trees[0], file_id),
98
90
                        get_blob(present[1], trees[1], file_id))
99
91
            renamed = (parent[0], name[0]) != (parent[1], name[1])
108
100
        return has_changes
109
101
 
110
102
 
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
 
103
class GitMergeDirective(merge_directive._BaseMergeDirective):
123
104
 
124
105
    def to_lines(self):
125
106
        return self.patch.splitlines(True)
126
107
 
127
 
    def to_files(self):
128
 
        return self.patches
129
 
 
130
108
    @classmethod
131
109
    def _generate_commit(cls, repository, revision_id, num, total):
132
110
        s = StringIO()
145
123
        differ.show_diff(None, None)
146
124
        write_commit_patch(s, commit, contents.getvalue(), (num, total),
147
125
                           version_tail)
148
 
        summary = "%04d-%s.patch" % (num, get_summary(commit).rstrip("."))
 
126
        summary = "%04d-%s" % (num, get_summary(commit))
149
127
        return summary, s.getvalue()
150
128
 
151
129
    @classmethod
163
141
            total = len(todo)
164
142
            for i, revid in enumerate(graph.iter_topo_order(todo)):
165
143
                patches.append(cls._generate_commit(repository, revid, i+1,
166
 
                    total))
 
144
                                                    total))
167
145
        finally:
168
146
            submit_branch.unlock()
169
 
        return cls(revision_id, None, time, timezone,
170
 
            target_branch=target_branch, source_branch=public_branch,
171
 
            message=message, patches=patches)
 
147
        return cls(revision_id, None, time, timezone, target_branch,
 
148
            "".join([patch for (summary, patch) in patches]),
 
149
            None, public_branch, message)
172
150
 
173
151
 
174
152
def send_git(branch, revision_id, submit_branch, public_branch, no_patch,