~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/info.py

  • Committer: Aaron Bentley
  • Date: 2007-03-20 13:49:49 UTC
  • mto: This revision was merged to the branch mainline in revision 2528.
  • Revision ID: abentley@panoramicfeedback.com-20070320134949-e3qzzgn391slskml
Unify info display into show_component_info

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
                           NoRepositoryPresent, NotLocalUrl)
29
29
from bzrlib.missing import find_unmerged
30
30
from bzrlib.symbol_versioning import (deprecated_function,
31
 
        zero_eight)
 
31
        zero_eight, zero_sixteen)
32
32
 
33
33
 
34
34
def plural(n, base='', pl=None):
264
264
        print '  %8d KiB' % (stats['size']/1024)
265
265
 
266
266
 
 
267
def show_bzrdir_info(a_bzrdir, verbose=False):
 
268
    """Output to stdout the 'info' for a_bzrdir."""
 
269
    try:
 
270
        tree = a_bzrdir.open_workingtree()
 
271
    except (NoWorkingTree, NotLocalUrl):
 
272
        tree = None
 
273
        try:
 
274
            branch = a_bzrdir.open_branch()
 
275
        except NotBranchError:
 
276
            branch = None
 
277
            try:
 
278
                repository = a_bzrdir.open_repository()
 
279
            except NoRepositoryPresent:
 
280
                # Return silently; cmd_info already returned NotBranchError
 
281
                # if no bzrdir could be opened.
 
282
                return
 
283
            else:
 
284
                lockable = repository
 
285
        else:
 
286
            repository = branch.repository
 
287
            lockable = branch
 
288
    else:
 
289
        branch = tree.branch
 
290
        repository = branch.repository
 
291
        lockable = tree
 
292
 
 
293
    lockable.lock_read()
 
294
    try:
 
295
        show_component_info(a_bzrdir, repository, branch, tree, verbose)
 
296
    finally:
 
297
        lockable.unlock()
 
298
 
 
299
 
 
300
def show_component_info(control, repository, branch=None, working=None,
 
301
    verbose=1):
 
302
    """Write info about all bzrdir components to stdout"""
 
303
    verbose = {False: 1, True: 2}.get(verbose, verbose)
 
304
    _show_location_info(repository, branch, working)
 
305
    if branch is not None:
 
306
        _show_related_info(branch)
 
307
    _show_format_info(control, repository, branch, working)
 
308
    _show_locking_info(repository, branch, working)
 
309
    if branch is not None:
 
310
        _show_missing_revisions_branch(branch)
 
311
    if working is not None:
 
312
        _show_missing_revisions_working(working)
 
313
        _show_working_stats(working)
 
314
    elif branch is not None:
 
315
        _show_missing_revisions_branch(branch)
 
316
    if branch is not None:
 
317
        stats = _show_branch_stats(branch, verbose==2)
 
318
    else:
 
319
        stats = repository.gather_stats()
 
320
    if branch is None and working is None:
 
321
        _show_repository_info(repository)
 
322
    _show_repository_stats(stats)
 
323
 
 
324
 
267
325
@deprecated_function(zero_eight)
268
326
def show_info(b):
269
327
    """Please see show_bzrdir_info."""
270
328
    return show_bzrdir_info(b.bzrdir)
271
329
 
272
330
 
273
 
def show_bzrdir_info(a_bzrdir, verbose=False):
274
 
    """Output to stdout the 'info' for a_bzrdir."""
275
 
    try:
276
 
        working = a_bzrdir.open_workingtree()
277
 
        working.lock_read()
278
 
        try:
279
 
            show_tree_info(working, verbose)
280
 
        finally:
281
 
            working.unlock()
282
 
        return
283
 
    except (NoWorkingTree, NotLocalUrl):
284
 
        pass
285
 
 
286
 
    try:
287
 
        branch = a_bzrdir.open_branch()
288
 
        branch.lock_read()
289
 
        try:
290
 
            show_branch_info(branch, verbose)
291
 
        finally:
292
 
            branch.unlock()
293
 
        return
294
 
    except NotBranchError:
295
 
        pass
296
 
 
297
 
    try:
298
 
        repository = a_bzrdir.open_repository()
299
 
        repository.lock_read()
300
 
        try:
301
 
            show_repository_info(repository, verbose)
302
 
        finally:
303
 
            repository.unlock()
304
 
        return
305
 
    except NoRepositoryPresent:
306
 
        pass
307
 
 
308
 
    # Return silently, cmd_info already returned NotBranchError if no bzrdir
309
 
    # could be opened.
310
 
 
311
 
 
 
331
@deprecated_function(zero_sixteen)
312
332
def show_tree_info(working, verbose):
313
333
    """Output to stdout the 'info' for working."""
314
334
    branch = working.branch
315
335
    repository = branch.repository
316
336
    control = working.bzrdir
317
 
 
318
 
    _show_location_info(repository, branch, working)
319
 
    _show_related_info(branch)
320
 
    _show_format_info(control, repository, branch, working)
321
 
    _show_locking_info(repository, branch, working)
322
 
    _show_missing_revisions_branch(branch)
323
 
    _show_missing_revisions_working(working)
324
 
    _show_working_stats(working)
325
 
    stats = _show_branch_stats(branch, verbose)
326
 
    _show_repository_stats(stats)
327
 
 
328
 
 
 
337
    show_component_info(control, repository, branch, working, verbose)
 
338
 
 
339
 
 
340
@deprecated_function(zero_sixteen)
329
341
def show_branch_info(branch, verbose):
330
342
    """Output to stdout the 'info' for branch."""
331
343
    repository = branch.repository
332
344
    control = branch.bzrdir
333
 
 
334
 
    _show_location_info(repository, branch)
335
 
    _show_related_info(branch)
336
 
    _show_format_info(control, repository, branch)
337
 
    _show_locking_info(repository, branch)
338
 
    _show_missing_revisions_branch(branch)
339
 
    stats = _show_branch_stats(branch, verbose)
340
 
    _show_repository_stats(stats)
341
 
 
342
 
 
 
345
    show_component_info(control, repository, branch, verbose=verbose)
 
346
 
 
347
 
 
348
@deprecated_function(zero_sixteen)
343
349
def show_repository_info(repository, verbose):
344
350
    """Output to stdout the 'info' for repository."""
345
351
    control = repository.bzrdir
346
 
 
347
 
    _show_location_info(repository)
348
 
    _show_format_info(control, repository)
349
 
    _show_locking_info(repository)
350
 
    _show_repository_info(repository)
351
 
    stats = repository.gather_stats()
352
 
    _show_repository_stats(stats)
 
352
    show_component_info(control, repository, verbose=verbose)