88
81
# is, missing) in both trees are skipped as well.
89
82
if parent == (None, None) or kind == (None, None):
91
path_encoded = (get_encoded_path(paths[0]),
84
path_encoded = (get_encoded_path(paths[0]),
92
85
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]:
86
present = ((kind[0] is not None and versioned[0]),
87
(kind[1] is not None and versioned[1]))
97
88
contents = (get_blob(present[0], trees[0], file_id),
98
89
get_blob(present[1], trees[1], file_id))
99
90
renamed = (parent[0], name[0]) != (parent[1], name[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],
91
mode = (get_file_mode(trees[0], path_encoded[0],
92
kind[0], executable[0]),
93
get_file_mode(trees[1], path_encoded[1],
103
94
kind[1], executable[1]))
104
write_blob_diff(self.to_file,
105
(path_encoded[0], mode[0], contents[0]),
95
write_blob_diff(self.to_file,
96
(path_encoded[0], mode[0], contents[0]),
106
97
(path_encoded[1], mode[1], contents[1]))
107
98
has_changes |= (changed_content or renamed)
108
99
return has_changes
111
class GitMergeDirective(BaseMergeDirective):
113
multiple_output_files = True
115
def __init__(self, revision_id, testament_sha1, time, timezone,
116
target_branch, source_branch=None, message=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
102
class GitMergeDirective(merge_directive._BaseMergeDirective):
124
104
def to_lines(self):
125
105
return self.patch.splitlines(True)
131
108
def _generate_commit(cls, repository, revision_id, num, total):
140
117
tree_1 = repository.revision_tree(lhs_parent)
141
118
tree_2 = repository.revision_tree(revision_id)
142
119
contents = StringIO()
143
differ = GitDiffTree.from_trees_options(tree_1, tree_2,
120
differ = GitDiffTree.from_trees_options(tree_1, tree_2,
144
121
contents, 'utf8', None, 'a/', 'b/', None)
145
122
differ.show_diff(None, None)
146
write_commit_patch(s, commit, contents.getvalue(), (num, total),
123
write_commit_patch(s, commit, contents.getvalue(), (num, total),
148
summary = "%04d-%s.patch" % (num, get_summary(commit).rstrip("."))
125
summary = "%04d-%s" % (num, get_summary(commit))
149
126
return summary, s.getvalue()
162
139
todo = graph.find_difference(submit_revision_id, revision_id)[1]
163
140
total = len(todo)
164
141
for i, revid in enumerate(graph.iter_topo_order(todo)):
165
patches.append(cls._generate_commit(repository, revid, i+1,
142
patches.append(cls._generate_commit(repository, revid, i+1,
168
145
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)
174
def send_git(branch, revision_id, submit_branch, public_branch, no_patch,
175
no_bundle, message, base_revision_id):
177
raise errors.BzrCommandError("no patch not supported for git-am style patches")
179
raise errors.BzrCommandError("no bundle not supported for git-am style patches")
146
return cls(revision_id, None, time, timezone, target_branch,
147
"".join([patch for (summary, patch) in patches]),
148
None, public_branch, message)
151
def send_git(branch, revision_id, submit_branch, public_branch,
152
no_patch, no_bundle, message, base_revision_id):
180
153
return GitMergeDirective.from_objects(
181
154
branch.repository, revision_id, time.time(),
182
155
osutils.local_time_offset(), submit_branch,