~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/status.py

  • Committer: Andrew Bennetts
  • Date: 2010-08-17 06:45:33 UTC
  • mfrom: (5050.17.9 2.2)
  • mto: This revision was merged to the branch mainline in revision 5379.
  • Revision ID: andrew.bennetts@canonical.com-20100817064533-kof2i2f3r6mr4ayb
Merge lp:bzr/2.2 into lp:bzr, including fixes for #192859, #224373, #300062, #585667, #614404, #617503.

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,
22
21
    log,
23
22
    osutils,
24
23
    tsort,
34
33
def report_changes(to_file, old, new, specific_files, 
35
34
                   show_short_reporter, show_long_callback, 
36
35
                   short=False, want_unchanged=False, 
37
 
                   want_unversioned=False, show_ids=False, classify=True):
 
36
                   want_unversioned=False, show_ids=False):
38
37
    """Display summary of changes.
39
38
 
40
39
    This compares two trees with regards to a list of files, and delegates 
59
58
        files.
60
59
    :param show_ids: If set, includes each file's id.
61
60
    :param want_unversioned: If False, only shows versioned files.
62
 
    :param classify: Add special symbols to indicate file kind.
63
61
    """
64
62
 
65
63
    if short:
77
75
            delta.unversioned if not new.is_ignored(unversioned[0])]
78
76
        show_long_callback(to_file, delta, 
79
77
                           show_ids=show_ids,
80
 
                           show_unchanged=want_unchanged,
81
 
                           classify=classify)
 
78
                           show_unchanged=want_unchanged)
82
79
 
83
80
 
84
81
def show_tree_status(wt, show_unchanged=None,
90
87
                     short=False,
91
88
                     verbose=False,
92
89
                     versioned=False,
93
 
                     classify=True,
94
90
                     show_long_callback=_mod_delta.report_delta):
95
91
    """Display summary of changes.
96
92
 
120
116
    :param verbose: If True, show all merged revisions, not just
121
117
        the merge tips
122
118
    :param versioned: If True, only shows versioned files.
123
 
    :param classify: Add special symbols to indicate file kind.
124
119
    :param show_long_callback: A callback: message = show_long_callback(to_file, delta, 
125
120
        show_ids, show_unchanged, indent, filter), only used with the long output
126
121
    """
155
150
        old.lock_read()
156
151
        new.lock_read()
157
152
        try:
158
 
            for hook in hooks['pre_status']:
159
 
                hook(StatusHookParams(old, new, to_file, versioned,
160
 
                    show_ids, short, verbose))
161
 
 
162
153
            specific_files, nonexistents \
163
154
                = _filter_nonexistent(specific_files, old, new)
164
155
            want_unversioned = not versioned
165
156
 
166
157
            # Reporter used for short outputs
167
158
            reporter = _mod_delta._ChangeReporter(output_file=to_file,
168
 
                unversioned_filter=new.is_ignored, classify=classify)
 
159
                unversioned_filter=new.is_ignored)
169
160
            report_changes(to_file, old, new, specific_files, 
170
161
                           reporter, show_long_callback, 
171
162
                           short=short, want_unchanged=show_unchanged, 
172
 
                           want_unversioned=want_unversioned, show_ids=show_ids,
173
 
                           classify=classify)
 
163
                           want_unversioned=want_unversioned, show_ids=show_ids)
174
164
 
175
165
            # show the ignored files among specific files (i.e. show the files
176
166
            # identified from input that we choose to ignore). 
199
189
                    prefix = 'C  '
200
190
                else:
201
191
                    prefix = ' '
202
 
                to_file.write("%s %s\n" % (prefix, unicode(conflict)))
 
192
                to_file.write("%s %s\n" % (prefix, conflict))
203
193
            # Show files that were requested but don't exist (and are
204
194
            # not versioned).  We don't involve delta in this; these
205
195
            # paths are really the province of just the status
220
210
                show_pending_merges(new, to_file, short, verbose=verbose)
221
211
            if nonexistents:
222
212
                raise errors.PathsDoNotExist(nonexistents)
223
 
            for hook in hooks['post_status']:
224
 
                hook(StatusHookParams(old, new, to_file, versioned,
225
 
                    show_ids, short, verbose))
226
213
        finally:
227
214
            old.unlock()
228
215
            new.unlock()
369
356
    # their groups individually.  But for consistency of this
370
357
    # function's API, it's better to sort both than just 'nonexistent'.
371
358
    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