45
44
ud = difflib.unified_diff(oldlines, newlines,
46
45
fromfile=old_label, tofile=new_label)
48
48
# work-around for difflib being too smart for its own good
49
49
# if /dev/null is "1,0", patch won't recognize it as /dev/null
52
51
ud[2] = ud[2].replace('-1,0', '-0,0')
55
53
ud[2] = ud[2].replace('+1,0', '+0,0')
54
# work around for difflib emitting random spaces after the label
55
ud[0] = ud[0][:-2] + '\n'
56
ud[1] = ud[1][:-2] + '\n'
58
59
to_file.write(line)
155
153
The more general form is show_diff_trees(), where the caller
156
154
supplies any two trees.
161
161
old_tree = b.basis_tree()
163
old_tree = b.revision_tree(b.lookup_revision(revision))
165
new_tree = b.working_tree()
167
show_diff_trees(old_tree, new_tree, sys.stdout, specific_files,
163
old_tree = b.revision_tree(revision.in_history(b).rev_id)
165
if revision2 is None:
166
new_tree = b.working_tree()
168
new_tree = b.revision_tree(revision2.in_history(b).rev_id)
170
show_diff_trees(old_tree, new_tree, output, specific_files,
168
171
external_diff_options)
205
208
specific_files=specific_files)
207
210
for path, file_id, kind in delta.removed:
208
print >>to_file, '*** removed %s %r' % (kind, path)
211
print >>to_file, '=== removed %s %r' % (kind, path)
209
212
if kind == 'file':
210
213
diff_file(old_label + path,
211
214
old_tree.get_file(file_id).readlines(),
216
218
for path, file_id, kind in delta.added:
217
print >>to_file, '*** added %s %r' % (kind, path)
219
print >>to_file, '=== added %s %r' % (kind, path)
218
220
if kind == 'file':
219
221
diff_file(DEVNULL,
221
223
new_label + path,
222
224
new_tree.get_file(file_id).readlines(),
225
226
for old_path, new_path, file_id, kind, text_modified in delta.renamed:
226
print >>to_file, '*** renamed %s %r => %r' % (kind, old_path, new_path)
227
print >>to_file, '=== renamed %s %r => %r' % (kind, old_path, new_path)
228
_maybe_diff_file_or_symlink(old_label, old_path, old_tree, file_id,
229
new_label, new_path, new_tree,
230
text_modified, kind, to_file, diff_file)
231
for path, file_id, kind in delta.modified:
232
print >>to_file, '=== modified %s %r' % (kind, path)
233
_maybe_diff_file_or_symlink(old_label, path, old_tree, file_id,
234
new_label, path, new_tree,
235
True, kind, to_file, diff_file)
238
def _maybe_diff_file_or_symlink(old_label, old_path, old_tree, file_id,
239
new_label, new_path, new_tree, text_modified,
240
kind, to_file, diff_file):
228
243
diff_file(old_label + old_path,
229
244
old_tree.get_file(file_id).readlines(),
230
245
new_label + new_path,
231
246
new_tree.get_file(file_id).readlines(),
234
for path, file_id, kind in delta.modified:
235
print >>to_file, '*** modified %s %r' % (kind, path)
237
diff_file(old_label + path,
238
old_tree.get_file(file_id).readlines(),
240
new_tree.get_file(file_id).readlines(),
248
elif kind == 'symlink':
249
_diff_symlink(old_tree, new_tree, file_id, to_file)
251
def _diff_symlink(old_tree, new_tree, file_id, to_file):
252
t1 = old_tree.get_symlink_target(file_id)
253
t2 = new_tree.get_symlink_target(file_id)
254
print >>to_file, '=== target changed %r => %r' % (t1, t2)