14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
from __future__ import absolute_import
21
19
from bzrlib import (
22
20
delta as _mod_delta,
27
25
revision as _mod_revision,
29
27
import bzrlib.errors as errors
28
from bzrlib.osutils import is_inside_any
29
from bzrlib.symbol_versioning import (deprecated_function,
30
31
from bzrlib.trace import mutter, warning
32
33
# TODO: when showing single-line logs, truncate to the width of the terminal
33
34
# if known, but only if really going to the terminal (not into a file)
36
def report_changes(to_file, old, new, specific_files,
37
show_short_reporter, show_long_callback,
38
short=False, want_unchanged=False,
39
want_unversioned=False, show_ids=False, classify=True):
40
"""Display summary of changes.
42
This compares two trees with regards to a list of files, and delegates
43
the display to underlying elements.
45
For short output, it creates an iterator on all changes, and lets a given
46
reporter display these changes.
48
For stantard output, it creates a delta of the changes, and forwards it
51
:param to_file: If set, write to this file (default stdout.)
52
:param old: Start tree for the comparison
53
:param end: End tree for the comparison
54
:param specific_files: If set, a list of filenames whose status should be
55
shown. It is an error to give a filename that is not in the working
56
tree, or in the working inventory or in the basis inventory.
57
:param show_short_reporter: Reporter in charge of display for short output
58
:param show_long_callback: Callback in charge of display for normal output
59
:param short: If True, gives short SVN-style status lines.
60
:param want_unchanged: Deprecated parameter. If set, includes unchanged
62
:param show_ids: If set, includes each file's id.
63
:param want_unversioned: If False, only shows versioned files.
64
:param classify: Add special symbols to indicate file kind.
68
changes = new.iter_changes(old, want_unchanged, specific_files,
69
require_versioned=False, want_unversioned=want_unversioned)
70
_mod_delta.report_changes(changes, show_short_reporter)
73
delta = new.changes_from(old, want_unchanged=want_unchanged,
74
specific_files=specific_files,
75
want_unversioned=want_unversioned)
76
# filter out unknown files. We may want a tree method for
78
delta.unversioned = [unversioned for unversioned in
79
delta.unversioned if not new.is_ignored(unversioned[0])]
80
show_long_callback(to_file, delta,
82
show_unchanged=want_unchanged,
86
37
def show_tree_status(wt, show_unchanged=None,
87
38
specific_files=None,
160
for hook in hooks['pre_status']:
161
hook(StatusHookParams(old, new, to_file, versioned,
162
show_ids, short, verbose, specific_files=specific_files))
164
106
specific_files, nonexistents \
165
107
= _filter_nonexistent(specific_files, old, new)
166
108
want_unversioned = not versioned
168
# Reporter used for short outputs
169
reporter = _mod_delta._ChangeReporter(output_file=to_file,
170
unversioned_filter=new.is_ignored, classify=classify)
171
report_changes(to_file, old, new, specific_files,
172
reporter, show_long_callback,
173
short=short, want_unchanged=show_unchanged,
174
want_unversioned=want_unversioned, show_ids=show_ids,
177
# show the ignored files among specific files (i.e. show the files
178
# identified from input that we choose to ignore).
179
if specific_files is not None:
180
# Ignored files is sorted because specific_files is already sorted
181
ignored_files = [specific for specific in
182
specific_files if new.is_ignored(specific)]
183
if len(ignored_files) > 0 and not short:
184
to_file.write("ignored:\n")
188
for ignored_file in ignored_files:
189
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,
191
127
# show the new conflicts only for now. XXX: get them from the
193
129
conflicts = new.conflicts()
371
298
# their groups individually. But for consistency of this
372
299
# function's API, it's better to sort both than just 'nonexistent'.
373
300
return sorted(remaining), sorted(nonexistent)
376
class StatusHooks(_mod_hooks.Hooks):
377
"""A dictionary mapping hook name to a list of callables for status hooks.
379
e.g. ['post_status'] Is the list of items to be called when the
380
status command has finished printing the status.
384
"""Create the default hooks.
386
These are all empty initially, because by default nothing should get
389
_mod_hooks.Hooks.__init__(self, "bzrlib.status", "hooks")
390
self.add_hook('post_status',
391
"Called with argument StatusHookParams after Bazaar has "
392
"displayed the status. StatusHookParams has the attributes "
393
"(old_tree, new_tree, to_file, versioned, show_ids, short, "
394
"verbose). The last four arguments correspond to the command "
395
"line options specified by the user for the status command. "
396
"to_file is the output stream for writing.",
398
self.add_hook('pre_status',
399
"Called with argument StatusHookParams before Bazaar "
400
"displays the status. StatusHookParams has the attributes "
401
"(old_tree, new_tree, to_file, versioned, show_ids, short, "
402
"verbose). The last four arguments correspond to the command "
403
"line options specified by the user for the status command. "
404
"to_file is the output stream for writing.",
408
class StatusHookParams(object):
409
"""Object holding parameters passed to post_status hooks.
411
:ivar old_tree: Start tree (basis tree) for comparison.
412
:ivar new_tree: Working tree.
413
:ivar to_file: If set, write to this file.
414
:ivar versioned: Show only versioned files.
415
:ivar show_ids: Show internal object ids.
416
:ivar short: Use short status indicators.
417
:ivar verbose: Verbose flag.
420
def __init__(self, old_tree, new_tree, to_file, versioned, show_ids,
421
short, verbose, specific_files=None):
422
"""Create a group of post_status hook parameters.
424
:param old_tree: Start tree (basis tree) for comparison.
425
:param new_tree: Working tree.
426
:param to_file: If set, write to this file.
427
:param versioned: Show only versioned files.
428
:param show_ids: Show internal object ids.
429
:param short: Use short status indicators.
430
:param verbose: Verbose flag.
431
:param specific_files: If set, a list of filenames whose status should be
432
shown. It is an error to give a filename that is not in the working
433
tree, or in the working inventory or in the basis inventory.
435
self.old_tree = old_tree
436
self.new_tree = new_tree
437
self.to_file = to_file
438
self.versioned = versioned
439
self.show_ids = show_ids
441
self.verbose = verbose
442
self.specific_files = specific_files
444
def __eq__(self, other):
445
return self.__dict__ == other.__dict__
448
return "<%s(%s, %s, %s, %s, %s, %s, %s, %s)>" % (self.__class__.__name__,
449
self.old_tree, self.new_tree, self.to_file, self.versioned,
450
self.show_ids, self.short, self.verbose, self.specific_files)
453
def _show_shelve_summary(params):
454
"""post_status hook to display a summary of shelves.
456
:param params: StatusHookParams.
458
# Don't show shelves if status of specific files is being shown, only if
459
# no file arguments have been passed
460
if params.specific_files:
462
get_shelf_manager = getattr(params.new_tree, 'get_shelf_manager', None)
463
if get_shelf_manager is None:
465
manager = get_shelf_manager()
466
shelves = manager.active_shelves()
468
singular = '%d shelf exists. '
469
plural = '%d shelves exist. '
470
if len(shelves) == 1:
474
params.to_file.write(fmt % len(shelves))
475
params.to_file.write('See "bzr shelve --list" for details.\n')
478
hooks = StatusHooks()
481
hooks.install_named_hook('post_status', _show_shelve_summary,