342
339
def report_delta(to_file, delta, short_status=False, show_ids=False,
343
340
show_unchanged=False, indent='', filter=None):
345
__report_delta_short(to_file, delta, show_ids, show_unchanged,
348
__report_delta_long(to_file, delta, show_ids, show_unchanged,
351
def __report_delta_short(to_file, delta, show_ids=False, show_unchanged=False,
352
indent='', filter=None):
353
"""Output given delta in status-like form to to_file, using a short format.
355
:param to_file: A file-like object where the output is displayed.
357
:param delta: A TreeDelta containing the changes to be displayed
359
:param show_ids: Output the file ids if True.
361
:param show_unchanged: Output the unchanged files if True.
363
:param indent: Added at the beginning of all output lines (for merged
366
:param filter: A callable receiving a path and a file id and
367
returning True if the path should be displayed.
370
def decorate_path(path, kind, meta_modified=None):
371
if kind == 'directory':
373
elif kind == 'symlink':
379
def show_more_renamed(item):
380
(oldpath, file_id, kind,
381
text_modified, meta_modified, newpath) = item
382
dec_new_path = decorate_path(newpath, kind, meta_modified)
383
to_file.write(' => %s' % dec_new_path)
384
if text_modified or meta_modified:
385
extra_modified.append((newpath, file_id, kind,
386
text_modified, meta_modified))
388
def show_more_kind_changed(item):
389
(path, file_id, old_kind, new_kind) = item
390
to_file.write(' (%s => %s)' % (old_kind, new_kind))
392
def show_path(path, file_id, kind, meta_modified,
393
default_format, with_file_id_format):
394
dec_path = decorate_path(path, kind, meta_modified)
396
to_file.write(with_file_id_format % dec_path)
398
to_file.write(default_format % dec_path)
400
def show_list(files, short_status_letter, default_format='%s',
401
with_file_id_format='%-30s', show_more=None):
403
prefix = indent + short_status_letter + ' '
406
path, file_id, kind = item[:3]
407
if (filter is not None and not filter(path, file_id)):
411
meta_modified = item[4]
413
to_file.write(prefix)
414
show_path(path, file_id, kind, meta_modified,
415
default_format, with_file_id_format)
416
if show_more is not None:
419
to_file.write(' %s' % file_id)
422
show_list(delta.removed, 'D')
423
show_list(delta.added, 'A')
425
# Reorder delta.renamed tuples so that all lists share the same
426
# order for their 3 first fields and that they also begin like
427
# the delta.modified tuples
428
renamed = [(p, i, k, tm, mm, np)
429
for p, np, i, k, tm, mm in delta.renamed]
430
show_list(renamed, 'R', with_file_id_format='%s',
431
show_more=show_more_renamed)
432
show_list(delta.kind_changed, 'K',
433
with_file_id_format='%s',
434
show_more=show_more_kind_changed)
435
show_list(delta.modified + extra_modified, 'M')
437
show_list(delta.unchanged, 'S')
439
show_list(delta.unversioned, ' ')
443
def __report_delta_long(to_file, delta, show_ids=False, show_unchanged=False,
444
indent='', filter=None):
445
"""Output given delta in status-like form to to_file.
447
:param to_file: A file-like object where the output is displayed.
449
:param delta: A TreeDelta containing the changes to be displayed
451
:param show_ids: Output the file ids if True.
453
:param show_unchanged: Output the unchanged files if True.
455
:param indent: Added at the beginning of all output lines (for merged
458
:param filter: A callable receiving a path and a file id and
459
returning True if the path should be displayed.
462
def decorate_path(path, kind, meta_modified=None):
463
if kind == 'directory':
465
elif kind == 'symlink':
471
def show_more_renamed(item):
472
(oldpath, file_id, kind,
473
text_modified, meta_modified, newpath) = item
474
dec_new_path = decorate_path(newpath, kind, meta_modified)
475
to_file.write(' => %s' % dec_new_path)
476
if text_modified or meta_modified:
477
extra_modified.append((newpath, file_id, kind,
478
text_modified, meta_modified))
480
def show_more_kind_changed(item):
481
(path, file_id, old_kind, new_kind) = item
482
to_file.write(' (%s => %s)' % (old_kind, new_kind))
484
def show_path(path, file_id, kind, meta_modified,
485
default_format, with_file_id_format):
486
dec_path = decorate_path(path, kind, meta_modified)
488
to_file.write(with_file_id_format % dec_path)
490
to_file.write(default_format % dec_path)
492
def show_list(files, long_status_name, default_format='%s',
493
with_file_id_format='%-30s', show_more=None):
341
"""Output this delta in status-like form to to_file.
343
:param to_file: A file-like object where the output is displayed.
345
:param delta: A TreeDelta containing the changes to be displayed
347
:param short_status: Single-line status if True.
349
:param show_ids: Output the file ids if True.
351
:param show_unchanged: Output the unchanged files if True.
353
:param indent: Added at the beginning of all output lines (for merged
356
:param filter: A callable receiving a path and a file id and
357
returning True if the path should be displayed.
360
def decorate_path(path, kind, meta_modified=None):
361
if kind == 'directory':
363
elif kind == 'symlink':
369
def show_more_renamed(item):
370
(oldpath, file_id, kind,
371
text_modified, meta_modified, newpath) = item
372
dec_new_path = decorate_path(newpath, kind, meta_modified)
373
to_file.write(' => %s' % dec_new_path)
374
if text_modified or meta_modified:
375
extra_modified.append((newpath, file_id, kind,
376
text_modified, meta_modified))
378
def show_more_kind_changed(item):
379
(path, file_id, old_kind, new_kind) = item
380
to_file.write(' (%s => %s)' % (old_kind, new_kind))
382
def show_path(path, file_id, kind, meta_modified,
383
default_format, with_file_id_format):
384
dec_path = decorate_path(path, kind, meta_modified)
386
to_file.write(with_file_id_format % dec_path)
388
to_file.write(default_format % dec_path)
390
def show_list(files, long_status_name, short_status_letter,
391
default_format='%s', with_file_id_format='%-30s',
495
394
header_shown = False
496
prefix = indent + ' '
396
prefix = short_status_letter
399
prefix = indent + prefix + ' '
498
401
for item in files:
499
402
path, file_id, kind = item[:3]
500
403
if (filter is not None and not filter(path, file_id)):
405
if not header_shown and not short_status:
503
406
to_file.write(indent + long_status_name + ':\n')
504
407
header_shown = True
505
408
meta_modified = None
515
418
to_file.write(' %s' % file_id)
516
419
to_file.write('\n')
518
show_list(delta.removed, 'removed')
519
show_list(delta.added, 'added')
421
show_list(delta.removed, 'removed', 'D')
422
show_list(delta.added, 'added', 'A')
520
423
extra_modified = []
521
424
# Reorder delta.renamed tuples so that all lists share the same
522
425
# order for their 3 first fields and that they also begin like
523
426
# the delta.modified tuples
524
427
renamed = [(p, i, k, tm, mm, np)
525
428
for p, np, i, k, tm, mm in delta.renamed]
526
show_list(renamed, 'renamed', with_file_id_format='%s',
429
show_list(renamed, 'renamed', 'R', with_file_id_format='%s',
527
430
show_more=show_more_renamed)
528
show_list(delta.kind_changed, 'kind changed',
431
show_list(delta.kind_changed, 'kind changed', 'K',
529
432
with_file_id_format='%s',
530
433
show_more=show_more_kind_changed)
531
show_list(delta.modified + extra_modified, 'modified')
434
show_list(delta.modified + extra_modified, 'modified', 'M')
532
435
if show_unchanged:
533
show_list(delta.unchanged, 'unchanged')
436
show_list(delta.unchanged, 'unchanged', 'S')
535
show_list(delta.unversioned, 'unknown')
438
show_list(delta.unversioned, 'unknown', ' ')