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.delta import compare_trees
18
from bzrlib.errors import BzrError
19
from bzrlib.symbol_versioning import *
17
20
from bzrlib.trace import mutter
18
from bzrlib.errors import BzrError
19
from bzrlib.delta import compare_trees
21
22
# TODO: Rather than building a changeset object, we should probably
22
23
# invoke callbacks on an object. That object can either accumulate a
141
142
oldtmpf.close() # and delete
146
@deprecated_function(zero_eight)
144
147
def show_diff(b, from_spec, specific_files, external_diff_options=None,
145
148
revision2=None, output=None, b2=None):
146
149
"""Shortcut for showing the diff to the working tree.
151
Please use show_diff_trees instead.
159
164
output = sys.stdout
161
166
if from_spec is None:
167
old_tree = b.bzrdir.open_workingtree()
163
old_tree = b.basis_tree()
165
old_tree = b.working_tree()
169
old_tree = old_tree = old_tree.basis_tree()
167
171
old_tree = b.repository.revision_tree(from_spec.in_history(b).rev_id)
169
173
if revision2 is None:
171
new_tree = b.working_tree()
175
new_tree = b.bzrdir.open_workingtree()
173
new_tree = b2.working_tree()
177
new_tree = b2.bzrdir.open_workingtree()
175
179
new_tree = b.repository.revision_tree(revision2.in_history(b).rev_id)
178
182
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)
182
228
def show_diff_trees(old_tree, new_tree, to_file, specific_files=None,
183
229
external_diff_options=None):
205
251
def _show_diff_trees(old_tree, new_tree, to_file,
206
252
specific_files, external_diff_options):
208
# TODO: Options to control putting on a prefix or suffix, perhaps as a format string
254
# TODO: Options to control putting on a prefix or suffix, perhaps
255
# as a format string?
212
259
DEVNULL = '/dev/null'
213
260
# Windows users, don't panic about this filename -- it is a
233
280
for path, file_id, kind in delta.removed:
235
print >>to_file, '=== removed %s %r' % (kind, path)
282
print >>to_file, '=== removed %s %r' % (kind, old_label + path)
236
283
old_tree.inventory[file_id].diff(diff_file, old_label + path, old_tree,
237
284
DEVNULL, None, None, to_file)
238
285
for path, file_id, kind in delta.added:
240
print >>to_file, '=== added %s %r' % (kind, path)
287
print >>to_file, '=== added %s %r' % (kind, new_label + path)
241
288
new_tree.inventory[file_id].diff(diff_file, new_label + path, new_tree,
242
289
DEVNULL, None, None, to_file,
247
294
prop_str = get_prop_change(meta_modified)
248
295
print >>to_file, '=== renamed %s %r => %r%s' % (
249
kind, old_path, new_path, prop_str)
296
kind, old_label + old_path, new_label + new_path, prop_str)
250
297
_maybe_diff_file_or_symlink(old_label, old_path, old_tree, file_id,
251
298
new_label, new_path, new_tree,
252
299
text_modified, kind, to_file, diff_file)
253
300
for path, file_id, kind, text_modified, meta_modified in delta.modified:
255
302
prop_str = get_prop_change(meta_modified)
256
print >>to_file, '=== modified %s %r%s' % (kind, path, prop_str)
303
print >>to_file, '=== modified %s %r%s' % (kind, old_label + path,
257
305
if text_modified:
258
306
_maybe_diff_file_or_symlink(old_label, path, old_tree, file_id,
259
307
new_label, path, new_tree,