70
def external_diff(old_label, oldlines, new_label, newlines, to_file):
70
def external_diff(old_label, oldlines, new_label, newlines, to_file,
71
72
"""Display a diff by calling out to the external diff program."""
98
system('diff -u --label %s %s --label %s %s' % (old_label, oldtmpf.name, new_label, newtmpf.name))
102
'--label', old_label,
104
'--label', new_label,
107
# diff only allows one style to be specified; they don't override.
108
# note that some of these take optargs, and the optargs can be
109
# directly appended to the options.
110
# this is only an approximate parser; it doesn't properly understand
112
for s in ['-c', '-u', '-C', '-U',
117
'-y', '--side-by-side',
129
diffcmd.extend(diff_opts)
131
rc = os.spawnvp(os.P_WAIT, 'diff', diffcmd)
133
if rc != 0 and rc != 1:
134
# returns 1 if files differ; that's OK
136
msg = 'signal %d' % (-rc)
138
msg = 'exit code %d' % rc
140
raise BzrError('external diff failed with %s; command: %r' % (rc, diffcmd))
100
142
oldtmpf.close() # and delete
105
def diff_file(old_label, oldlines, new_label, newlines, to_file):
107
differ = external_diff
109
differ = internal_diff
111
differ(old_label, oldlines, new_label, newlines, to_file)
115
def show_diff(b, revision, specific_files):
147
def show_diff(b, revision, specific_files, external_diff_options=None):
118
150
if revision == None:
123
155
new_tree = b.working_tree()
125
show_diff_trees(old_tree, new_tree, sys.stdout, specific_files)
129
def show_diff_trees(old_tree, new_tree, to_file, specific_files=None):
157
show_diff_trees(old_tree, new_tree, sys.stdout, specific_files,
158
external_diff_options)
162
def show_diff_trees(old_tree, new_tree, to_file, specific_files=None,
163
external_diff_options=None):
130
164
"""Show in text form the changes from one tree to another.
133
167
If set, include only changes to these files.
169
external_diff_options
170
If set, use an external GNU diff and pass these options.
136
173
# TODO: Options to control putting on a prefix or suffix, perhaps as a format string
145
182
# TODO: Generation of pseudo-diffs for added/deleted files could
146
183
# be usefully made into a much faster special case.
185
if external_diff_options:
186
assert isinstance(external_diff_options, basestring)
187
opts = external_diff_options.split()
188
def diff_file(olab, olines, nlab, nlines, to_file):
189
external_diff(olab, olines, nlab, nlines, to_file, opts)
191
diff_file = internal_diff
148
194
delta = compare_trees(old_tree, new_tree, want_unchanged=False,
149
195
specific_files=specific_files)