~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/info.py

  • Committer: Robert Collins
  • Date: 2010-04-08 04:34:03 UTC
  • mfrom: (5138 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5139.
  • Revision ID: robertc@robertcollins.net-20100408043403-56z0d07vdqrx7f3t
Update bugfix for 528114 to trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
 
 
1
# Copyright (C) 2005-2010 Canonical Ltd
 
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
__all__ = ['show_bzrdir_info']
18
18
 
 
19
from cStringIO import StringIO
19
20
import os
20
21
import time
21
22
import sys
24
25
    bzrdir,
25
26
    diff,
26
27
    errors,
 
28
    hooks as _mod_hooks,
27
29
    osutils,
28
30
    urlutils,
29
31
    )
141
143
    locs.add_url('push branch', branch.get_push_location())
142
144
    locs.add_url('parent branch', branch.get_parent())
143
145
    locs.add_url('submit branch', branch.get_submit_branch())
 
146
    try:
 
147
        locs.add_url('stacked on', branch.get_stacked_on_url())
 
148
    except (errors.UnstackableBranchFormat, errors.UnstackableRepositoryFormat,
 
149
        errors.NotStacked):
 
150
        pass
144
151
    return locs
145
152
 
146
153
 
256
263
 
257
264
    dir_cnt = 0
258
265
    for file_id in work_inv:
259
 
        if (work_inv.get_file_kind(file_id) == 'directory' and 
 
266
        if (work_inv.get_file_kind(file_id) == 'directory' and
260
267
            not work_inv.is_root(file_id)):
261
268
            dir_cnt += 1
262
269
    outfile.write('  %8d versioned %s\n' % (dir_cnt,
294
301
            'the repository.\n')
295
302
 
296
303
 
297
 
def _show_repository_stats(stats, outfile):
 
304
def _show_repository_stats(repository, stats, outfile):
298
305
    """Show statistics about a repository."""
299
 
    if 'revisions' in stats or 'size' in stats:
300
 
        outfile.write('\n')
301
 
        outfile.write('Repository:\n')
 
306
    f = StringIO()
302
307
    if 'revisions' in stats:
303
308
        revisions = stats['revisions']
304
 
        outfile.write('  %8d revision%s\n' % (revisions, plural(revisions)))
 
309
        f.write('  %8d revision%s\n' % (revisions, plural(revisions)))
305
310
    if 'size' in stats:
306
 
        outfile.write('  %8d KiB\n' % (stats['size']/1024))
 
311
        f.write('  %8d KiB\n' % (stats['size']/1024))
 
312
    for hook in hooks['repository']:
 
313
        hook(repository, stats, f)
 
314
    if f.getvalue() != "":
 
315
        outfile.write('\n')
 
316
        outfile.write('Repository:\n')
 
317
        outfile.write(f.getvalue())
307
318
 
308
319
 
309
320
def show_bzrdir_info(a_bzrdir, verbose=False, outfile=None):
371
382
    elif branch is not None:
372
383
        _show_missing_revisions_branch(branch, outfile)
373
384
    if branch is not None:
374
 
        stats = _show_branch_stats(branch, verbose==2, outfile)
 
385
        show_committers = verbose >= 2
 
386
        stats = _show_branch_stats(branch, show_committers, outfile)
375
387
    else:
376
388
        stats = repository.gather_stats()
377
389
    if branch is None and working is None:
378
390
        _show_repository_info(repository, outfile)
379
 
    _show_repository_stats(stats, outfile)
 
391
    _show_repository_stats(repository, stats, outfile)
380
392
 
381
393
 
382
394
def describe_layout(repository=None, branch=None, tree=None):
466
478
        # do.
467
479
        candidates = new_candidates
468
480
    return ' or '.join(candidates)
 
481
 
 
482
 
 
483
class InfoHooks(_mod_hooks.Hooks):
 
484
    """Hooks for the info command."""
 
485
 
 
486
    def __init__(self):
 
487
        super(InfoHooks, self).__init__()
 
488
        self.create_hook(_mod_hooks.HookPoint('repository',
 
489
            "Invoked when displaying the statistics for a repository. "
 
490
            "repository is called with a statistics dictionary as returned "
 
491
            "by the repository and a file-like object to write to.", (1, 15), 
 
492
            None))
 
493
 
 
494
 
 
495
hooks = InfoHooks()