~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/info.py

  • Committer: Aaron Bentley
  • Date: 2009-08-14 15:35:31 UTC
  • mto: (4603.1.22 shelve-editor)
  • mto: This revision was merged to the branch mainline in revision 4795.
  • Revision ID: aaron@aaronbentley.com-20090814153531-t3t34s2obh05uga7
Simplify unchanged case.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
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
17
17
__all__ = ['show_bzrdir_info']
18
18
 
19
19
from cStringIO import StringIO
 
20
import os
20
21
import time
21
22
import sys
22
23
 
23
24
from bzrlib import (
24
25
    bzrdir,
25
 
    controldir,
 
26
    diff,
26
27
    errors,
27
28
    hooks as _mod_hooks,
28
29
    osutils,
79
80
 
80
81
def gather_location_info(repository, branch=None, working=None):
81
82
    locs = {}
82
 
    repository_path = repository.user_url
 
83
    repository_path = repository.bzrdir.root_transport.base
83
84
    if branch is not None:
84
 
        branch_path = branch.user_url
 
85
        branch_path = branch.bzrdir.root_transport.base
85
86
        master_path = branch.get_bound_location()
86
87
        if master_path is None:
87
88
            master_path = branch_path
89
90
        branch_path = None
90
91
        master_path = None
91
92
    if working:
92
 
        working_path = working.user_url
 
93
        working_path = working.bzrdir.root_transport.base
93
94
        if working_path != branch_path:
94
95
            locs['light checkout root'] = working_path
95
96
        if master_path != branch_path:
222
223
    """Show missing revisions in working tree."""
223
224
    branch = working.branch
224
225
    basis = working.basis_tree()
225
 
    try:
226
 
        branch_revno, branch_last_revision = branch.last_revision_info()
227
 
    except errors.UnsupportedOperation:
228
 
        return
 
226
    work_inv = working.inventory
 
227
    branch_revno, branch_last_revision = branch.last_revision_info()
229
228
    try:
230
229
        tree_last_id = working.get_parent_ids()[0]
231
230
    except IndexError:
242
241
def _show_working_stats(working, outfile):
243
242
    """Show statistics about a working tree."""
244
243
    basis = working.basis_tree()
 
244
    work_inv = working.inventory
245
245
    delta = working.changes_from(basis, want_unchanged=True)
246
246
 
247
247
    outfile.write('\n')
262
262
    outfile.write('  %8d ignored\n' % ignore_cnt)
263
263
 
264
264
    dir_cnt = 0
265
 
    root_id = working.get_root_id()
266
 
    for path, entry in working.iter_entries_by_dir():
267
 
        if entry.kind == 'directory' and entry.file_id != root_id:
 
265
    for file_id in work_inv:
 
266
        if (work_inv.get_file_kind(file_id) == 'directory' and
 
267
            not work_inv.is_root(file_id)):
268
268
            dir_cnt += 1
269
269
    outfile.write('  %8d versioned %s\n' % (dir_cnt,
270
270
        plural(dir_cnt, 'subdirectory', 'subdirectories')))
272
272
 
273
273
def _show_branch_stats(branch, verbose, outfile):
274
274
    """Show statistics about a branch."""
275
 
    try:
276
 
        revno, head = branch.last_revision_info()
277
 
    except errors.UnsupportedOperation:
278
 
        return {}
 
275
    revno, head = branch.last_revision_info()
279
276
    outfile.write('\n')
280
277
    outfile.write('Branch history:\n')
281
278
    outfile.write('  %8d revision%s\n' % (revno, plural(revno)))
337
334
                repository = a_bzrdir.open_repository()
338
335
            except NoRepositoryPresent:
339
336
                # Return silently; cmd_info already returned NotBranchError
340
 
                # if no controldir could be opened.
 
337
                # if no bzrdir could be opened.
341
338
                return
342
339
            else:
343
340
                lockable = repository
423
420
        if branch is None and tree is not None:
424
421
            phrase = "branchless tree"
425
422
        else:
426
 
            if (tree is not None and tree.user_url !=
427
 
                branch.user_url):
 
423
            if (tree is not None and tree.bzrdir.root_transport.base !=
 
424
                branch.bzrdir.root_transport.base):
428
425
                independence = ''
429
426
                phrase = "Lightweight checkout"
430
427
            elif branch.get_bound_location() is not None:
449
446
    """
450
447
    candidates  = []
451
448
    if (branch is not None and tree is not None and
452
 
        branch.user_url != tree.user_url):
 
449
        branch.bzrdir.root_transport.base !=
 
450
        tree.bzrdir.root_transport.base):
453
451
        branch = None
454
452
        repository = None
455
 
    non_aliases = set(controldir.format_registry.keys())
456
 
    non_aliases.difference_update(controldir.format_registry.aliases())
 
453
    non_aliases = set(bzrdir.format_registry.keys())
 
454
    non_aliases.difference_update(bzrdir.format_registry.aliases())
457
455
    for key in non_aliases:
458
 
        format = controldir.format_registry.make_bzrdir(key)
 
456
        format = bzrdir.format_registry.make_bzrdir(key)
459
457
        if isinstance(format, bzrdir.BzrDirMetaFormat1):
460
458
            if (tree and format.workingtree_format !=
461
459
                tree._format):
473
471
        return 'unnamed'
474
472
    candidates.sort()
475
473
    new_candidates = [c for c in candidates if not
476
 
        controldir.format_registry.get_info(c).hidden]
 
474
        bzrdir.format_registry.get_info(c).hidden]
477
475
    if len(new_candidates) > 0:
478
476
        # If there are any non-hidden formats that match, only return those to
479
477
        # avoid listing hidden formats except when only a hidden format will
486
484
    """Hooks for the info command."""
487
485
 
488
486
    def __init__(self):
489
 
        super(InfoHooks, self).__init__("bzrlib.info", "hooks")
490
 
        self.add_hook('repository',
 
487
        self.create_hook(_mod_hooks.HookPoint('repository',
491
488
            "Invoked when displaying the statistics for a repository. "
492
489
            "repository is called with a statistics dictionary as returned "
493
 
            "by the repository and a file-like object to write to.", (1, 15))
 
490
            "by the repository and a file-like object to write to.", (1, 15), 
 
491
            None))
494
492
 
495
493
 
496
494
hooks = InfoHooks()