~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: 2010-07-07 04:03:32 UTC
  • mfrom: (5335.2.3 doc)
  • Revision ID: pqm@pqm.ubuntu.com-20100707040332-we60v2hsd39rumlr
(mbp) developer docs about testing (Martin Pool)

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
 
import os
 
19
from cStringIO import StringIO
20
20
import time
21
21
import sys
22
22
 
23
23
from bzrlib import (
24
24
    bzrdir,
25
 
    diff,
26
25
    errors,
 
26
    hooks as _mod_hooks,
27
27
    osutils,
28
28
    urlutils,
29
29
    )
78
78
 
79
79
def gather_location_info(repository, branch=None, working=None):
80
80
    locs = {}
81
 
    repository_path = repository.bzrdir.root_transport.base
 
81
    repository_path = repository.user_url
82
82
    if branch is not None:
83
 
        branch_path = branch.bzrdir.root_transport.base
 
83
        branch_path = branch.user_url
84
84
        master_path = branch.get_bound_location()
85
85
        if master_path is None:
86
86
            master_path = branch_path
88
88
        branch_path = None
89
89
        master_path = None
90
90
    if working:
91
 
        working_path = working.bzrdir.root_transport.base
 
91
        working_path = working.user_url
92
92
        if working_path != branch_path:
93
93
            locs['light checkout root'] = working_path
94
94
        if master_path != branch_path:
261
261
 
262
262
    dir_cnt = 0
263
263
    for file_id in work_inv:
264
 
        if (work_inv.get_file_kind(file_id) == 'directory' and 
 
264
        if (work_inv.get_file_kind(file_id) == 'directory' and
265
265
            not work_inv.is_root(file_id)):
266
266
            dir_cnt += 1
267
267
    outfile.write('  %8d versioned %s\n' % (dir_cnt,
299
299
            'the repository.\n')
300
300
 
301
301
 
302
 
def _show_repository_stats(stats, outfile):
 
302
def _show_repository_stats(repository, stats, outfile):
303
303
    """Show statistics about a repository."""
304
 
    if 'revisions' in stats or 'size' in stats:
305
 
        outfile.write('\n')
306
 
        outfile.write('Repository:\n')
 
304
    f = StringIO()
307
305
    if 'revisions' in stats:
308
306
        revisions = stats['revisions']
309
 
        outfile.write('  %8d revision%s\n' % (revisions, plural(revisions)))
 
307
        f.write('  %8d revision%s\n' % (revisions, plural(revisions)))
310
308
    if 'size' in stats:
311
 
        outfile.write('  %8d KiB\n' % (stats['size']/1024))
 
309
        f.write('  %8d KiB\n' % (stats['size']/1024))
 
310
    for hook in hooks['repository']:
 
311
        hook(repository, stats, f)
 
312
    if f.getvalue() != "":
 
313
        outfile.write('\n')
 
314
        outfile.write('Repository:\n')
 
315
        outfile.write(f.getvalue())
312
316
 
313
317
 
314
318
def show_bzrdir_info(a_bzrdir, verbose=False, outfile=None):
376
380
    elif branch is not None:
377
381
        _show_missing_revisions_branch(branch, outfile)
378
382
    if branch is not None:
379
 
        stats = _show_branch_stats(branch, verbose==2, outfile)
 
383
        show_committers = verbose >= 2
 
384
        stats = _show_branch_stats(branch, show_committers, outfile)
380
385
    else:
381
386
        stats = repository.gather_stats()
382
387
    if branch is None and working is None:
383
388
        _show_repository_info(repository, outfile)
384
 
    _show_repository_stats(stats, outfile)
 
389
    _show_repository_stats(repository, stats, outfile)
385
390
 
386
391
 
387
392
def describe_layout(repository=None, branch=None, tree=None):
413
418
        if branch is None and tree is not None:
414
419
            phrase = "branchless tree"
415
420
        else:
416
 
            if (tree is not None and tree.bzrdir.root_transport.base !=
417
 
                branch.bzrdir.root_transport.base):
 
421
            if (tree is not None and tree.user_url !=
 
422
                branch.user_url):
418
423
                independence = ''
419
424
                phrase = "Lightweight checkout"
420
425
            elif branch.get_bound_location() is not None:
439
444
    """
440
445
    candidates  = []
441
446
    if (branch is not None and tree is not None and
442
 
        branch.bzrdir.root_transport.base !=
443
 
        tree.bzrdir.root_transport.base):
 
447
        branch.user_url != tree.user_url):
444
448
        branch = None
445
449
        repository = None
446
450
    non_aliases = set(bzrdir.format_registry.keys())
471
475
        # do.
472
476
        candidates = new_candidates
473
477
    return ' or '.join(candidates)
 
478
 
 
479
 
 
480
class InfoHooks(_mod_hooks.Hooks):
 
481
    """Hooks for the info command."""
 
482
 
 
483
    def __init__(self):
 
484
        super(InfoHooks, self).__init__()
 
485
        self.create_hook(_mod_hooks.HookPoint('repository',
 
486
            "Invoked when displaying the statistics for a repository. "
 
487
            "repository is called with a statistics dictionary as returned "
 
488
            "by the repository and a file-like object to write to.", (1, 15), 
 
489
            None))
 
490
 
 
491
 
 
492
hooks = InfoHooks()