~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/info.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-03-16 14:01:20 UTC
  • mfrom: (3280.2.5 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20080316140120-i3yq8yr1l66m11h7
Start 1.4 development

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
 
#
 
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
__all__ = ['show_bzrdir_info']
18
18
 
19
 
from cStringIO import StringIO
20
19
import os
21
20
import time
22
21
import sys
25
24
    bzrdir,
26
25
    diff,
27
26
    errors,
28
 
    hooks as _mod_hooks,
29
27
    osutils,
30
28
    urlutils,
31
29
    )
32
30
from bzrlib.errors import (NoWorkingTree, NotBranchError,
33
31
                           NoRepositoryPresent, NotLocalUrl)
34
32
from bzrlib.missing import find_unmerged
 
33
from bzrlib.symbol_versioning import (deprecated_function,
 
34
        zero_eighteen)
35
35
 
36
36
 
37
37
def plural(n, base='', pl=None):
143
143
    locs.add_url('push branch', branch.get_push_location())
144
144
    locs.add_url('parent branch', branch.get_parent())
145
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
151
146
    return locs
152
147
 
153
148
 
263
258
 
264
259
    dir_cnt = 0
265
260
    for file_id in work_inv:
266
 
        if (work_inv.get_file_kind(file_id) == 'directory' and
 
261
        if (work_inv.get_file_kind(file_id) == 'directory' and 
267
262
            not work_inv.is_root(file_id)):
268
263
            dir_cnt += 1
269
264
    outfile.write('  %8d versioned %s\n' % (dir_cnt,
301
296
            'the repository.\n')
302
297
 
303
298
 
304
 
def _show_repository_stats(repository, stats, outfile):
 
299
def _show_repository_stats(stats, outfile):
305
300
    """Show statistics about a repository."""
306
 
    f = StringIO()
 
301
    if 'revisions' in stats or 'size' in stats:
 
302
        outfile.write('\n')
 
303
        outfile.write('Repository:\n')
307
304
    if 'revisions' in stats:
308
305
        revisions = stats['revisions']
309
 
        f.write('  %8d revision%s\n' % (revisions, plural(revisions)))
 
306
        outfile.write('  %8d revision%s\n' % (revisions, plural(revisions)))
310
307
    if 'size' in stats:
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())
 
308
        outfile.write('  %8d KiB\n' % (stats['size']/1024))
318
309
 
319
310
 
320
311
def show_bzrdir_info(a_bzrdir, verbose=False, outfile=None):
382
373
    elif branch is not None:
383
374
        _show_missing_revisions_branch(branch, outfile)
384
375
    if branch is not None:
385
 
        show_committers = verbose >= 2
386
 
        stats = _show_branch_stats(branch, show_committers, outfile)
 
376
        stats = _show_branch_stats(branch, verbose==2, outfile)
387
377
    else:
388
378
        stats = repository.gather_stats()
389
379
    if branch is None and working is None:
390
380
        _show_repository_info(repository, outfile)
391
 
    _show_repository_stats(repository, stats, outfile)
 
381
    _show_repository_stats(stats, outfile)
392
382
 
393
383
 
394
384
def describe_layout(repository=None, branch=None, tree=None):
478
468
        # do.
479
469
        candidates = new_candidates
480
470
    return ' or '.join(candidates)
481
 
 
482
 
 
483
 
class InfoHooks(_mod_hooks.Hooks):
484
 
    """Hooks for the info command."""
485
 
 
486
 
    def __init__(self):
487
 
        self.create_hook(_mod_hooks.HookPoint('repository',
488
 
            "Invoked when displaying the statistics for a repository. "
489
 
            "repository is called with a statistics dictionary as returned "
490
 
            "by the repository and a file-like object to write to.", (1, 15), 
491
 
            None))
492
 
 
493
 
 
494
 
hooks = InfoHooks()