/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/info.py

  • Committer: Martin Pool
  • Date: 2011-11-29 09:13:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6329.
  • Revision ID: mbp@canonical.com-20111129091354-zcwnzn3cy1jfzqju
ContainerWriter: Avoid one possible large-string join

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
from bzrlib import (
24
24
    bzrdir,
 
25
    controldir,
25
26
    errors,
26
27
    hooks as _mod_hooks,
27
28
    osutils,
112
113
        elif branch_path is not None:
113
114
            # standalone
114
115
            locs['branch root'] = branch_path
115
 
            if master_path != branch_path:
116
 
                locs['bound to branch'] = master_path
117
116
        else:
118
117
            locs['repository'] = repository_path
 
118
        if master_path != branch_path:
 
119
            locs['bound to branch'] = master_path
119
120
    if repository.is_shared():
120
121
        # lightweight checkout of branch in shared repository
121
122
        locs['shared repository'] = repository_path
158
159
        outfile.writelines(locs.get_lines())
159
160
 
160
161
 
 
162
def _show_control_dir_info(control, outfile):
 
163
    """Show control dir information."""
 
164
    if control._format.colocated_branches:
 
165
        outfile.write('\n')
 
166
        outfile.write('Control directory:\n')
 
167
        outfile.write('         %d branches\n' % len(control.list_branches()))
 
168
 
 
169
 
161
170
def _show_format_info(control=None, repository=None, branch=None,
162
171
                      working=None, outfile=None):
163
172
    """Show known formats for control, working, branch and repository."""
221
230
    """Show missing revisions in working tree."""
222
231
    branch = working.branch
223
232
    basis = working.basis_tree()
224
 
    work_inv = working.inventory
225
 
    branch_revno, branch_last_revision = branch.last_revision_info()
 
233
    try:
 
234
        branch_revno, branch_last_revision = branch.last_revision_info()
 
235
    except errors.UnsupportedOperation:
 
236
        return
226
237
    try:
227
238
        tree_last_id = working.get_parent_ids()[0]
228
239
    except IndexError:
239
250
def _show_working_stats(working, outfile):
240
251
    """Show statistics about a working tree."""
241
252
    basis = working.basis_tree()
242
 
    work_inv = working.inventory
243
253
    delta = working.changes_from(basis, want_unchanged=True)
244
254
 
245
255
    outfile.write('\n')
260
270
    outfile.write('  %8d ignored\n' % ignore_cnt)
261
271
 
262
272
    dir_cnt = 0
263
 
    for file_id in work_inv:
264
 
        if (work_inv.get_file_kind(file_id) == 'directory' and
265
 
            not work_inv.is_root(file_id)):
 
273
    root_id = working.get_root_id()
 
274
    for path, entry in working.iter_entries_by_dir():
 
275
        if entry.kind == 'directory' and entry.file_id != root_id:
266
276
            dir_cnt += 1
267
277
    outfile.write('  %8d versioned %s\n' % (dir_cnt,
268
278
        plural(dir_cnt, 'subdirectory', 'subdirectories')))
270
280
 
271
281
def _show_branch_stats(branch, verbose, outfile):
272
282
    """Show statistics about a branch."""
273
 
    revno, head = branch.last_revision_info()
 
283
    try:
 
284
        revno, head = branch.last_revision_info()
 
285
    except errors.UnsupportedOperation:
 
286
        return {}
274
287
    outfile.write('\n')
275
288
    outfile.write('Branch history:\n')
276
289
    outfile.write('  %8d revision%s\n' % (revno, plural(revno)))
332
345
                repository = a_bzrdir.open_repository()
333
346
            except NoRepositoryPresent:
334
347
                # Return silently; cmd_info already returned NotBranchError
335
 
                # if no bzrdir could be opened.
 
348
                # if no controldir could be opened.
336
349
                return
337
350
            else:
338
351
                lockable = repository
372
385
        return
373
386
    _show_format_info(control, repository, branch, working, outfile)
374
387
    _show_locking_info(repository, branch, working, outfile)
 
388
    _show_control_dir_info(control, outfile)
375
389
    if branch is not None:
376
390
        _show_missing_revisions_branch(branch, outfile)
377
391
    if working is not None:
447
461
        branch.user_url != tree.user_url):
448
462
        branch = None
449
463
        repository = None
450
 
    non_aliases = set(bzrdir.format_registry.keys())
451
 
    non_aliases.difference_update(bzrdir.format_registry.aliases())
 
464
    non_aliases = set(controldir.format_registry.keys())
 
465
    non_aliases.difference_update(controldir.format_registry.aliases())
452
466
    for key in non_aliases:
453
 
        format = bzrdir.format_registry.make_bzrdir(key)
 
467
        format = controldir.format_registry.make_bzrdir(key)
454
468
        if isinstance(format, bzrdir.BzrDirMetaFormat1):
455
469
            if (tree and format.workingtree_format !=
456
470
                tree._format):
468
482
        return 'unnamed'
469
483
    candidates.sort()
470
484
    new_candidates = [c for c in candidates if not
471
 
        bzrdir.format_registry.get_info(c).hidden]
 
485
        controldir.format_registry.get_info(c).hidden]
472
486
    if len(new_candidates) > 0:
473
487
        # If there are any non-hidden formats that match, only return those to
474
488
        # avoid listing hidden formats except when only a hidden format will
481
495
    """Hooks for the info command."""
482
496
 
483
497
    def __init__(self):
484
 
        super(InfoHooks, self).__init__()
485
 
        self.create_hook(_mod_hooks.HookPoint('repository',
 
498
        super(InfoHooks, self).__init__("bzrlib.info", "hooks")
 
499
        self.add_hook('repository',
486
500
            "Invoked when displaying the statistics for a repository. "
487
501
            "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))
 
502
            "by the repository and a file-like object to write to.", (1, 15))
490
503
 
491
504
 
492
505
hooks = InfoHooks()