~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/info.py

  • Committer: John Arbash Meinel
  • Date: 2011-05-11 11:35:28 UTC
  • mto: This revision was merged to the branch mainline in revision 5851.
  • Revision ID: john@arbash-meinel.com-20110511113528-qepibuwxicjrbb2h
Break compatibility with python <2.6.

This includes auditing the code for places where we were doing
explicit 'sys.version' checks and removing them as appropriate.

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
    )
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)
35
33
 
36
34
 
37
35
def plural(n, base='', pl=None):
80
78
 
81
79
def gather_location_info(repository, branch=None, working=None):
82
80
    locs = {}
83
 
    repository_path = repository.bzrdir.root_transport.base
 
81
    repository_path = repository.user_url
84
82
    if branch is not None:
85
 
        branch_path = branch.bzrdir.root_transport.base
 
83
        branch_path = branch.user_url
86
84
        master_path = branch.get_bound_location()
87
85
        if master_path is None:
88
86
            master_path = branch_path
90
88
        branch_path = None
91
89
        master_path = None
92
90
    if working:
93
 
        working_path = working.bzrdir.root_transport.base
 
91
        working_path = working.user_url
94
92
        if working_path != branch_path:
95
93
            locs['light checkout root'] = working_path
96
94
        if master_path != branch_path:
143
141
    locs.add_url('push branch', branch.get_push_location())
144
142
    locs.add_url('parent branch', branch.get_parent())
145
143
    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
146
149
    return locs
147
150
 
148
151
 
218
221
    """Show missing revisions in working tree."""
219
222
    branch = working.branch
220
223
    basis = working.basis_tree()
221
 
    work_inv = working.inventory
222
224
    branch_revno, branch_last_revision = branch.last_revision_info()
223
225
    try:
224
226
        tree_last_id = working.get_parent_ids()[0]
236
238
def _show_working_stats(working, outfile):
237
239
    """Show statistics about a working tree."""
238
240
    basis = working.basis_tree()
239
 
    work_inv = working.inventory
240
241
    delta = working.changes_from(basis, want_unchanged=True)
241
242
 
242
243
    outfile.write('\n')
257
258
    outfile.write('  %8d ignored\n' % ignore_cnt)
258
259
 
259
260
    dir_cnt = 0
260
 
    for file_id in work_inv:
261
 
        if (work_inv.get_file_kind(file_id) == 'directory' and 
262
 
            not work_inv.is_root(file_id)):
 
261
    root_id = working.get_root_id()
 
262
    for path, entry in working.iter_entries_by_dir():
 
263
        if entry.kind == 'directory' and entry.file_id != root_id:
263
264
            dir_cnt += 1
264
265
    outfile.write('  %8d versioned %s\n' % (dir_cnt,
265
266
        plural(dir_cnt, 'subdirectory', 'subdirectories')))
296
297
            'the repository.\n')
297
298
 
298
299
 
299
 
def _show_repository_stats(stats, outfile):
 
300
def _show_repository_stats(repository, stats, outfile):
300
301
    """Show statistics about a repository."""
301
 
    if 'revisions' in stats or 'size' in stats:
302
 
        outfile.write('\n')
303
 
        outfile.write('Repository:\n')
 
302
    f = StringIO()
304
303
    if 'revisions' in stats:
305
304
        revisions = stats['revisions']
306
 
        outfile.write('  %8d revision%s\n' % (revisions, plural(revisions)))
 
305
        f.write('  %8d revision%s\n' % (revisions, plural(revisions)))
307
306
    if 'size' in stats:
308
 
        outfile.write('  %8d KiB\n' % (stats['size']/1024))
 
307
        f.write('  %8d KiB\n' % (stats['size']/1024))
 
308
    for hook in hooks['repository']:
 
309
        hook(repository, stats, f)
 
310
    if f.getvalue() != "":
 
311
        outfile.write('\n')
 
312
        outfile.write('Repository:\n')
 
313
        outfile.write(f.getvalue())
309
314
 
310
315
 
311
316
def show_bzrdir_info(a_bzrdir, verbose=False, outfile=None):
373
378
    elif branch is not None:
374
379
        _show_missing_revisions_branch(branch, outfile)
375
380
    if branch is not None:
376
 
        stats = _show_branch_stats(branch, verbose==2, outfile)
 
381
        show_committers = verbose >= 2
 
382
        stats = _show_branch_stats(branch, show_committers, outfile)
377
383
    else:
378
384
        stats = repository.gather_stats()
379
385
    if branch is None and working is None:
380
386
        _show_repository_info(repository, outfile)
381
 
    _show_repository_stats(stats, outfile)
 
387
    _show_repository_stats(repository, stats, outfile)
382
388
 
383
389
 
384
390
def describe_layout(repository=None, branch=None, tree=None):
410
416
        if branch is None and tree is not None:
411
417
            phrase = "branchless tree"
412
418
        else:
413
 
            if (tree is not None and tree.bzrdir.root_transport.base !=
414
 
                branch.bzrdir.root_transport.base):
 
419
            if (tree is not None and tree.user_url !=
 
420
                branch.user_url):
415
421
                independence = ''
416
422
                phrase = "Lightweight checkout"
417
423
            elif branch.get_bound_location() is not None:
436
442
    """
437
443
    candidates  = []
438
444
    if (branch is not None and tree is not None and
439
 
        branch.bzrdir.root_transport.base !=
440
 
        tree.bzrdir.root_transport.base):
 
445
        branch.user_url != tree.user_url):
441
446
        branch = None
442
447
        repository = None
443
 
    for key in bzrdir.format_registry.keys():
 
448
    non_aliases = set(bzrdir.format_registry.keys())
 
449
    non_aliases.difference_update(bzrdir.format_registry.aliases())
 
450
    for key in non_aliases:
444
451
        format = bzrdir.format_registry.make_bzrdir(key)
445
452
        if isinstance(format, bzrdir.BzrDirMetaFormat1):
446
453
            if (tree and format.workingtree_format !=
457
464
        candidates.append(key)
458
465
    if len(candidates) == 0:
459
466
        return 'unnamed'
460
 
    new_candidates = [c for c in candidates if c != 'default']
461
 
    if len(new_candidates) > 0:
462
 
        candidates = new_candidates
 
467
    candidates.sort()
463
468
    new_candidates = [c for c in candidates if not
464
469
        bzrdir.format_registry.get_info(c).hidden]
465
470
    if len(new_candidates) > 0:
 
471
        # If there are any non-hidden formats that match, only return those to
 
472
        # avoid listing hidden formats except when only a hidden format will
 
473
        # do.
466
474
        candidates = new_candidates
467
475
    return ' or '.join(candidates)
 
476
 
 
477
 
 
478
class InfoHooks(_mod_hooks.Hooks):
 
479
    """Hooks for the info command."""
 
480
 
 
481
    def __init__(self):
 
482
        super(InfoHooks, self).__init__("bzrlib.info", "hooks")
 
483
        self.add_hook('repository',
 
484
            "Invoked when displaying the statistics for a repository. "
 
485
            "repository is called with a statistics dictionary as returned "
 
486
            "by the repository and a file-like object to write to.", (1, 15))
 
487
 
 
488
 
 
489
hooks = InfoHooks()