/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/status.py

  • Committer: Parth Malwankar
  • Date: 2010-09-14 13:26:02 UTC
  • mto: This revision was merged to the branch mainline in revision 5444.
  • Revision ID: parth.malwankar@gmail.com-20100914132602-yuryma2apcrb501s
fixed NEWS entry

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,
 
23
    shelf,
22
24
    osutils,
23
25
    tsort,
24
26
    revision as _mod_revision,
150
152
        old.lock_read()
151
153
        new.lock_read()
152
154
        try:
 
155
            for hook in hooks['pre_status']:
 
156
                hook(StatusHookParams(old, new, to_file, versioned,
 
157
                    show_ids, short, verbose))
 
158
 
153
159
            specific_files, nonexistents \
154
160
                = _filter_nonexistent(specific_files, old, new)
155
161
            want_unversioned = not versioned
210
216
                show_pending_merges(new, to_file, short, verbose=verbose)
211
217
            if nonexistents:
212
218
                raise errors.PathsDoNotExist(nonexistents)
 
219
            for hook in hooks['post_status']:
 
220
                hook(StatusHookParams(old, new, to_file, versioned,
 
221
                    show_ids, short, verbose))
213
222
        finally:
214
223
            old.unlock()
215
224
            new.unlock()
356
365
    # their groups individually.  But for consistency of this
357
366
    # function's API, it's better to sort both than just 'nonexistent'.
358
367
    return sorted(remaining), sorted(nonexistent)
 
368
 
 
369
 
 
370
class StatusHooks(_mod_hooks.Hooks):
 
371
    """A dictionary mapping hook name to a list of callables for status hooks.
 
372
 
 
373
    e.g. ['post_status'] Is the list of items to be called when the
 
374
    status command has finished printing the status.
 
375
    """
 
376
 
 
377
    def __init__(self):
 
378
        """Create the default hooks.
 
379
 
 
380
        These are all empty initially, because by default nothing should get
 
381
        notified.
 
382
        """
 
383
        _mod_hooks.Hooks.__init__(self)
 
384
        self.create_hook(_mod_hooks.HookPoint('post_status',
 
385
            "Called with argument StatusHookParams after Bazaar has "
 
386
            "displayed the status. StatusHookParams has the attributes "
 
387
            "(old_tree, new_tree, to_file, versioned, show_ids, short, "
 
388
            "verbose). The last four arguments correspond to the command "
 
389
            "line options specified by the user for the status command. "
 
390
            "to_file is the output stream for writing.",
 
391
            (2, 3), None))
 
392
        self.create_hook(_mod_hooks.HookPoint('pre_status',
 
393
            "Called with argument StatusHookParams before Bazaar "
 
394
            "displays the status. StatusHookParams has the attributes "
 
395
            "(old_tree, new_tree, to_file, versioned, show_ids, short, "
 
396
            "verbose). The last four arguments correspond to the command "
 
397
            "line options specified by the user for the status command. "
 
398
            "to_file is the output stream for writing.",
 
399
            (2, 3), None))
 
400
 
 
401
 
 
402
class StatusHookParams(object):
 
403
    """Object holding parameters passed to post_status hooks.
 
404
 
 
405
    :ivar old_tree: Start tree (basis tree) for comparison.
 
406
    :ivar new_tree: Working tree.
 
407
    :ivar to_file: If set, write to this file.
 
408
    :ivar versioned: Show only versioned files.
 
409
    :ivar show_ids: Show internal object ids.
 
410
    :ivar short: Use short status indicators.
 
411
    :ivar verbose: Verbose flag.
 
412
    """
 
413
 
 
414
    def __init__(self, old_tree, new_tree, to_file, versioned, show_ids,
 
415
            short, verbose):
 
416
        """Create a group of post_status hook parameters.
 
417
 
 
418
        :param old_tree: Start tree (basis tree) for comparison.
 
419
        :param new_tree: Working tree.
 
420
        :param to_file: If set, write to this file.
 
421
        :param versioned: Show only versioned files.
 
422
        :param show_ids: Show internal object ids.
 
423
        :param short: Use short status indicators.
 
424
        :param verbose: Verbose flag.
 
425
        """
 
426
        self.old_tree = old_tree
 
427
        self.new_tree = new_tree
 
428
        self.to_file = to_file
 
429
        self.versioned = versioned
 
430
        self.show_ids = show_ids
 
431
        self.short = short
 
432
        self.verbose = verbose
 
433
 
 
434
    def __eq__(self, other):
 
435
        return self.__dict__ == other.__dict__
 
436
 
 
437
    def __repr__(self):
 
438
        return "<%s(%s, %s, %s, %s, %s, %s, %s)>" % (self.__class__.__name__,
 
439
            self.old_tree, self.new_tree, self.to_file, self.versioned,
 
440
            self.show_ids, self.short, self.verbose)
 
441
 
 
442
 
 
443
def _show_shelve_summary(params):
 
444
    """post_status hook to display a summary of shelves.
 
445
 
 
446
    :param params: StatusHookParams.
 
447
    """
 
448
    shelves = shelf.list_shelves(params.new_tree)
 
449
    if shelves:
 
450
        params.to_file.write('%d shelves exist. '
 
451
            'See "bzr shelve --list" for details.\n' % len(shelves))
 
452
 
 
453
 
 
454
hooks = StatusHooks()
 
455
 
 
456
 
 
457
hooks.install_named_hook('post_status', _show_shelve_summary,
 
458
    'bzr status')
 
459