/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/delta.py

  • Committer: Arnaud Jeansen
  • Date: 2010-03-19 22:58:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5126.
  • Revision ID: arnaud.jeansen@gmail.com-20100319225814-b4o3j0q5d1b7gjgg
Create a short show callback using the previously removed short code (it was not dead, only not used by status). Port log to directly call the callbacks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
292
292
        self.output("%s%s%s %s%s", rename, self.modified_map[modified], exe,
293
293
                    old_path, path)
294
294
 
295
 
 
296
295
def report_changes(change_iterator, reporter):
297
296
    """Report the changes from a change iterator.
298
297
 
336
335
        versioned_change = versioned_change_map[versioned]
337
336
        reporter.report(file_id, path, versioned_change, renamed, modified,
338
337
                        exe_change, kind)
 
338
 
 
339
 
 
340
def report_short(to_file, delta, show_ids=False, show_unchanged=False,
 
341
         indent='', filter=None):
 
342
    """Output given delta in status-like form to to_file, using a short format.
 
343
 
 
344
    :param to_file: A file-like object where the output is displayed.
 
345
 
 
346
    :param delta: A TreeDelta containing the changes to be displayed
 
347
 
 
348
    :param show_ids: Output the file ids if True.
 
349
 
 
350
    :param show_unchanged: Output the unchanged files if True.
 
351
 
 
352
    :param indent: Added at the beginning of all output lines (for merged
 
353
        revisions).
 
354
 
 
355
    :param filter: A callable receiving a path and a file id and
 
356
        returning True if the path should be displayed.
 
357
    """
 
358
 
 
359
    def decorate_path(path, kind, meta_modified=None):
 
360
        if kind == 'directory':
 
361
            path += '/'
 
362
        elif kind == 'symlink':
 
363
            path += '@'
 
364
        if meta_modified:
 
365
            path += '*'
 
366
        return path
 
367
 
 
368
    def show_more_renamed(item):
 
369
        (oldpath, file_id, kind,
 
370
         text_modified, meta_modified, newpath) = item
 
371
        dec_new_path = decorate_path(newpath, kind, meta_modified)
 
372
        to_file.write(' => %s' % dec_new_path)
 
373
        if text_modified or meta_modified:
 
374
            extra_modified.append((newpath, file_id, kind,
 
375
                                   text_modified, meta_modified))
 
376
 
 
377
    def show_more_kind_changed(item):
 
378
        (path, file_id, old_kind, new_kind) = item
 
379
        to_file.write(' (%s => %s)' % (old_kind, new_kind))
 
380
 
 
381
    def show_path(path, file_id, kind, meta_modified,
 
382
                  default_format, with_file_id_format):
 
383
        dec_path = decorate_path(path, kind, meta_modified)
 
384
        if show_ids:
 
385
            to_file.write(with_file_id_format % dec_path)
 
386
        else:
 
387
            to_file.write(default_format % dec_path)
 
388
 
 
389
    def show_list(files, short_status_letter, default_format='%s', 
 
390
                  with_file_id_format='%-30s', show_more=None):
 
391
        if files:
 
392
            prefix = indent + short_status_letter + '  '
 
393
 
 
394
            for item in files:
 
395
                path, file_id, kind = item[:3]
 
396
                if (filter is not None and not filter(path, file_id)):
 
397
                    continue
 
398
                meta_modified = None
 
399
                if len(item) == 5:
 
400
                    meta_modified = item[4]
 
401
 
 
402
                to_file.write(prefix)
 
403
                show_path(path, file_id, kind, meta_modified,
 
404
                          default_format, with_file_id_format)
 
405
                if show_more is not None:
 
406
                    show_more(item)
 
407
                if show_ids:
 
408
                    to_file.write(' %s' % file_id)
 
409
                to_file.write('\n')
 
410
 
 
411
    show_list(delta.removed, 'D')
 
412
    show_list(delta.added, 'A')
 
413
    extra_modified = []
 
414
    # Reorder delta.renamed tuples so that all lists share the same
 
415
    # order for their 3 first fields and that they also begin like
 
416
    # the delta.modified tuples
 
417
    renamed = [(p, i, k, tm, mm, np)
 
418
               for  p, np, i, k, tm, mm  in delta.renamed]
 
419
    show_list(renamed, 'R', with_file_id_format='%s',
 
420
              show_more=show_more_renamed)
 
421
    show_list(delta.kind_changed, 'K', 
 
422
              with_file_id_format='%s',
 
423
              show_more=show_more_kind_changed)
 
424
    show_list(delta.modified + extra_modified, 'M')
 
425
    if show_unchanged:
 
426
        show_list(delta.unchanged, 'S')
 
427
 
 
428
    show_list(delta.unversioned, ' ')
 
429
 
 
430
 
 
431
 
 
432
def report_long(to_file, delta, show_ids=False, show_unchanged=False,
 
433
         indent='', filter=None):
 
434
    """Output given delta in status-like form to to_file.
 
435
 
 
436
    :param to_file: A file-like object where the output is displayed.
 
437
 
 
438
    :param delta: A TreeDelta containing the changes to be displayed
 
439
 
 
440
    :param show_ids: Output the file ids if True.
 
441
 
 
442
    :param show_unchanged: Output the unchanged files if True.
 
443
 
 
444
    :param indent: Added at the beginning of all output lines (for merged
 
445
        revisions).
 
446
 
 
447
    :param filter: A callable receiving a path and a file id and
 
448
        returning True if the path should be displayed.
 
449
    """
 
450
 
 
451
    def decorate_path(path, kind, meta_modified=None):
 
452
        if kind == 'directory':
 
453
            path += '/'
 
454
        elif kind == 'symlink':
 
455
            path += '@'
 
456
        if meta_modified:
 
457
            path += '*'
 
458
        return path
 
459
 
 
460
    def show_more_renamed(item):
 
461
        (oldpath, file_id, kind,
 
462
         text_modified, meta_modified, newpath) = item
 
463
        dec_new_path = decorate_path(newpath, kind, meta_modified)
 
464
        to_file.write(' => %s' % dec_new_path)
 
465
        if text_modified or meta_modified:
 
466
            extra_modified.append((newpath, file_id, kind,
 
467
                                   text_modified, meta_modified))
 
468
 
 
469
    def show_more_kind_changed(item):
 
470
        (path, file_id, old_kind, new_kind) = item
 
471
        to_file.write(' (%s => %s)' % (old_kind, new_kind))
 
472
 
 
473
    def show_path(path, file_id, kind, meta_modified,
 
474
                  default_format, with_file_id_format):
 
475
        dec_path = decorate_path(path, kind, meta_modified)
 
476
        if show_ids:
 
477
            to_file.write(with_file_id_format % dec_path)
 
478
        else:
 
479
            to_file.write(default_format % dec_path)
 
480
 
 
481
    def show_list(files, long_status_name, default_format='%s', 
 
482
                  with_file_id_format='%-30s', show_more=None):
 
483
        if files:
 
484
            header_shown = False
 
485
            prefix = indent + '  '
 
486
 
 
487
            for item in files:
 
488
                path, file_id, kind = item[:3]
 
489
                if (filter is not None and not filter(path, file_id)):
 
490
                    continue
 
491
                if not header_shown:
 
492
                    to_file.write(indent + long_status_name + ':\n')
 
493
                    header_shown = True
 
494
                meta_modified = None
 
495
                if len(item) == 5:
 
496
                    meta_modified = item[4]
 
497
 
 
498
                to_file.write(prefix)
 
499
                show_path(path, file_id, kind, meta_modified,
 
500
                          default_format, with_file_id_format)
 
501
                if show_more is not None:
 
502
                    show_more(item)
 
503
                if show_ids:
 
504
                    to_file.write(' %s' % file_id)
 
505
                to_file.write('\n')
 
506
 
 
507
    show_list(delta.removed, 'removed')
 
508
    show_list(delta.added, 'added')
 
509
    extra_modified = []
 
510
    # Reorder delta.renamed tuples so that all lists share the same
 
511
    # order for their 3 first fields and that they also begin like
 
512
    # the delta.modified tuples
 
513
    renamed = [(p, i, k, tm, mm, np)
 
514
               for  p, np, i, k, tm, mm  in delta.renamed]
 
515
    show_list(renamed, 'renamed', with_file_id_format='%s',
 
516
              show_more=show_more_renamed)
 
517
    show_list(delta.kind_changed, 'kind changed', 
 
518
              with_file_id_format='%s',
 
519
              show_more=show_more_kind_changed)
 
520
    show_list(delta.modified + extra_modified, 'modified')
 
521
    if show_unchanged:
 
522
        show_list(delta.unchanged, 'unchanged')
 
523
 
 
524
    show_list(delta.unversioned, 'unknown')
 
525