14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
from bzrlib.trace import mutter
18
from bzrlib.errors import BzrError
17
19
from bzrlib.delta import compare_trees
18
from bzrlib.errors import BzrError
19
from bzrlib.symbol_versioning import *
20
from bzrlib.trace import mutter
22
21
# TODO: Rather than building a changeset object, we should probably
23
22
# invoke callbacks on an object. That object can either accumulate a
142
141
oldtmpf.close() # and delete
146
@deprecated_function(zero_eight)
147
144
def show_diff(b, from_spec, specific_files, external_diff_options=None,
148
145
revision2=None, output=None, b2=None):
149
146
"""Shortcut for showing the diff to the working tree.
151
Please use show_diff_trees instead.
164
159
output = sys.stdout
166
161
if from_spec is None:
167
old_tree = b.bzrdir.open_workingtree()
169
old_tree = old_tree = old_tree.basis_tree()
163
old_tree = b.basis_tree()
165
old_tree = b.working_tree()
171
old_tree = b.repository.revision_tree(from_spec.in_history(b).rev_id)
167
old_tree = b.revision_tree(from_spec.in_history(b).rev_id)
173
169
if revision2 is None:
175
new_tree = b.bzrdir.open_workingtree()
171
new_tree = b.working_tree()
177
new_tree = b2.bzrdir.open_workingtree()
173
new_tree = b2.working_tree()
179
new_tree = b.repository.revision_tree(revision2.in_history(b).rev_id)
175
new_tree = b.revision_tree(revision2.in_history(b).rev_id)
181
177
return show_diff_trees(old_tree, new_tree, output, specific_files,
182
178
external_diff_options)
185
def diff_cmd_helper(tree, specific_files, external_diff_options,
186
old_revision_spec=None, new_revision_spec=None):
187
"""Helper for cmd_diff.
193
The specific files to compare, or None
195
external_diff_options
196
If non-None, run an external diff, and pass it these options
199
If None, use basis tree as old revision, otherwise use the tree for
200
the specified revision.
203
If None, use working tree as new revision, otherwise use the tree for
204
the specified revision.
206
The more general form is show_diff_trees(), where the caller
207
supplies any two trees.
212
revision_id = spec.in_store(tree.branch).rev_id
213
return tree.branch.repository.revision_tree(revision_id)
214
if old_revision_spec is None:
215
old_tree = tree.basis_tree()
217
old_tree = spec_tree(old_revision_spec)
219
if new_revision_spec is None:
222
new_tree = spec_tree(new_revision_spec)
224
return show_diff_trees(old_tree, new_tree, sys.stdout, specific_files,
225
external_diff_options)
228
182
def show_diff_trees(old_tree, new_tree, to_file, specific_files=None,
229
183
external_diff_options=None):
236
190
If set, use an external GNU diff and pass these options.
243
return _show_diff_trees(old_tree, new_tree, to_file,
244
specific_files, external_diff_options)
251
def _show_diff_trees(old_tree, new_tree, to_file,
252
specific_files, external_diff_options):
254
# TODO: Options to control putting on a prefix or suffix, perhaps
255
# as a format string?
193
# TODO: Options to control putting on a prefix or suffix, perhaps as a format string
259
197
DEVNULL = '/dev/null'
260
198
# Windows users, don't panic about this filename -- it is a
280
218
for path, file_id, kind in delta.removed:
282
print >>to_file, '=== removed %s %r' % (kind, old_label + path)
220
print >>to_file, '=== removed %s %r' % (kind, path)
283
221
old_tree.inventory[file_id].diff(diff_file, old_label + path, old_tree,
284
222
DEVNULL, None, None, to_file)
285
223
for path, file_id, kind in delta.added:
287
print >>to_file, '=== added %s %r' % (kind, new_label + path)
225
print >>to_file, '=== added %s %r' % (kind, path)
288
226
new_tree.inventory[file_id].diff(diff_file, new_label + path, new_tree,
289
227
DEVNULL, None, None, to_file,
294
232
prop_str = get_prop_change(meta_modified)
295
233
print >>to_file, '=== renamed %s %r => %r%s' % (
296
kind, old_label + old_path, new_label + new_path, prop_str)
234
kind, old_path, new_path, prop_str)
297
235
_maybe_diff_file_or_symlink(old_label, old_path, old_tree, file_id,
298
236
new_label, new_path, new_tree,
299
237
text_modified, kind, to_file, diff_file)
300
238
for path, file_id, kind, text_modified, meta_modified in delta.modified:
302
240
prop_str = get_prop_change(meta_modified)
303
print >>to_file, '=== modified %s %r%s' % (kind, old_label + path,
241
print >>to_file, '=== modified %s %r%s' % (kind, path, prop_str)
305
242
if text_modified:
306
243
_maybe_diff_file_or_symlink(old_label, path, old_tree, file_id,
307
244
new_label, path, new_tree,