356
364
# their groups individually. But for consistency of this
357
365
# function's API, it's better to sort both than just 'nonexistent'.
358
366
return sorted(remaining), sorted(nonexistent)
369
class StatusHooks(_mod_hooks.Hooks):
370
"""A dictionary mapping hook name to a list of callables for status hooks.
372
e.g. ['post_status'] Is the list of items to be called when the
373
status command has finished printing the status.
377
"""Create the default hooks.
379
These are all empty initially, because by default nothing should get
382
_mod_hooks.Hooks.__init__(self)
383
self.create_hook(_mod_hooks.HookPoint('post_status',
384
"Called with argument StatusHookParams after Bazaar has "
385
"displayed the status. StatusHookParams has the attributes "
386
"(old_tree, new_tree, to_file, versioned, show_ids, short, "
387
"verbose). The last four arguments correspond to the command "
388
"line options specified by the user for the status command. "
389
"to_file is the output stream for writing.",
391
self.create_hook(_mod_hooks.HookPoint('pre_status',
392
"Called with argument StatusHookParams before Bazaar "
393
"displays the status. StatusHookParams has the attributes "
394
"(old_tree, new_tree, to_file, versioned, show_ids, short, "
395
"verbose). The last four arguments correspond to the command "
396
"line options specified by the user for the status command. "
397
"to_file is the output stream for writing.",
401
class StatusHookParams(object):
402
"""Object holding parameters passed to post_status hooks.
404
:ivar old_tree: Start tree (basis tree) for comparison.
405
:ivar new_tree: Working tree.
406
:ivar to_file: If set, write to this file.
407
:ivar versioned: Show only versioned files.
408
:ivar show_ids: Show internal object ids.
409
:ivar short: Use short status indicators.
410
:ivar verbose: Verbose flag.
413
def __init__(self, old_tree, new_tree, to_file, versioned, show_ids,
415
"""Create a group of post_status hook parameters.
417
:param old_tree: Start tree (basis tree) for comparison.
418
:param new_tree: Working tree.
419
:param to_file: If set, write to this file.
420
:param versioned: Show only versioned files.
421
:param show_ids: Show internal object ids.
422
:param short: Use short status indicators.
423
:param verbose: Verbose flag.
425
self.old_tree = old_tree
426
self.new_tree = new_tree
427
self.to_file = to_file
428
self.versioned = versioned
429
self.show_ids = show_ids
431
self.verbose = verbose
433
def __eq__(self, other):
434
return self.__dict__ == other.__dict__
437
return "<%s(%s, %s, %s, %s, %s, %s, %s)>" % (self.__class__.__name__,
438
self.old_tree, self.new_tree, self.to_file, self.versioned,
439
self.show_ids, self.short, self.verbose)
442
def _show_shelve_summary(params):
443
"""post_status hook to display a summary of shelves.
445
:param params: StatusHookParams.
447
get_shelf_manager = getattr(params.new_tree, 'get_shelf_manager', None)
448
if get_shelf_manager is None:
450
manager = get_shelf_manager()
451
shelves = manager.active_shelves()
453
singular = '%d shelf exists. '
454
plural = '%d shelves exist. '
455
if len(shelves) == 1:
459
params.to_file.write(fmt % len(shelves))
460
params.to_file.write('See "bzr shelve --list" for details.\n')
463
hooks = StatusHooks()
466
hooks.install_named_hook('post_status', _show_shelve_summary,