~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/info.py

  • Committer: Ian Clatworthy
  • Date: 2007-12-11 02:07:30 UTC
  • mto: (3119.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 3120.
  • Revision ID: ian.clatworthy@internode.on.net-20071211020730-sdj4kj794dw0628e
make help topics more discoverable

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
2
 
#
 
1
# Copyright (C) 2005, 2006, 2007 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., 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
 
19
import os
20
20
import time
21
21
import sys
22
22
 
23
23
from bzrlib import (
24
24
    bzrdir,
 
25
    diff,
25
26
    errors,
26
 
    hooks as _mod_hooks,
27
27
    osutils,
28
28
    urlutils,
29
29
    )
30
30
from bzrlib.errors import (NoWorkingTree, NotBranchError,
31
31
                           NoRepositoryPresent, NotLocalUrl)
32
32
from bzrlib.missing import find_unmerged
 
33
from bzrlib.symbol_versioning import (deprecated_function,
 
34
        zero_eighteen)
33
35
 
34
36
 
35
37
def plural(n, base='', pl=None):
78
80
 
79
81
def gather_location_info(repository, branch=None, working=None):
80
82
    locs = {}
81
 
    repository_path = repository.user_url
 
83
    repository_path = repository.bzrdir.root_transport.base
82
84
    if branch is not None:
83
 
        branch_path = branch.user_url
 
85
        branch_path = branch.bzrdir.root_transport.base
84
86
        master_path = branch.get_bound_location()
85
87
        if master_path is None:
86
88
            master_path = branch_path
88
90
        branch_path = None
89
91
        master_path = None
90
92
    if working:
91
 
        working_path = working.user_url
 
93
        working_path = working.bzrdir.root_transport.base
92
94
        if working_path != branch_path:
93
95
            locs['light checkout root'] = working_path
94
96
        if master_path != branch_path:
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())
144
 
    try:
145
 
        locs.add_url('stacked on', branch.get_stacked_on_url())
146
 
    except (errors.UnstackableBranchFormat, errors.UnstackableRepositoryFormat,
147
 
        errors.NotStacked):
148
 
        pass
149
146
    return locs
150
147
 
151
148
 
261
258
 
262
259
    dir_cnt = 0
263
260
    for file_id in work_inv:
264
 
        if (work_inv.get_file_kind(file_id) == 'directory' and
 
261
        if (work_inv.get_file_kind(file_id) == 'directory' and 
265
262
            not work_inv.is_root(file_id)):
266
263
            dir_cnt += 1
267
264
    outfile.write('  %8d versioned %s\n' % (dir_cnt,
299
296
            'the repository.\n')
300
297
 
301
298
 
302
 
def _show_repository_stats(repository, stats, outfile):
 
299
def _show_repository_stats(stats, outfile):
303
300
    """Show statistics about a repository."""
304
 
    f = StringIO()
 
301
    if 'revisions' in stats or 'size' in stats:
 
302
        outfile.write('\n')
 
303
        outfile.write('Repository:\n')
305
304
    if 'revisions' in stats:
306
305
        revisions = stats['revisions']
307
 
        f.write('  %8d revision%s\n' % (revisions, plural(revisions)))
 
306
        outfile.write('  %8d revision%s\n' % (revisions, plural(revisions)))
308
307
    if 'size' in stats:
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())
 
308
        outfile.write('  %8d KiB\n' % (stats['size']/1024))
316
309
 
317
310
 
318
311
def show_bzrdir_info(a_bzrdir, verbose=False, outfile=None):
380
373
    elif branch is not None:
381
374
        _show_missing_revisions_branch(branch, outfile)
382
375
    if branch is not None:
383
 
        show_committers = verbose >= 2
384
 
        stats = _show_branch_stats(branch, show_committers, outfile)
 
376
        stats = _show_branch_stats(branch, verbose==2, outfile)
385
377
    else:
386
378
        stats = repository.gather_stats()
387
379
    if branch is None and working is None:
388
380
        _show_repository_info(repository, outfile)
389
 
    _show_repository_stats(repository, stats, outfile)
 
381
    _show_repository_stats(stats, outfile)
390
382
 
391
383
 
392
384
def describe_layout(repository=None, branch=None, tree=None):
418
410
        if branch is None and tree is not None:
419
411
            phrase = "branchless tree"
420
412
        else:
421
 
            if (tree is not None and tree.user_url !=
422
 
                branch.user_url):
 
413
            if (tree is not None and tree.bzrdir.root_transport.base !=
 
414
                branch.bzrdir.root_transport.base):
423
415
                independence = ''
424
416
                phrase = "Lightweight checkout"
425
417
            elif branch.get_bound_location() is not None:
444
436
    """
445
437
    candidates  = []
446
438
    if (branch is not None and tree is not None and
447
 
        branch.user_url != tree.user_url):
 
439
        branch.bzrdir.root_transport.base !=
 
440
        tree.bzrdir.root_transport.base):
448
441
        branch = None
449
442
        repository = None
450
 
    non_aliases = set(bzrdir.format_registry.keys())
451
 
    non_aliases.difference_update(bzrdir.format_registry.aliases())
452
 
    for key in non_aliases:
 
443
    for key in bzrdir.format_registry.keys():
453
444
        format = bzrdir.format_registry.make_bzrdir(key)
454
445
        if isinstance(format, bzrdir.BzrDirMetaFormat1):
455
446
            if (tree and format.workingtree_format !=
466
457
        candidates.append(key)
467
458
    if len(candidates) == 0:
468
459
        return 'unnamed'
469
 
    candidates.sort()
 
460
    new_candidates = [c for c in candidates if c != 'default']
 
461
    if len(new_candidates) > 0:
 
462
        candidates = new_candidates
470
463
    new_candidates = [c for c in candidates if not
471
464
        bzrdir.format_registry.get_info(c).hidden]
472
465
    if len(new_candidates) > 0:
473
 
        # If there are any non-hidden formats that match, only return those to
474
 
        # avoid listing hidden formats except when only a hidden format will
475
 
        # do.
476
466
        candidates = new_candidates
477
467
    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()