~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/status.py

  • Committer: Andrew Bennetts
  • Date: 2010-10-08 08:15:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101008081514-dviqzrdfwyzsqbz2
Split NEWS into per-release doc/en/release-notes/bzr-*.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
16
16
 
17
 
from __future__ import absolute_import
18
 
 
19
17
import sys
20
18
 
21
19
from bzrlib import (
36
34
def report_changes(to_file, old, new, specific_files, 
37
35
                   show_short_reporter, show_long_callback, 
38
36
                   short=False, want_unchanged=False, 
39
 
                   want_unversioned=False, show_ids=False, classify=True):
 
37
                   want_unversioned=False, show_ids=False):
40
38
    """Display summary of changes.
41
39
 
42
40
    This compares two trees with regards to a list of files, and delegates 
61
59
        files.
62
60
    :param show_ids: If set, includes each file's id.
63
61
    :param want_unversioned: If False, only shows versioned files.
64
 
    :param classify: Add special symbols to indicate file kind.
65
62
    """
66
63
 
67
64
    if short:
79
76
            delta.unversioned if not new.is_ignored(unversioned[0])]
80
77
        show_long_callback(to_file, delta, 
81
78
                           show_ids=show_ids,
82
 
                           show_unchanged=want_unchanged,
83
 
                           classify=classify)
 
79
                           show_unchanged=want_unchanged)
84
80
 
85
81
 
86
82
def show_tree_status(wt, show_unchanged=None,
92
88
                     short=False,
93
89
                     verbose=False,
94
90
                     versioned=False,
95
 
                     classify=True,
96
91
                     show_long_callback=_mod_delta.report_delta):
97
92
    """Display summary of changes.
98
93
 
122
117
    :param verbose: If True, show all merged revisions, not just
123
118
        the merge tips
124
119
    :param versioned: If True, only shows versioned files.
125
 
    :param classify: Add special symbols to indicate file kind.
126
120
    :param show_long_callback: A callback: message = show_long_callback(to_file, delta, 
127
121
        show_ids, show_unchanged, indent, filter), only used with the long output
128
122
    """
159
153
        try:
160
154
            for hook in hooks['pre_status']:
161
155
                hook(StatusHookParams(old, new, to_file, versioned,
162
 
                    show_ids, short, verbose, specific_files=specific_files))
 
156
                    show_ids, short, verbose))
163
157
 
164
158
            specific_files, nonexistents \
165
159
                = _filter_nonexistent(specific_files, old, new)
167
161
 
168
162
            # Reporter used for short outputs
169
163
            reporter = _mod_delta._ChangeReporter(output_file=to_file,
170
 
                unversioned_filter=new.is_ignored, classify=classify)
 
164
                unversioned_filter=new.is_ignored)
171
165
            report_changes(to_file, old, new, specific_files, 
172
166
                           reporter, show_long_callback, 
173
167
                           short=short, want_unchanged=show_unchanged, 
174
 
                           want_unversioned=want_unversioned, show_ids=show_ids,
175
 
                           classify=classify)
 
168
                           want_unversioned=want_unversioned, show_ids=show_ids)
176
169
 
177
170
            # show the ignored files among specific files (i.e. show the files
178
171
            # identified from input that we choose to ignore). 
201
194
                    prefix = 'C  '
202
195
                else:
203
196
                    prefix = ' '
204
 
                to_file.write("%s %s\n" % (prefix, unicode(conflict)))
 
197
                to_file.write("%s %s\n" % (prefix, conflict))
205
198
            # Show files that were requested but don't exist (and are
206
199
            # not versioned).  We don't involve delta in this; these
207
200
            # paths are really the province of just the status
224
217
                raise errors.PathsDoNotExist(nonexistents)
225
218
            for hook in hooks['post_status']:
226
219
                hook(StatusHookParams(old, new, to_file, versioned,
227
 
                    show_ids, short, verbose, specific_files=specific_files))
 
220
                    show_ids, short, verbose))
228
221
        finally:
229
222
            old.unlock()
230
223
            new.unlock()
386
379
        These are all empty initially, because by default nothing should get
387
380
        notified.
388
381
        """
389
 
        _mod_hooks.Hooks.__init__(self, "bzrlib.status", "hooks")
390
 
        self.add_hook('post_status',
 
382
        _mod_hooks.Hooks.__init__(self)
 
383
        self.create_hook(_mod_hooks.HookPoint('post_status',
391
384
            "Called with argument StatusHookParams after Bazaar has "
392
385
            "displayed the status. StatusHookParams has the attributes "
393
386
            "(old_tree, new_tree, to_file, versioned, show_ids, short, "
394
387
            "verbose). The last four arguments correspond to the command "
395
388
            "line options specified by the user for the status command. "
396
389
            "to_file is the output stream for writing.",
397
 
            (2, 3))
398
 
        self.add_hook('pre_status',
 
390
            (2, 3), None))
 
391
        self.create_hook(_mod_hooks.HookPoint('pre_status',
399
392
            "Called with argument StatusHookParams before Bazaar "
400
393
            "displays the status. StatusHookParams has the attributes "
401
394
            "(old_tree, new_tree, to_file, versioned, show_ids, short, "
402
395
            "verbose). The last four arguments correspond to the command "
403
396
            "line options specified by the user for the status command. "
404
397
            "to_file is the output stream for writing.",
405
 
            (2, 3))
 
398
            (2, 3), None))
406
399
 
407
400
 
408
401
class StatusHookParams(object):
418
411
    """
419
412
 
420
413
    def __init__(self, old_tree, new_tree, to_file, versioned, show_ids,
421
 
            short, verbose, specific_files=None):
 
414
            short, verbose):
422
415
        """Create a group of post_status hook parameters.
423
416
 
424
417
        :param old_tree: Start tree (basis tree) for comparison.
428
421
        :param show_ids: Show internal object ids.
429
422
        :param short: Use short status indicators.
430
423
        :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.
434
424
        """
435
425
        self.old_tree = old_tree
436
426
        self.new_tree = new_tree
439
429
        self.show_ids = show_ids
440
430
        self.short = short
441
431
        self.verbose = verbose
442
 
        self.specific_files = specific_files
443
432
 
444
433
    def __eq__(self, other):
445
434
        return self.__dict__ == other.__dict__
446
435
 
447
436
    def __repr__(self):
448
 
        return "<%s(%s, %s, %s, %s, %s, %s, %s, %s)>" % (self.__class__.__name__,
 
437
        return "<%s(%s, %s, %s, %s, %s, %s, %s)>" % (self.__class__.__name__,
449
438
            self.old_tree, self.new_tree, self.to_file, self.versioned,
450
 
            self.show_ids, self.short, self.verbose, self.specific_files)
 
439
            self.show_ids, self.short, self.verbose)
451
440
 
452
441
 
453
442
def _show_shelve_summary(params):
455
444
 
456
445
    :param params: StatusHookParams.
457
446
    """
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:
461
 
        return
462
 
    get_shelf_manager = getattr(params.new_tree, 'get_shelf_manager', None)
463
 
    if get_shelf_manager is None:
464
 
        return
465
 
    manager = get_shelf_manager()
 
447
    manager = params.new_tree.get_shelf_manager()
466
448
    shelves = manager.active_shelves()
467
449
    if shelves:
468
 
        singular = '%d shelf exists. '
469
 
        plural = '%d shelves exist. '
470
 
        if len(shelves) == 1:
471
 
            fmt = singular
472
 
        else:
473
 
            fmt = plural
474
 
        params.to_file.write(fmt % len(shelves))
475
 
        params.to_file.write('See "bzr shelve --list" for details.\n')
 
450
        params.to_file.write('%d shelves exist. '
 
451
            'See "bzr shelve --list" for details.\n' % len(shelves))
476
452
 
477
453
 
478
454
hooks = StatusHooks()