68
71
and self.renamed == other.renamed \
69
72
and self.modified == other.modified \
70
73
and self.unchanged == other.unchanged \
71
and self.kind_changed == other.kind_changed
74
and self.kind_changed == other.kind_changed \
75
and self.unversioned == other.unversioned
73
77
def __ne__(self, other):
74
78
return not (self == other)
76
80
def __repr__(self):
77
81
return "TreeDelta(added=%r, removed=%r, renamed=%r," \
78
" kind_changed=%r, modified=%r, unchanged=%r)" % (self.added,
82
" kind_changed=%r, modified=%r, unchanged=%r," \
83
" unversioned=%r)" % (self.added,
79
84
self.removed, self.renamed, self.kind_changed, self.modified,
85
self.unchanged, self.unversioned)
82
87
def has_changed(self):
83
88
return bool(self.modified
200
209
include_root=False)
203
def _compare_trees(old_tree, new_tree, want_unchanged, specific_file_ids,
212
def _compare_trees(old_tree, new_tree, want_unchanged, specific_files,
213
include_root, extra_trees=None,
214
want_unversioned=False):
215
"""Worker function that implements Tree.changes_from."""
205
216
delta = TreeDelta()
206
217
# mutter('start compare_trees')
208
219
for (file_id, path, content_change, versioned, parent_id, name, kind,
209
executable) in new_tree._iter_changes(old_tree, want_unchanged,
220
executable) in new_tree._iter_changes(old_tree, want_unchanged,
221
specific_files, extra_trees=extra_trees,
222
want_unversioned=want_unversioned):
223
if versioned == (False, False):
224
delta.unversioned.append((path[1], None, kind[1]))
211
226
if not include_root and (None, None) == parent_id:
213
228
fully_present = tuple((versioned[x] and kind[x] is not None) for
215
230
if fully_present[0] != fully_present[1]:
216
231
if fully_present[1] is True:
217
delta.added.append((path, file_id, kind[1]))
232
delta.added.append((path[1], file_id, kind[1]))
219
234
assert fully_present[0] is True
220
old_path = old_tree.id2path(file_id)
221
delta.removed.append((old_path, file_id, kind[0]))
235
delta.removed.append((path[0], file_id, kind[0]))
222
236
elif fully_present[0] is False:
224
238
elif name[0] != name[1] or parent_id[0] != parent_id[1]:
225
239
# If the name changes, or the parent_id changes, we have a rename
226
240
# (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,
242
delta.renamed.append((path[0],
234
247
(executable[0] != executable[1])))
235
248
elif kind[0] != kind[1]:
236
delta.kind_changed.append((path, file_id, kind[0], kind[1]))
249
delta.kind_changed.append((path[1], file_id, kind[0], kind[1]))
237
250
elif content_change is True or executable[0] != executable[1]:
238
delta.modified.append((path, file_id, kind[1],
251
delta.modified.append((path[1], file_id, kind[1],
240
253
(executable[0] != executable[1])))
242
delta.unchanged.append((path, file_id, kind[1]))
255
delta.unchanged.append((path[1], file_id, kind[1]))
244
257
delta.removed.sort()
245
258
delta.added.sort()
255
268
class ChangeReporter(object):
256
269
"""Report changes between two trees"""
258
def __init__(self, old_inventory, output=None, suppress_root_add=True,
271
def __init__(self, output=None, suppress_root_add=True,
272
output_file=None, unversioned_filter=None):
262
:param old_inventory: The inventory of the old tree
263
275
:param output: a function with the signature of trace.note, i.e.
264
276
accepts a format and parameters.
265
277
:param supress_root_add: If true, adding the root will be ignored
266
278
(i.e. when a tree has just been initted)
267
279
:param output_file: If supplied, a file-like object to write to.
268
280
Only one of output and output_file may be supplied.
281
:param unversioned_filter: A filter function to be called on
282
unversioned files. This should return True to ignore a path.
283
By default, no filtering takes place.
270
self.old_inventory = old_inventory
271
285
if output_file is not None:
272
286
if output is not None:
273
287
raise BzrError('Cannot specify both output and output_file')
278
292
from bzrlib import trace
279
293
self.output = trace.note
280
294
self.suppress_root_add = suppress_root_add
295
self.modified_map = {'kind changed': 'K',
300
self.versioned_map = {'added': '+', # versioned target
301
'unchanged': ' ', # versioned in both
302
'removed': '-', # versioned in source
303
'unversioned': '?', # versioned in neither
305
self.unversioned_filter = unversioned_filter
282
def report(self, file_id, path, versioned, renamed, modified, exe_change,
307
def report(self, file_id, paths, versioned, renamed, modified, exe_change,
284
309
"""Report one change to a file
286
311
: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'
312
:param path: The old and new paths as generated by Tree._iter_changes.
313
:param versioned: may be 'added', 'removed', 'unchanged', or
290
315
:param renamed: may be True or False
291
316
:param modified: may be 'created', 'deleted', 'kind changed',
292
317
'modified' or 'unchanged'.
294
319
:param kind: A pair of file kinds, as generated by Tree._iter_changes.
295
320
None indicates no file present.
297
if path == '' and versioned == 'added' and self.suppress_root_add:
322
if paths[1] == '' and versioned == 'added' and self.suppress_root_add:
299
modified_map = {'kind changed': 'K',
304
versioned_map = {'added': '+',
324
if versioned == 'unversioned':
325
# skip ignored unversioned files if needed.
326
if self.unversioned_filter is not None:
327
if self.unversioned_filter(paths[1]):
329
# dont show a content change in the output.
330
modified = 'unchanged'
331
# we show both paths in the following situations:
332
# the file versioning is unchanged AND
333
# ( the path is different OR
334
# the kind is different)
335
if (versioned == 'unchanged' and
336
(renamed or modified == 'kind changed')):
338
# on a rename, we show old and new
339
old_path, path = paths
341
# if its not renamed, we're showing both for kind changes
342
# so only show the new path
343
old_path, path = paths[1], paths[1]
344
# if the file is not missing in the source, we show its kind
345
# when we show two paths.
346
if kind[0] is not None:
347
old_path += osutils.kind_marker(kind[0])
349
elif versioned == 'removed':
350
# not present in target
309
old_path = self.old_inventory.id2path(file_id)
312
rename = versioned_map[versioned]
313
if modified == 'kind changed':
359
rename = self.versioned_map[versioned]
360
# we show the old kind on the new path when the content is deleted.
316
361
if modified == 'deleted':
317
362
path += osutils.kind_marker(kind[0])
363
# otherwise we always show the current kind when there is one
318
364
elif kind[1] is not None:
319
365
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,
370
self.output("%s%s%s %s%s", rename, self.modified_map[modified], exe,
339
381
generated by Tree._iter_changes
340
382
:param reporter: The ChangeReporter that will report the changes.
384
versioned_change_map = {
385
(True, True) : 'unchanged',
386
(True, False) : 'removed',
387
(False, True) : 'added',
388
(False, False): 'unversioned',
342
390
for (file_id, path, content_change, versioned, parent_id, name, kind,
343
391
executable) in change_iterator:
344
392
exe_change = False