~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/status.py

  • Committer: Jelmer Vernooij
  • Date: 2011-12-16 19:18:39 UTC
  • mto: This revision was merged to the branch mainline in revision 6391.
  • Revision ID: jelmer@samba.org-20111216191839-eg681lxqibi1qxu1
Fix remaining tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
def report_changes(to_file, old, new, specific_files, 
35
35
                   show_short_reporter, show_long_callback, 
36
36
                   short=False, want_unchanged=False, 
37
 
                   want_unversioned=False, show_ids=False):
 
37
                   want_unversioned=False, show_ids=False, classify=True):
38
38
    """Display summary of changes.
39
39
 
40
40
    This compares two trees with regards to a list of files, and delegates 
59
59
        files.
60
60
    :param show_ids: If set, includes each file's id.
61
61
    :param want_unversioned: If False, only shows versioned files.
 
62
    :param classify: Add special symbols to indicate file kind.
62
63
    """
63
64
 
64
65
    if short:
76
77
            delta.unversioned if not new.is_ignored(unversioned[0])]
77
78
        show_long_callback(to_file, delta, 
78
79
                           show_ids=show_ids,
79
 
                           show_unchanged=want_unchanged)
 
80
                           show_unchanged=want_unchanged,
 
81
                           classify=classify)
80
82
 
81
83
 
82
84
def show_tree_status(wt, show_unchanged=None,
88
90
                     short=False,
89
91
                     verbose=False,
90
92
                     versioned=False,
 
93
                     classify=True,
91
94
                     show_long_callback=_mod_delta.report_delta):
92
95
    """Display summary of changes.
93
96
 
117
120
    :param verbose: If True, show all merged revisions, not just
118
121
        the merge tips
119
122
    :param versioned: If True, only shows versioned files.
 
123
    :param classify: Add special symbols to indicate file kind.
120
124
    :param show_long_callback: A callback: message = show_long_callback(to_file, delta, 
121
125
        show_ids, show_unchanged, indent, filter), only used with the long output
122
126
    """
153
157
        try:
154
158
            for hook in hooks['pre_status']:
155
159
                hook(StatusHookParams(old, new, to_file, versioned,
156
 
                    show_ids, short, verbose))
 
160
                    show_ids, short, verbose, specific_files=specific_files))
157
161
 
158
162
            specific_files, nonexistents \
159
163
                = _filter_nonexistent(specific_files, old, new)
161
165
 
162
166
            # Reporter used for short outputs
163
167
            reporter = _mod_delta._ChangeReporter(output_file=to_file,
164
 
                unversioned_filter=new.is_ignored)
 
168
                unversioned_filter=new.is_ignored, classify=classify)
165
169
            report_changes(to_file, old, new, specific_files, 
166
170
                           reporter, show_long_callback, 
167
171
                           short=short, want_unchanged=show_unchanged, 
168
 
                           want_unversioned=want_unversioned, show_ids=show_ids)
 
172
                           want_unversioned=want_unversioned, show_ids=show_ids,
 
173
                           classify=classify)
169
174
 
170
175
            # show the ignored files among specific files (i.e. show the files
171
176
            # identified from input that we choose to ignore). 
194
199
                    prefix = 'C  '
195
200
                else:
196
201
                    prefix = ' '
197
 
                to_file.write("%s %s\n" % (prefix, conflict))
 
202
                to_file.write("%s %s\n" % (prefix, unicode(conflict)))
198
203
            # Show files that were requested but don't exist (and are
199
204
            # not versioned).  We don't involve delta in this; these
200
205
            # paths are really the province of just the status
217
222
                raise errors.PathsDoNotExist(nonexistents)
218
223
            for hook in hooks['post_status']:
219
224
                hook(StatusHookParams(old, new, to_file, versioned,
220
 
                    show_ids, short, verbose))
 
225
                    show_ids, short, verbose, specific_files=specific_files))
221
226
        finally:
222
227
            old.unlock()
223
228
            new.unlock()
379
384
        These are all empty initially, because by default nothing should get
380
385
        notified.
381
386
        """
382
 
        _mod_hooks.Hooks.__init__(self)
383
 
        self.create_hook(_mod_hooks.HookPoint('post_status',
 
387
        _mod_hooks.Hooks.__init__(self, "bzrlib.status", "hooks")
 
388
        self.add_hook('post_status',
384
389
            "Called with argument StatusHookParams after Bazaar has "
385
390
            "displayed the status. StatusHookParams has the attributes "
386
391
            "(old_tree, new_tree, to_file, versioned, show_ids, short, "
387
392
            "verbose). The last four arguments correspond to the command "
388
393
            "line options specified by the user for the status command. "
389
394
            "to_file is the output stream for writing.",
390
 
            (2, 3), None))
391
 
        self.create_hook(_mod_hooks.HookPoint('pre_status',
 
395
            (2, 3))
 
396
        self.add_hook('pre_status',
392
397
            "Called with argument StatusHookParams before Bazaar "
393
398
            "displays the status. StatusHookParams has the attributes "
394
399
            "(old_tree, new_tree, to_file, versioned, show_ids, short, "
395
400
            "verbose). The last four arguments correspond to the command "
396
401
            "line options specified by the user for the status command. "
397
402
            "to_file is the output stream for writing.",
398
 
            (2, 3), None))
 
403
            (2, 3))
399
404
 
400
405
 
401
406
class StatusHookParams(object):
411
416
    """
412
417
 
413
418
    def __init__(self, old_tree, new_tree, to_file, versioned, show_ids,
414
 
            short, verbose):
 
419
            short, verbose, specific_files=None):
415
420
        """Create a group of post_status hook parameters.
416
421
 
417
422
        :param old_tree: Start tree (basis tree) for comparison.
421
426
        :param show_ids: Show internal object ids.
422
427
        :param short: Use short status indicators.
423
428
        :param verbose: Verbose flag.
 
429
        :param specific_files: If set, a list of filenames whose status should be
 
430
            shown.  It is an error to give a filename that is not in the working
 
431
            tree, or in the working inventory or in the basis inventory.
424
432
        """
425
433
        self.old_tree = old_tree
426
434
        self.new_tree = new_tree
429
437
        self.show_ids = show_ids
430
438
        self.short = short
431
439
        self.verbose = verbose
 
440
        self.specific_files = specific_files
432
441
 
433
442
    def __eq__(self, other):
434
443
        return self.__dict__ == other.__dict__
435
444
 
436
445
    def __repr__(self):
437
 
        return "<%s(%s, %s, %s, %s, %s, %s, %s)>" % (self.__class__.__name__,
 
446
        return "<%s(%s, %s, %s, %s, %s, %s, %s, %s)>" % (self.__class__.__name__,
438
447
            self.old_tree, self.new_tree, self.to_file, self.versioned,
439
 
            self.show_ids, self.short, self.verbose)
 
448
            self.show_ids, self.short, self.verbose, self.specific_files)
440
449
 
441
450
 
442
451
def _show_shelve_summary(params):
444
453
 
445
454
    :param params: StatusHookParams.
446
455
    """
 
456
    # Don't show shelves if status of specific files is being shown, only if
 
457
    # no file arguments have been passed
 
458
    if params.specific_files:
 
459
        return
447
460
    get_shelf_manager = getattr(params.new_tree, 'get_shelf_manager', None)
448
461
    if get_shelf_manager is None:
449
462
        return
450
463
    manager = get_shelf_manager()
451
464
    shelves = manager.active_shelves()
452
465
    if shelves:
453
 
        params.to_file.write('%d shelves exist. '
454
 
            'See "bzr shelve --list" for details.\n' % len(shelves))
 
466
        singular = '%d shelf exists. '
 
467
        plural = '%d shelves exist. '
 
468
        if len(shelves) == 1:
 
469
            fmt = singular
 
470
        else:
 
471
            fmt = plural
 
472
        params.to_file.write(fmt % len(shelves))
 
473
        params.to_file.write('See "bzr shelve --list" for details.\n')
455
474
 
456
475
 
457
476
hooks = StatusHooks()