151
156
if meta_modified:
154
print >>to_file, '%s %s => %s %s' % (
155
short_status_letter, oldpath, newpath, fid)
159
to_file.write(indent + '%s %s => %s %s\n' % (
160
short_status_letter, oldpath, newpath, fid))
157
print >>to_file, '%s %s => %s' % (
158
short_status_letter, oldpath, newpath)
162
to_file.write(indent + '%s %s => %s\n' % (
163
short_status_letter, oldpath, newpath))
160
165
if self.kind_changed:
162
167
short_status_letter = 'K'
164
print >>to_file, 'kind changed:'
169
to_file.write(indent + 'kind changed:\n')
165
170
short_status_letter = ''
166
171
for (path, fid, old_kind, new_kind) in self.kind_changed:
171
print >>to_file, '%s %s (%s => %s)%s' % (
172
short_status_letter, path, old_kind, new_kind, suffix)
176
to_file.write(indent + '%s %s (%s => %s)%s\n' % (
177
short_status_letter, path, old_kind, new_kind, suffix))
174
179
if self.modified or extra_modified:
175
180
short_status_letter = 'M'
176
181
if not short_status:
177
print >>to_file, 'modified:'
182
to_file.write(indent + 'modified:\n')
178
183
short_status_letter = ''
179
184
show_list(self.modified, short_status_letter)
180
185
show_list(extra_modified, short_status_letter)
182
187
if show_unchanged and self.unchanged:
183
188
if not short_status:
184
print >>to_file, 'unchanged:'
189
to_file.write(indent + 'unchanged:\n')
185
190
show_list(self.unchanged)
187
192
show_list(self.unchanged, 'S')
195
to_file.write(indent + 'unknown:\n')
196
show_list(self.unversioned)
190
@deprecated_function(zero_nine)
191
def compare_trees(old_tree, new_tree, want_unchanged=False,
192
specific_files=None, extra_trees=None,
193
require_versioned=False):
194
"""compare_trees was deprecated in 0.10. Please see Tree.changes_from."""
195
return new_tree.changes_from(old_tree,
196
want_unchanged=want_unchanged,
197
specific_files=specific_files,
198
extra_trees=extra_trees,
199
require_versioned=require_versioned,
198
def get_changes_as_text(self, show_ids=False, show_unchanged=False,
201
output = StringIO.StringIO()
202
self.show(output, show_ids, show_unchanged, short_status)
203
return output.getvalue()
203
206
def _compare_trees(old_tree, new_tree, want_unchanged, specific_files,
204
include_root, extra_trees=None):
207
include_root, extra_trees=None,
208
require_versioned=False, want_unversioned=False):
209
"""Worker function that implements Tree.changes_from."""
205
210
delta = TreeDelta()
206
211
# mutter('start compare_trees')
208
213
for (file_id, path, content_change, versioned, parent_id, name, kind,
209
executable) in new_tree._iter_changes(old_tree, want_unchanged,
210
specific_files, extra_trees=extra_trees):
214
executable) in new_tree.iter_changes(old_tree, want_unchanged,
215
specific_files, extra_trees=extra_trees,
216
require_versioned=require_versioned,
217
want_unversioned=want_unversioned):
218
if versioned == (False, False):
219
delta.unversioned.append((path[1], None, kind[1]))
211
221
if not include_root and (None, None) == parent_id:
213
223
fully_present = tuple((versioned[x] and kind[x] is not None) for
215
225
if fully_present[0] != fully_present[1]:
216
226
if fully_present[1] is True:
217
delta.added.append((path, file_id, kind[1]))
227
delta.added.append((path[1], file_id, kind[1]))
219
assert fully_present[0] is True
220
old_path = old_tree.id2path(file_id)
221
delta.removed.append((old_path, file_id, kind[0]))
229
delta.removed.append((path[0], file_id, kind[0]))
222
230
elif fully_present[0] is False:
224
232
elif name[0] != name[1] or parent_id[0] != parent_id[1]:
225
233
# If the name changes, or the parent_id changes, we have a rename
226
234
# (if we move a parent, that doesn't count as a rename for the
228
old_path = old_tree.id2path(file_id)
229
delta.renamed.append((old_path,
236
delta.renamed.append((path[0],
234
241
(executable[0] != executable[1])))
235
242
elif kind[0] != kind[1]:
236
delta.kind_changed.append((path, file_id, kind[0], kind[1]))
243
delta.kind_changed.append((path[1], file_id, kind[0], kind[1]))
237
244
elif content_change is True or executable[0] != executable[1]:
238
delta.modified.append((path, file_id, kind[1],
245
delta.modified.append((path[1], file_id, kind[1],
240
247
(executable[0] != executable[1])))
242
delta.unchanged.append((path, file_id, kind[1]))
249
delta.unchanged.append((path[1], file_id, kind[1]))
244
251
delta.removed.sort()
245
252
delta.added.sort()
255
class ChangeReporter(object):
262
class _ChangeReporter(object):
256
263
"""Report changes between two trees"""
258
def __init__(self, old_inventory, output=None, suppress_root_add=True,
265
def __init__(self, output=None, suppress_root_add=True,
266
output_file=None, unversioned_filter=None):
262
:param old_inventory: The inventory of the old tree
263
269
:param output: a function with the signature of trace.note, i.e.
264
270
accepts a format and parameters.
265
271
:param supress_root_add: If true, adding the root will be ignored
266
272
(i.e. when a tree has just been initted)
267
273
:param output_file: If supplied, a file-like object to write to.
268
274
Only one of output and output_file may be supplied.
275
:param unversioned_filter: A filter function to be called on
276
unversioned files. This should return True to ignore a path.
277
By default, no filtering takes place.
270
self.old_inventory = old_inventory
271
279
if output_file is not None:
272
280
if output is not None:
273
281
raise BzrError('Cannot specify both output and output_file')
278
286
from bzrlib import trace
279
287
self.output = trace.note
280
288
self.suppress_root_add = suppress_root_add
289
self.modified_map = {'kind changed': 'K',
294
self.versioned_map = {'added': '+', # versioned target
295
'unchanged': ' ', # versioned in both
296
'removed': '-', # versioned in source
297
'unversioned': '?', # versioned in neither
299
self.unversioned_filter = unversioned_filter
282
def report(self, file_id, path, versioned, renamed, modified, exe_change,
301
def report(self, file_id, paths, versioned, renamed, modified, exe_change,
284
303
"""Report one change to a file
286
305
:param file_id: The file_id of the file
287
:param path: The path the file has (or would have) in the tree (as
288
generated by Tree._iter_changes)
289
:param versioned: may be 'added', 'removed', or 'unchanged'
306
:param path: The old and new paths as generated by Tree.iter_changes.
307
:param versioned: may be 'added', 'removed', 'unchanged', or
290
309
:param renamed: may be True or False
291
310
:param modified: may be 'created', 'deleted', 'kind changed',
292
311
'modified' or 'unchanged'.
293
312
:param exe_change: True if the execute bit has changed
294
:param kind: A pair of file kinds, as generated by Tree._iter_changes.
313
:param kind: A pair of file kinds, as generated by Tree.iter_changes.
295
314
None indicates no file present.
297
if path == '' and versioned == 'added' and self.suppress_root_add:
299
modified_map = {'kind changed': 'K',
304
versioned_map = {'added': '+',
318
if paths[1] == '' and versioned == 'added' and self.suppress_root_add:
320
if versioned == 'unversioned':
321
# skip ignored unversioned files if needed.
322
if self.unversioned_filter is not None:
323
if self.unversioned_filter(paths[1]):
325
# dont show a content change in the output.
326
modified = 'unchanged'
327
# we show both paths in the following situations:
328
# the file versioning is unchanged AND
329
# ( the path is different OR
330
# the kind is different)
331
if (versioned == 'unchanged' and
332
(renamed or modified == 'kind changed')):
334
# on a rename, we show old and new
335
old_path, path = paths
337
# if it's not renamed, we're showing both for kind changes
338
# so only show the new path
339
old_path, path = paths[1], paths[1]
340
# if the file is not missing in the source, we show its kind
341
# when we show two paths.
342
if kind[0] is not None:
343
old_path += osutils.kind_marker(kind[0])
345
elif versioned == 'removed':
346
# not present in target
309
old_path = self.old_inventory.id2path(file_id)
312
rename = versioned_map[versioned]
313
if modified == 'kind changed':
355
rename = self.versioned_map[versioned]
356
# we show the old kind on the new path when the content is deleted.
316
357
if modified == 'deleted':
317
358
path += osutils.kind_marker(kind[0])
359
# otherwise we always show the current kind when there is one
318
360
elif kind[1] is not None:
319
361
path += osutils.kind_marker(kind[1])
321
if kind[0] is not None:
322
old_path += osutils.kind_marker(kind[0])
328
self.output("%s%s%s %s%s", rename, modified_map[modified], exe,
366
self.output("%s%s%s %s%s", rename, self.modified_map[modified], exe,