1
*** modified file 'bzrlib/commands.py'
8
- takes_options = ['revision', 'diff-options']
9
+ takes_options = ['revision', 'diff-options', 'ndiff']
10
aliases = ['di', 'dif']
12
- def run(self, revision=None, file_list=None, diff_options=None):
13
+ def run(self, revision=None, file_list=None, diff_options=None,
15
from bzrlib.diff import show_diff
29
show_diff(b, revision, specific_files=file_list,
30
- external_diff_options=diff_options)
31
+ external_diff_options=diff_options,
43
'revision': _parse_revision_str,
45
*** modified file 'bzrlib/diff.py'
53
+def internal_ndiff(old_label, oldlines,
54
+ new_label, newlines,
56
+ """Show diff in python-specific ndiff format."""
57
+ from difflib import ndiff
58
+ to_file.writelines(ndiff(oldlines, newlines))
61
def external_diff(old_label, oldlines, new_label, newlines, to_file,
66
-def show_diff(b, revision, specific_files, external_diff_options=None):
67
+def show_diff(b, revision, specific_files, external_diff_options=None,
69
"""Shortcut for showing the diff to the working tree.
75
None for each, or otherwise the old revision to compare against.
78
+ 'unified', 'context', 'ndiff', 'external'
80
The more general form is show_diff_trees(), where the caller
81
supplies any two trees.
83
new_tree = b.working_tree()
85
show_diff_trees(old_tree, new_tree, sys.stdout, specific_files,
86
- external_diff_options)
87
+ external_diff_options, format)
91
def show_diff_trees(old_tree, new_tree, to_file, specific_files=None,
92
- external_diff_options=None):
93
+ external_diff_options=None,
95
"""Show in text form the changes from one tree to another.
99
if external_diff_options:
100
assert isinstance(external_diff_options, basestring)
101
opts = external_diff_options.split()
102
- def diff_file(olab, olines, nlab, nlines, to_file):
103
+ def diff_fn(olab, olines, nlab, nlines, to_file):
104
external_diff(olab, olines, nlab, nlines, to_file, opts)
105
+ elif format == 'ndiff':
106
+ diff_fn = internal_ndiff
108
- diff_file = internal_diff
109
+ diff_fn = internal_diff
112
delta = compare_trees(old_tree, new_tree, want_unchanged=False,
114
for path, file_id, kind in delta.removed:
115
print >>to_file, '*** removed %s %r' % (kind, path)
117
- diff_file(old_label + path,
118
+ diff_fn(old_label + path,
119
old_tree.get_file(file_id).readlines(),
123
for path, file_id, kind in delta.added:
124
print >>to_file, '*** added %s %r' % (kind, path)
130
new_tree.get_file(file_id).readlines(),
132
for old_path, new_path, file_id, kind, text_modified in delta.renamed:
133
print >>to_file, '*** renamed %s %r => %r' % (kind, old_path, new_path)
135
- diff_file(old_label + old_path,
136
+ diff_fn(old_label + old_path,
137
old_tree.get_file(file_id).readlines(),
138
new_label + new_path,
139
new_tree.get_file(file_id).readlines(),
141
for path, file_id, kind in delta.modified:
142
print >>to_file, '*** modified %s %r' % (kind, path)
144
- diff_file(old_label + path,
145
+ diff_fn(old_label + path,
146
old_tree.get_file(file_id).readlines(),
148
new_tree.get_file(file_id).readlines(),