19
19
from bzrlib import (
20
20
delta as _mod_delta,
25
25
revision as _mod_revision,
27
27
import bzrlib.errors as errors
28
from bzrlib.osutils import is_inside_any
29
from bzrlib.symbol_versioning import (deprecated_function,
28
31
from bzrlib.trace import mutter, warning
30
33
# TODO: when showing single-line logs, truncate to the width of the terminal
31
34
# if known, but only if really going to the terminal (not into a file)
34
def report_changes(to_file, old, new, specific_files,
35
show_short_reporter, show_long_callback,
36
short=False, want_unchanged=False,
37
want_unversioned=False, show_ids=False, classify=True):
38
"""Display summary of changes.
40
This compares two trees with regards to a list of files, and delegates
41
the display to underlying elements.
43
For short output, it creates an iterator on all changes, and lets a given
44
reporter display these changes.
46
For stantard output, it creates a delta of the changes, and forwards it
49
:param to_file: If set, write to this file (default stdout.)
50
:param old: Start tree for the comparison
51
:param end: End tree for the comparison
52
:param specific_files: If set, a list of filenames whose status should be
53
shown. It is an error to give a filename that is not in the working
54
tree, or in the working inventory or in the basis inventory.
55
:param show_short_reporter: Reporter in charge of display for short output
56
:param show_long_callback: Callback in charge of display for normal output
57
:param short: If True, gives short SVN-style status lines.
58
:param want_unchanged: Deprecated parameter. If set, includes unchanged
60
:param show_ids: If set, includes each file's id.
61
:param want_unversioned: If False, only shows versioned files.
62
:param classify: Add special symbols to indicate file kind.
66
changes = new.iter_changes(old, want_unchanged, specific_files,
67
require_versioned=False, want_unversioned=want_unversioned)
68
_mod_delta.report_changes(changes, show_short_reporter)
71
delta = new.changes_from(old, want_unchanged=want_unchanged,
72
specific_files=specific_files,
73
want_unversioned=want_unversioned)
74
# filter out unknown files. We may want a tree method for
76
delta.unversioned = [unversioned for unversioned in
77
delta.unversioned if not new.is_ignored(unversioned[0])]
78
show_long_callback(to_file, delta,
80
show_unchanged=want_unchanged,
84
37
def show_tree_status(wt, show_unchanged=None,
85
38
specific_files=None,
158
for hook in hooks['pre_status']:
159
hook(StatusHookParams(old, new, to_file, versioned,
160
show_ids, short, verbose, specific_files=specific_files))
162
106
specific_files, nonexistents \
163
107
= _filter_nonexistent(specific_files, old, new)
164
108
want_unversioned = not versioned
166
# Reporter used for short outputs
167
reporter = _mod_delta._ChangeReporter(output_file=to_file,
168
unversioned_filter=new.is_ignored, classify=classify)
169
report_changes(to_file, old, new, specific_files,
170
reporter, show_long_callback,
171
short=short, want_unchanged=show_unchanged,
172
want_unversioned=want_unversioned, show_ids=show_ids,
175
# show the ignored files among specific files (i.e. show the files
176
# identified from input that we choose to ignore).
177
if specific_files is not None:
178
# Ignored files is sorted because specific_files is already sorted
179
ignored_files = [specific for specific in
180
specific_files if new.is_ignored(specific)]
181
if len(ignored_files) > 0 and not short:
182
to_file.write("ignored:\n")
186
for ignored_file in ignored_files:
187
to_file.write("%s %s\n" % (prefix, ignored_file))
110
changes = new.iter_changes(old, show_unchanged, specific_files,
111
require_versioned=False, want_unversioned=want_unversioned)
112
reporter = _mod_delta._ChangeReporter(output_file=to_file,
113
unversioned_filter=new.is_ignored)
114
_mod_delta.report_changes(changes, reporter)
116
delta = new.changes_from(old, want_unchanged=show_unchanged,
117
specific_files=specific_files,
118
want_unversioned=want_unversioned)
119
# filter out unknown files. We may want a tree method for
121
delta.unversioned = [unversioned for unversioned in
122
delta.unversioned if not new.is_ignored(unversioned[0])]
125
show_unchanged=show_unchanged,
189
127
# show the new conflicts only for now. XXX: get them from the
191
129
conflicts = new.conflicts()
369
304
# their groups individually. But for consistency of this
370
305
# function's API, it's better to sort both than just 'nonexistent'.
371
306
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,