158
for hook in hooks['pre_status']:
159
hook(StatusHookParams(old, new, to_file, versioned,
160
show_ids, short, verbose, specific_files=specific_files))
153
162
specific_files, nonexistents \
154
163
= _filter_nonexistent(specific_files, old, new)
155
164
want_unversioned = not versioned
157
166
# Reporter used for short outputs
158
167
reporter = _mod_delta._ChangeReporter(output_file=to_file,
159
unversioned_filter=new.is_ignored)
168
unversioned_filter=new.is_ignored, classify=classify)
160
169
report_changes(to_file, old, new, specific_files,
161
170
reporter, show_long_callback,
162
171
short=short, want_unchanged=show_unchanged,
163
want_unversioned=want_unversioned, show_ids=show_ids)
172
want_unversioned=want_unversioned, show_ids=show_ids,
165
175
# show the ignored files among specific files (i.e. show the files
166
176
# identified from input that we choose to ignore).
356
369
# their groups individually. But for consistency of this
357
370
# function's API, it's better to sort both than just 'nonexistent'.
358
371
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,
419
short, verbose, specific_files=None):
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.
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.
433
self.old_tree = old_tree
434
self.new_tree = new_tree
435
self.to_file = to_file
436
self.versioned = versioned
437
self.show_ids = show_ids
439
self.verbose = verbose
440
self.specific_files = specific_files
442
def __eq__(self, other):
443
return self.__dict__ == other.__dict__
446
return "<%s(%s, %s, %s, %s, %s, %s, %s, %s)>" % (self.__class__.__name__,
447
self.old_tree, self.new_tree, self.to_file, self.versioned,
448
self.show_ids, self.short, self.verbose, self.specific_files)
451
def _show_shelve_summary(params):
452
"""post_status hook to display a summary of shelves.
454
:param params: StatusHookParams.
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:
460
get_shelf_manager = getattr(params.new_tree, 'get_shelf_manager', None)
461
if get_shelf_manager is None:
463
manager = get_shelf_manager()
464
shelves = manager.active_shelves()
466
singular = '%d shelf exists. '
467
plural = '%d shelves exist. '
468
if len(shelves) == 1:
472
params.to_file.write(fmt % len(shelves))
473
params.to_file.write('See "bzr shelve --list" for details.\n')
476
hooks = StatusHooks()
479
hooks.install_named_hook('post_status', _show_shelve_summary,