~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/status.py

  • Committer: Patch Queue Manager
  • Date: 2011-10-14 16:54:26 UTC
  • mfrom: (6216.1.1 remove-this-file)
  • Revision ID: pqm@pqm.ubuntu.com-20111014165426-tjix4e6idryf1r2z
(jelmer) Remove an accidentally committed .THIS file. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
from bzrlib import (
20
20
    delta as _mod_delta,
 
21
    hooks as _mod_hooks,
21
22
    log,
22
23
    osutils,
23
24
    tsort,
33
34
def report_changes(to_file, old, new, specific_files, 
34
35
                   show_short_reporter, show_long_callback, 
35
36
                   short=False, want_unchanged=False, 
36
 
                   want_unversioned=False, show_ids=False):
 
37
                   want_unversioned=False, show_ids=False, classify=True):
37
38
    """Display summary of changes.
38
39
 
39
40
    This compares two trees with regards to a list of files, and delegates 
58
59
        files.
59
60
    :param show_ids: If set, includes each file's id.
60
61
    :param want_unversioned: If False, only shows versioned files.
 
62
    :param classify: Add special symbols to indicate file kind.
61
63
    """
62
64
 
63
65
    if short:
75
77
            delta.unversioned if not new.is_ignored(unversioned[0])]
76
78
        show_long_callback(to_file, delta, 
77
79
                           show_ids=show_ids,
78
 
                           show_unchanged=want_unchanged)
 
80
                           show_unchanged=want_unchanged,
 
81
                           classify=classify)
79
82
 
80
83
 
81
84
def show_tree_status(wt, show_unchanged=None,
87
90
                     short=False,
88
91
                     verbose=False,
89
92
                     versioned=False,
 
93
                     classify=True,
90
94
                     show_long_callback=_mod_delta.report_delta):
91
95
    """Display summary of changes.
92
96
 
116
120
    :param verbose: If True, show all merged revisions, not just
117
121
        the merge tips
118
122
    :param versioned: If True, only shows versioned files.
 
123
    :param classify: Add special symbols to indicate file kind.
119
124
    :param show_long_callback: A callback: message = show_long_callback(to_file, delta, 
120
125
        show_ids, show_unchanged, indent, filter), only used with the long output
121
126
    """
150
155
        old.lock_read()
151
156
        new.lock_read()
152
157
        try:
 
158
            for hook in hooks['pre_status']:
 
159
                hook(StatusHookParams(old, new, to_file, versioned,
 
160
                    show_ids, short, verbose))
 
161
 
153
162
            specific_files, nonexistents \
154
163
                = _filter_nonexistent(specific_files, old, new)
155
164
            want_unversioned = not versioned
156
165
 
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,
 
173
                           classify=classify)
164
174
 
165
175
            # show the ignored files among specific files (i.e. show the files
166
176
            # identified from input that we choose to ignore). 
189
199
                    prefix = 'C  '
190
200
                else:
191
201
                    prefix = ' '
192
 
                to_file.write("%s %s\n" % (prefix, conflict))
 
202
                to_file.write("%s %s\n" % (prefix, unicode(conflict)))
193
203
            # Show files that were requested but don't exist (and are
194
204
            # not versioned).  We don't involve delta in this; these
195
205
            # paths are really the province of just the status
210
220
                show_pending_merges(new, to_file, short, verbose=verbose)
211
221
            if nonexistents:
212
222
                raise errors.PathsDoNotExist(nonexistents)
 
223
            for hook in hooks['post_status']:
 
224
                hook(StatusHookParams(old, new, to_file, versioned,
 
225
                    show_ids, short, verbose))
213
226
        finally:
214
227
            old.unlock()
215
228
            new.unlock()
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)
 
372
 
 
373
 
 
374
class StatusHooks(_mod_hooks.Hooks):
 
375
    """A dictionary mapping hook name to a list of callables for status hooks.
 
376
 
 
377
    e.g. ['post_status'] Is the list of items to be called when the
 
378
    status command has finished printing the status.
 
379
    """
 
380
 
 
381
    def __init__(self):
 
382
        """Create the default hooks.
 
383
 
 
384
        These are all empty initially, because by default nothing should get
 
385
        notified.
 
386
        """
 
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.",
 
395
            (2, 3))
 
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.",
 
403
            (2, 3))
 
404
 
 
405
 
 
406
class StatusHookParams(object):
 
407
    """Object holding parameters passed to post_status hooks.
 
408
 
 
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.
 
416
    """
 
417
 
 
418
    def __init__(self, old_tree, new_tree, to_file, versioned, show_ids,
 
419
            short, verbose):
 
420
        """Create a group of post_status hook parameters.
 
421
 
 
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
        """
 
430
        self.old_tree = old_tree
 
431
        self.new_tree = new_tree
 
432
        self.to_file = to_file
 
433
        self.versioned = versioned
 
434
        self.show_ids = show_ids
 
435
        self.short = short
 
436
        self.verbose = verbose
 
437
 
 
438
    def __eq__(self, other):
 
439
        return self.__dict__ == other.__dict__
 
440
 
 
441
    def __repr__(self):
 
442
        return "<%s(%s, %s, %s, %s, %s, %s, %s)>" % (self.__class__.__name__,
 
443
            self.old_tree, self.new_tree, self.to_file, self.versioned,
 
444
            self.show_ids, self.short, self.verbose)
 
445
 
 
446
 
 
447
def _show_shelve_summary(params):
 
448
    """post_status hook to display a summary of shelves.
 
449
 
 
450
    :param params: StatusHookParams.
 
451
    """
 
452
    get_shelf_manager = getattr(params.new_tree, 'get_shelf_manager', None)
 
453
    if get_shelf_manager is None:
 
454
        return
 
455
    manager = get_shelf_manager()
 
456
    shelves = manager.active_shelves()
 
457
    if shelves:
 
458
        singular = '%d shelf exists. '
 
459
        plural = '%d shelves exist. '
 
460
        if len(shelves) == 1:
 
461
            fmt = singular
 
462
        else:
 
463
            fmt = plural
 
464
        params.to_file.write(fmt % len(shelves))
 
465
        params.to_file.write('See "bzr shelve --list" for details.\n')
 
466
 
 
467
 
 
468
hooks = StatusHooks()
 
469
 
 
470
 
 
471
hooks.install_named_hook('post_status', _show_shelve_summary,
 
472
    'bzr status')
 
473