158
for hook in hooks['pre_status']:
159
hook(StatusHookParams(old, new, to_file, versioned,
160
show_ids, short, verbose))
162
153
specific_files, nonexistents \
163
154
= _filter_nonexistent(specific_files, old, new)
164
155
want_unversioned = not versioned
166
157
# Reporter used for short outputs
167
158
reporter = _mod_delta._ChangeReporter(output_file=to_file,
168
unversioned_filter=new.is_ignored, classify=classify)
159
unversioned_filter=new.is_ignored)
169
160
report_changes(to_file, old, new, specific_files,
170
161
reporter, show_long_callback,
171
162
short=short, want_unchanged=show_unchanged,
172
want_unversioned=want_unversioned, show_ids=show_ids,
163
want_unversioned=want_unversioned, show_ids=show_ids)
175
165
# show the ignored files among specific files (i.e. show the files
176
166
# identified from input that we choose to ignore).
369
356
# their groups individually. But for consistency of this
370
357
# function's API, it's better to sort both than just 'nonexistent'.
371
358
return sorted(remaining), sorted(nonexistent)
374
class StatusHooks(_mod_hooks.Hooks):
375
"""A dictionary mapping hook name to a list of callables for status hooks.
377
e.g. ['post_status'] Is the list of items to be called when the
378
status command has finished printing the status.
382
"""Create the default hooks.
384
These are all empty initially, because by default nothing should get
387
_mod_hooks.Hooks.__init__(self, "bzrlib.status", "hooks")
388
self.add_hook('post_status',
389
"Called with argument StatusHookParams after Bazaar has "
390
"displayed the status. StatusHookParams has the attributes "
391
"(old_tree, new_tree, to_file, versioned, show_ids, short, "
392
"verbose). The last four arguments correspond to the command "
393
"line options specified by the user for the status command. "
394
"to_file is the output stream for writing.",
396
self.add_hook('pre_status',
397
"Called with argument StatusHookParams before Bazaar "
398
"displays the status. StatusHookParams has the attributes "
399
"(old_tree, new_tree, to_file, versioned, show_ids, short, "
400
"verbose). The last four arguments correspond to the command "
401
"line options specified by the user for the status command. "
402
"to_file is the output stream for writing.",
406
class StatusHookParams(object):
407
"""Object holding parameters passed to post_status hooks.
409
:ivar old_tree: Start tree (basis tree) for comparison.
410
:ivar new_tree: Working tree.
411
:ivar to_file: If set, write to this file.
412
:ivar versioned: Show only versioned files.
413
:ivar show_ids: Show internal object ids.
414
:ivar short: Use short status indicators.
415
:ivar verbose: Verbose flag.
418
def __init__(self, old_tree, new_tree, to_file, versioned, show_ids,
420
"""Create a group of post_status hook parameters.
422
:param old_tree: Start tree (basis tree) for comparison.
423
:param new_tree: Working tree.
424
:param to_file: If set, write to this file.
425
:param versioned: Show only versioned files.
426
:param show_ids: Show internal object ids.
427
:param short: Use short status indicators.
428
:param verbose: Verbose flag.
430
self.old_tree = old_tree
431
self.new_tree = new_tree
432
self.to_file = to_file
433
self.versioned = versioned
434
self.show_ids = show_ids
436
self.verbose = verbose
438
def __eq__(self, other):
439
return self.__dict__ == other.__dict__
442
return "<%s(%s, %s, %s, %s, %s, %s, %s)>" % (self.__class__.__name__,
443
self.old_tree, self.new_tree, self.to_file, self.versioned,
444
self.show_ids, self.short, self.verbose)
447
def _show_shelve_summary(params):
448
"""post_status hook to display a summary of shelves.
450
:param params: StatusHookParams.
452
get_shelf_manager = getattr(params.new_tree, 'get_shelf_manager', None)
453
if get_shelf_manager is None:
455
manager = get_shelf_manager()
456
shelves = manager.active_shelves()
458
singular = '%d shelf exists. '
459
plural = '%d shelves exist. '
460
if len(shelves) == 1:
464
params.to_file.write(fmt % len(shelves))
465
params.to_file.write('See "bzr shelve --list" for details.\n')
468
hooks = StatusHooks()
471
hooks.install_named_hook('post_status', _show_shelve_summary,