/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: John Arbash Meinel
  • Date: 2006-04-25 15:05:42 UTC
  • mfrom: (1185.85.85 bzr-encoding)
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060425150542-c7b518dca9928691
[merge] the old bzr-encoding changes, reparenting them on bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
2
 
#
 
1
# Copyright (C) 2004, 2005 by Martin Pool
 
2
# Copyright (C) 2005 by Canonical Ltd
 
3
 
 
4
 
3
5
# This program is free software; you can redistribute it and/or modify
4
6
# it under the terms of the GNU General Public License as published by
5
7
# the Free Software Foundation; either version 2 of the License, or
6
8
# (at your option) any later version.
7
 
#
 
9
 
8
10
# This program is distributed in the hope that it will be useful,
9
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
13
# GNU General Public License for more details.
12
 
#
 
14
 
13
15
# You should have received a copy of the GNU General Public License
14
16
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
from __future__ import absolute_import
 
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
 
19
19
__all__ = ['show_bzrdir_info']
20
20
 
21
 
from io import StringIO
22
21
import time
23
 
import sys
24
 
 
25
 
from . import (
26
 
    branch as _mod_branch,
27
 
    controldir,
28
 
    errors,
29
 
    hooks as _mod_hooks,
30
 
    osutils,
31
 
    urlutils,
32
 
    )
33
 
from .bzr import (
34
 
    bzrdir,
35
 
    )
36
 
from .errors import (NoWorkingTree, NotBranchError,
37
 
                     NoRepositoryPresent, NotLocalUrl)
38
 
from .missing import find_unmerged
39
 
 
40
 
 
41
 
def plural(n, base=u'', pl=None):
 
22
 
 
23
 
 
24
import bzrlib.diff as diff
 
25
from bzrlib.errors import (NoWorkingTree, NotBranchError,
 
26
                           NoRepositoryPresent, NotLocalUrl)
 
27
from bzrlib.missing import find_unmerged
 
28
from bzrlib.osutils import format_date
 
29
from bzrlib.symbol_versioning import *
 
30
 
 
31
 
 
32
def _countiter(it):
 
33
    # surely there's a builtin for this?
 
34
    i = 0
 
35
    for j in it:
 
36
        i += 1
 
37
    return i        
 
38
 
 
39
 
 
40
def plural(n, base='', pl=None):
42
41
    if n == 1:
43
42
        return base
44
 
    elif pl is not None:
 
43
    elif pl != None:
45
44
        return pl
46
45
    else:
47
 
        return u's'
48
 
 
49
 
 
50
 
class LocationList(object):
51
 
 
52
 
    def __init__(self, base_path):
53
 
        self.locs = []
54
 
        self.base_path = base_path
55
 
 
56
 
    def add_url(self, label, url):
57
 
        """Add a URL to the list, converting it to a path if possible"""
58
 
        if url is None:
59
 
            return
60
 
        try:
61
 
            path = urlutils.local_path_from_url(url)
62
 
        except urlutils.InvalidURL:
63
 
            self.locs.append((label, url))
64
 
        else:
65
 
            self.add_path(label, path)
66
 
 
67
 
    def add_path(self, label, path):
68
 
        """Add a path, converting it to a relative path if possible"""
69
 
        try:
70
 
            path = osutils.relpath(self.base_path, path)
71
 
        except errors.PathNotChild:
72
 
            pass
73
 
        else:
74
 
            if path == '':
75
 
                path = '.'
76
 
        if path != '/':
77
 
            path = path.rstrip('/')
78
 
        self.locs.append((label, path))
79
 
 
80
 
    def get_lines(self):
81
 
        max_len = max(len(l) for l, u in self.locs)
82
 
        return ["  %*s: %s\n" % (max_len, l, u) for l, u in self.locs]
83
 
 
84
 
 
85
 
def gather_location_info(repository=None, branch=None, working=None,
86
 
                         control=None):
87
 
    locs = {}
88
 
    if branch is not None:
89
 
        branch_path = branch.user_url
90
 
        master_path = branch.get_bound_location()
91
 
        if master_path is None:
92
 
            master_path = branch_path
93
 
    else:
94
 
        branch_path = None
95
 
        master_path = None
96
 
        try:
97
 
            if control is not None and control.get_branch_reference():
98
 
                locs['checkout of branch'] = control.get_branch_reference()
99
 
        except NotBranchError:
100
 
            pass
101
 
    if working:
102
 
        working_path = working.user_url
103
 
        if working_path != branch_path:
104
 
            locs['light checkout root'] = working_path
105
 
        if master_path != branch_path:
106
 
            if repository.is_shared():
107
 
                locs['repository checkout root'] = branch_path
108
 
            else:
109
 
                locs['checkout root'] = branch_path
110
 
        if working_path != master_path:
111
 
            (master_path_base, params) = urlutils.split_segment_parameters(
112
 
                master_path)
113
 
            if working_path == master_path_base:
114
 
                locs['checkout of co-located branch'] = params['branch']
115
 
            elif 'branch' in params:
116
 
                locs['checkout of branch'] = "%s, branch %s" % (
117
 
                    master_path_base, params['branch'])
118
 
            else:
119
 
                locs['checkout of branch'] = master_path
120
 
        elif repository.is_shared():
121
 
            locs['repository branch'] = branch_path
122
 
        elif branch_path is not None:
123
 
            # standalone
124
 
            locs['branch root'] = branch_path
125
 
    else:
126
 
        working_path = None
127
 
        if repository is not None and repository.is_shared():
128
 
            # lightweight checkout of branch in shared repository
129
 
            if branch_path is not None:
130
 
                locs['repository branch'] = branch_path
131
 
        elif branch_path is not None:
132
 
            # standalone
133
 
            locs['branch root'] = branch_path
134
 
        elif repository is not None:
135
 
            locs['repository'] = repository.user_url
136
 
        elif control is not None:
137
 
            locs['control directory'] = control.user_url
138
 
        else:
139
 
            # Really, at least a control directory should be
140
 
            # passed in for this method to be useful.
141
 
            pass
142
 
        if master_path != branch_path:
143
 
            locs['bound to branch'] = master_path
144
 
    if repository is not None and repository.is_shared():
145
 
        # lightweight checkout of branch in shared repository
146
 
        locs['shared repository'] = repository.user_url
147
 
    order = ['control directory', 'light checkout root',
148
 
             'repository checkout root', 'checkout root',
149
 
             'checkout of branch', 'checkout of co-located branch',
150
 
             'shared repository', 'repository', 'repository branch',
151
 
             'branch root', 'bound to branch']
152
 
    return [(n, locs[n]) for n in order if n in locs]
153
 
 
154
 
 
155
 
def _show_location_info(locs, outfile):
 
46
        return 's'
 
47
 
 
48
 
 
49
def _show_location_info(repository=None, branch=None, working=None):
156
50
    """Show known locations for working, branch and repository."""
157
 
    outfile.write('Location:\n')
158
 
    path_list = LocationList(osutils.getcwd())
159
 
    for name, loc in locs:
160
 
        path_list.add_url(name, loc)
161
 
    outfile.writelines(path_list.get_lines())
162
 
 
163
 
 
164
 
def _gather_related_branches(branch):
165
 
    locs = LocationList(osutils.getcwd())
166
 
    locs.add_url('public branch', branch.get_public_branch())
167
 
    locs.add_url('push branch', branch.get_push_location())
168
 
    locs.add_url('parent branch', branch.get_parent())
169
 
    locs.add_url('submit branch', branch.get_submit_branch())
170
 
    try:
171
 
        locs.add_url('stacked on', branch.get_stacked_on_url())
172
 
    except (_mod_branch.UnstackableBranchFormat, errors.UnstackableRepositoryFormat,
173
 
            errors.NotStacked):
174
 
        pass
175
 
    return locs
176
 
 
177
 
 
178
 
def _show_related_info(branch, outfile):
179
 
    """Show parent and push location of branch."""
180
 
    locs = _gather_related_branches(branch)
181
 
    if len(locs.locs) > 0:
182
 
        outfile.write('\n')
183
 
        outfile.write('Related branches:\n')
184
 
        outfile.writelines(locs.get_lines())
185
 
 
186
 
 
187
 
def _show_control_dir_info(control, outfile):
188
 
    """Show control dir information."""
189
 
    if control._format.colocated_branches:
190
 
        outfile.write('\n')
191
 
        outfile.write('Control directory:\n')
192
 
        outfile.write('         %d branches\n' % len(control.list_branches()))
193
 
 
194
 
 
195
 
def _show_format_info(control=None, repository=None, branch=None,
196
 
                      working=None, outfile=None):
 
51
    print 'Location:'
 
52
    if working and branch and working.bzrdir != branch.bzrdir:
 
53
        # Lightweight checkout
 
54
        print '       checkout root: %s' % (
 
55
            working.bzrdir.root_transport.base)
 
56
        print '  checkout of branch: %s' % (
 
57
            branch.bzrdir.root_transport.base)
 
58
    elif branch:
 
59
        # Standalone or bound branch (normal checkout)
 
60
        print '         branch root: %s' % (
 
61
            branch.bzrdir.root_transport.base)
 
62
        if branch.get_bound_location():
 
63
            print '     bound to branch: %s' % branch.get_bound_location()
 
64
 
 
65
    if repository and (not branch or repository.bzrdir != branch.bzrdir):
 
66
        if repository.is_shared():
 
67
            print '   shared repository: %s' % (
 
68
                repository.bzrdir.root_transport.base)
 
69
        else:
 
70
            print '          repository: %s' % (
 
71
                repository.bzrdir.root_transport.base)
 
72
 
 
73
    if branch:
 
74
        if branch.get_parent():
 
75
            print '       parent branch: %s' % branch.get_parent()
 
76
        if branch.get_push_location():
 
77
            print '      push to branch: %s' % branch.get_push_location()
 
78
 
 
79
 
 
80
def _show_format_info(control=None, repository=None, branch=None, working=None):
197
81
    """Show known formats for control, working, branch and repository."""
198
 
    outfile.write('\n')
199
 
    outfile.write('Format:\n')
 
82
    print
 
83
    print 'Format:'
200
84
    if control:
201
 
        outfile.write('       control: %s\n' %
202
 
                      control._format.get_format_description())
 
85
        print '       control: %s' % control._format.get_format_description()
203
86
    if working:
204
 
        outfile.write('  working tree: %s\n' %
205
 
                      working._format.get_format_description())
 
87
        print '  working tree: %s' % working._format.get_format_description()
206
88
    if branch:
207
 
        outfile.write('        branch: %s\n' %
208
 
                      branch._format.get_format_description())
 
89
        print '        branch: %s' % branch._format.get_format_description()
209
90
    if repository:
210
 
        outfile.write('    repository: %s\n' %
211
 
                      repository._format.get_format_description())
212
 
 
213
 
 
214
 
def _show_locking_info(repository=None, branch=None, working=None,
215
 
                       outfile=None):
216
 
    """Show locking status of working, branch and repository."""
217
 
    if (repository and repository.get_physical_lock_status() or
218
 
        (branch and branch.get_physical_lock_status()) or
219
 
            (working and working.get_physical_lock_status())):
220
 
        outfile.write('\n')
221
 
        outfile.write('Lock status:\n')
222
 
        if working:
223
 
            if working.get_physical_lock_status():
224
 
                status = 'locked'
225
 
            else:
226
 
                status = 'unlocked'
227
 
            outfile.write('  working tree: %s\n' % status)
228
 
        if branch:
229
 
            if branch.get_physical_lock_status():
230
 
                status = 'locked'
231
 
            else:
232
 
                status = 'unlocked'
233
 
            outfile.write('        branch: %s\n' % status)
234
 
        if repository:
235
 
            if repository.get_physical_lock_status():
236
 
                status = 'locked'
237
 
            else:
238
 
                status = 'unlocked'
239
 
            outfile.write('    repository: %s\n' % status)
240
 
 
241
 
 
242
 
def _show_missing_revisions_branch(branch, outfile):
 
91
        print '    repository: %s' % repository._format.get_format_description()
 
92
 
 
93
 
 
94
def _show_missing_revisions_branch(branch):
243
95
    """Show missing master revisions in branch."""
244
96
    # Try with inaccessible branch ?
245
97
    master = branch.get_master_branch()
246
98
    if master:
247
99
        local_extra, remote_extra = find_unmerged(branch, master)
248
100
        if remote_extra:
249
 
            outfile.write('\n')
250
 
            outfile.write(('Branch is out of date: missing %d '
251
 
                           'revision%s.\n') % (len(remote_extra),
252
 
                                               plural(len(remote_extra))))
253
 
 
254
 
 
255
 
def _show_missing_revisions_working(working, outfile):
 
101
            print
 
102
            print 'Branch is out of date: missing %d revision%s.' % (
 
103
                len(remote_extra), plural(len(remote_extra)))
 
104
 
 
105
 
 
106
def _show_missing_revisions_working(working):
256
107
    """Show missing revisions in working tree."""
257
108
    branch = working.branch
258
 
    try:
259
 
        branch_revno, branch_last_revision = branch.last_revision_info()
260
 
    except errors.UnsupportedOperation:
261
 
        return
262
 
    try:
263
 
        tree_last_id = working.get_parent_ids()[0]
264
 
    except IndexError:
265
 
        tree_last_id = None
 
109
    basis = working.basis_tree()
 
110
    work_inv = working.inventory
 
111
    delta = diff.compare_trees(basis, working, want_unchanged=True)
 
112
    history = branch.revision_history()
 
113
    tree_last_id = working.last_revision()
266
114
 
267
 
    if branch_revno and tree_last_id != branch_last_revision:
 
115
    if len(history) and tree_last_id != history[-1]:
268
116
        tree_last_revno = branch.revision_id_to_revno(tree_last_id)
269
 
        missing_count = branch_revno - tree_last_revno
270
 
        outfile.write('\n')
271
 
        outfile.write(('Working tree is out of date: missing %d '
272
 
                       'revision%s.\n') % (missing_count, plural(missing_count)))
273
 
 
274
 
 
275
 
def _show_working_stats(working, outfile):
 
117
        missing_count = len(history) - tree_last_revno
 
118
        print
 
119
        print 'Working tree is out of date: missing %d revision%s.' % (
 
120
            missing_count, plural(missing_count))
 
121
 
 
122
 
 
123
def _show_working_stats(working):
276
124
    """Show statistics about a working tree."""
277
125
    basis = working.basis_tree()
278
 
    delta = working.changes_from(basis, want_unchanged=True)
 
126
    work_inv = working.inventory
 
127
    delta = diff.compare_trees(basis, working, want_unchanged=True)
279
128
 
280
 
    outfile.write('\n')
281
 
    outfile.write('In the working tree:\n')
282
 
    outfile.write('  %8s unchanged\n' % len(delta.unchanged))
283
 
    outfile.write('  %8d modified\n' % len(delta.modified))
284
 
    outfile.write('  %8d added\n' % len(delta.added))
285
 
    outfile.write('  %8d removed\n' % len(delta.removed))
286
 
    outfile.write('  %8d renamed\n' % len(delta.renamed))
287
 
    outfile.write('  %8d copied\n' % len(delta.copied))
 
129
    print
 
130
    print 'In the working tree:'
 
131
    print '  %8s unchanged' % len(delta.unchanged)
 
132
    print '  %8d modified' % len(delta.modified)
 
133
    print '  %8d added' % len(delta.added)
 
134
    print '  %8d removed' % len(delta.removed)
 
135
    print '  %8d renamed' % len(delta.renamed)
288
136
 
289
137
    ignore_cnt = unknown_cnt = 0
290
138
    for path in working.extras():
292
140
            ignore_cnt += 1
293
141
        else:
294
142
            unknown_cnt += 1
295
 
    outfile.write('  %8d unknown\n' % unknown_cnt)
296
 
    outfile.write('  %8d ignored\n' % ignore_cnt)
 
143
    print '  %8d unknown' % unknown_cnt
 
144
    print '  %8d ignored' % ignore_cnt
297
145
 
298
146
    dir_cnt = 0
299
 
    for path, entry in working.iter_entries_by_dir():
300
 
        if entry.kind == 'directory' and path != '':
 
147
    for file_id in work_inv:
 
148
        if work_inv.get_file_kind(file_id) == 'directory':
301
149
            dir_cnt += 1
302
 
    outfile.write('  %8d versioned %s\n' % (dir_cnt,
303
 
                                            plural(dir_cnt, 'subdirectory', 'subdirectories')))
304
 
 
305
 
 
306
 
def _show_branch_stats(branch, verbose, outfile):
 
150
    print '  %8d versioned %s' \
 
151
          % (dir_cnt,
 
152
             plural(dir_cnt, 'subdirectory', 'subdirectories'))
 
153
 
 
154
 
 
155
def _show_branch_stats(branch, verbose):
307
156
    """Show statistics about a branch."""
308
 
    try:
309
 
        revno, head = branch.last_revision_info()
310
 
    except errors.UnsupportedOperation:
311
 
        return {}
312
 
    outfile.write('\n')
313
 
    outfile.write('Branch history:\n')
314
 
    outfile.write('  %8d revision%s\n' % (revno, plural(revno)))
315
 
    stats = branch.repository.gather_stats(head, committers=verbose)
 
157
    repository = branch.repository
 
158
    history = branch.revision_history()
 
159
 
 
160
    print
 
161
    print 'Branch history:'
 
162
    revno = len(history)
 
163
    print '  %8d revision%s' % (revno, plural(revno))
316
164
    if verbose:
317
 
        committers = stats['committers']
318
 
        outfile.write('  %8d committer%s\n' % (committers,
319
 
                                               plural(committers)))
320
 
    if revno:
321
 
        timestamp, timezone = stats['firstrev']
322
 
        age = int((time.time() - timestamp) / 3600 / 24)
323
 
        outfile.write('  %8d day%s old\n' % (age, plural(age)))
324
 
        outfile.write('   first revision: %s\n' %
325
 
                      osutils.format_date(timestamp, timezone))
326
 
        timestamp, timezone = stats['latestrev']
327
 
        outfile.write('  latest revision: %s\n' %
328
 
                      osutils.format_date(timestamp, timezone))
329
 
    return stats
330
 
 
331
 
 
332
 
def _show_repository_info(repository, outfile):
 
165
        committers = {}
 
166
        for rev in history:
 
167
            committers[repository.get_revision(rev).committer] = True
 
168
        print '  %8d committer%s' % (len(committers), plural(len(committers)))
 
169
    if revno > 0:
 
170
        firstrev = repository.get_revision(history[0])
 
171
        age = int((time.time() - firstrev.timestamp) / 3600 / 24)
 
172
        print '  %8d day%s old' % (age, plural(age))
 
173
        print '   first revision: %s' % format_date(firstrev.timestamp,
 
174
                                                    firstrev.timezone)
 
175
 
 
176
        lastrev = repository.get_revision(history[-1])
 
177
        print '  latest revision: %s' % format_date(lastrev.timestamp,
 
178
                                                    lastrev.timezone)
 
179
 
 
180
#     print
 
181
#     print 'Text store:'
 
182
#     c, t = branch.text_store.total_size()
 
183
#     print '  %8d file texts' % c
 
184
#     print '  %8d KiB' % (t/1024)
 
185
 
 
186
#     print
 
187
#     print 'Inventory store:'
 
188
#     c, t = branch.inventory_store.total_size()
 
189
#     print '  %8d inventories' % c
 
190
#     print '  %8d KiB' % (t/1024)
 
191
 
 
192
 
 
193
def _show_repository_info(repository):
333
194
    """Show settings of a repository."""
334
195
    if repository.make_working_trees():
335
 
        outfile.write('\n')
336
 
        outfile.write('Create working tree for new branches inside '
337
 
                      'the repository.\n')
338
 
 
339
 
 
340
 
def _show_repository_stats(repository, stats, outfile):
 
196
        print
 
197
        print 'Create working tree for new branches inside the repository.'
 
198
 
 
199
 
 
200
def _show_repository_stats(repository):
341
201
    """Show statistics about a repository."""
342
 
    f = StringIO()
343
 
    if 'revisions' in stats:
344
 
        revisions = stats['revisions']
345
 
        f.write('  %8d revision%s\n' % (revisions, plural(revisions)))
346
 
    if 'size' in stats:
347
 
        f.write('  %8d KiB\n' % (stats['size'] / 1024))
348
 
    for hook in hooks['repository']:
349
 
        hook(repository, stats, f)
350
 
    if f.getvalue() != "":
351
 
        outfile.write('\n')
352
 
        outfile.write('Repository:\n')
353
 
        outfile.write(f.getvalue())
354
 
 
355
 
 
356
 
def show_bzrdir_info(a_controldir, verbose=False, outfile=None):
357
 
    """Output to stdout the 'info' for a_controldir."""
358
 
    if outfile is None:
359
 
        outfile = sys.stdout
360
 
    try:
361
 
        tree = a_controldir.open_workingtree(
362
 
            recommend_upgrade=False)
363
 
    except (NoWorkingTree, NotLocalUrl, NotBranchError):
364
 
        tree = None
365
 
        try:
366
 
            branch = a_controldir.open_branch(name="")
367
 
        except NotBranchError:
368
 
            branch = None
369
 
            try:
370
 
                repository = a_controldir.open_repository()
371
 
            except NoRepositoryPresent:
372
 
                lockable = None
373
 
                repository = None
374
 
            else:
375
 
                lockable = repository
376
 
        else:
377
 
            repository = branch.repository
378
 
            lockable = branch
379
 
    else:
380
 
        branch = tree.branch
381
 
        repository = branch.repository
382
 
        lockable = tree
383
 
 
384
 
    if lockable is not None:
385
 
        lockable.lock_read()
386
 
    try:
387
 
        show_component_info(a_controldir, repository, branch, tree, verbose,
388
 
                            outfile)
389
 
    finally:
390
 
        if lockable is not None:
391
 
            lockable.unlock()
392
 
 
393
 
 
394
 
def show_component_info(control, repository, branch=None, working=None,
395
 
                        verbose=1, outfile=None):
396
 
    """Write info about all bzrdir components to stdout"""
397
 
    if outfile is None:
398
 
        outfile = sys.stdout
399
 
    if verbose is False:
400
 
        verbose = 1
401
 
    if verbose is True:
402
 
        verbose = 2
403
 
    layout = describe_layout(repository, branch, working, control)
404
 
    format = describe_format(control, repository, branch, working)
405
 
    outfile.write("%s (format: %s)\n" % (layout, format))
406
 
    _show_location_info(
407
 
        gather_location_info(control=control, repository=repository,
408
 
                             branch=branch, working=working),
409
 
        outfile)
410
 
    if branch is not None:
411
 
        _show_related_info(branch, outfile)
412
 
    if verbose == 0:
413
 
        return
414
 
    _show_format_info(control, repository, branch, working, outfile)
415
 
    _show_locking_info(repository, branch, working, outfile)
416
 
    _show_control_dir_info(control, outfile)
417
 
    if branch is not None:
418
 
        _show_missing_revisions_branch(branch, outfile)
419
 
    if working is not None:
420
 
        _show_missing_revisions_working(working, outfile)
421
 
        _show_working_stats(working, outfile)
422
 
    elif branch is not None:
423
 
        _show_missing_revisions_branch(branch, outfile)
424
 
    if branch is not None:
425
 
        show_committers = verbose >= 2
426
 
        stats = _show_branch_stats(branch, show_committers, outfile)
427
 
    elif repository is not None:
428
 
        stats = repository.gather_stats()
429
 
    if branch is None and working is None and repository is not None:
430
 
        _show_repository_info(repository, outfile)
431
 
    if repository is not None:
432
 
        _show_repository_stats(repository, stats, outfile)
433
 
 
434
 
 
435
 
def describe_layout(repository=None, branch=None, tree=None, control=None):
436
 
    """Convert a control directory layout into a user-understandable term
437
 
 
438
 
    Common outputs include "Standalone tree", "Repository branch" and
439
 
    "Checkout".  Uncommon outputs include "Unshared repository with trees"
440
 
    and "Empty control directory"
441
 
    """
442
 
    if branch is None and control is not None:
443
 
        try:
444
 
            branch_reference = control.get_branch_reference()
445
 
        except NotBranchError:
446
 
            pass
447
 
        else:
448
 
            if branch_reference is not None:
449
 
                return "Dangling branch reference"
450
 
    if repository is None:
451
 
        return 'Empty control directory'
452
 
    if branch is None and tree is None:
453
 
        if repository.is_shared():
454
 
            phrase = 'Shared repository'
455
 
        else:
456
 
            phrase = 'Unshared repository'
457
 
        extra = []
458
 
        if repository.make_working_trees():
459
 
            extra.append('trees')
460
 
        if len(control.branch_names()) > 0:
461
 
            extra.append('colocated branches')
462
 
        if extra:
463
 
            phrase += ' with ' + " and ".join(extra)
464
 
        return phrase
465
 
    else:
466
 
        if repository.is_shared():
467
 
            independence = "Repository "
468
 
        else:
469
 
            independence = "Standalone "
470
 
        if tree is not None:
471
 
            phrase = "tree"
472
 
        else:
473
 
            phrase = "branch"
474
 
        if branch is None and tree is not None:
475
 
            phrase = "branchless tree"
476
 
        else:
477
 
            if (tree is not None and tree.controldir.control_url !=
478
 
                    branch.controldir.control_url):
479
 
                independence = ''
480
 
                phrase = "Lightweight checkout"
481
 
            elif branch.get_bound_location() is not None:
482
 
                if independence == 'Standalone ':
483
 
                    independence = ''
484
 
                if tree is None:
485
 
                    phrase = "Bound branch"
486
 
                else:
487
 
                    phrase = "Checkout"
488
 
        if independence != "":
489
 
            phrase = phrase.lower()
490
 
        return "%s%s" % (independence, phrase)
491
 
 
492
 
 
493
 
def describe_format(control, repository, branch, tree):
494
 
    """Determine the format of an existing control directory
495
 
 
496
 
    Several candidates may be found.  If so, the names are returned as a
497
 
    single string, separated by ' or '.
498
 
 
499
 
    If no matching candidate is found, "unnamed" is returned.
500
 
    """
501
 
    candidates = []
502
 
    if (branch is not None and tree is not None and
503
 
            branch.user_url != tree.user_url):
504
 
        branch = None
505
 
        repository = None
506
 
    non_aliases = set(controldir.format_registry.keys())
507
 
    non_aliases.difference_update(controldir.format_registry.aliases())
508
 
    for key in non_aliases:
509
 
        format = controldir.format_registry.make_controldir(key)
510
 
        if isinstance(format, bzrdir.BzrDirMetaFormat1):
511
 
            if (tree and format.workingtree_format !=
512
 
                    tree._format):
513
 
                continue
514
 
            if (branch and format.get_branch_format() !=
515
 
                    branch._format):
516
 
                continue
517
 
            if (repository and format.repository_format !=
518
 
                    repository._format):
519
 
                continue
520
 
        if format.__class__ is not control._format.__class__:
521
 
            continue
522
 
        candidates.append(key)
523
 
    if len(candidates) == 0:
524
 
        return 'unnamed'
525
 
    candidates.sort()
526
 
    new_candidates = [c for c in candidates if not
527
 
                      controldir.format_registry.get_info(c).hidden]
528
 
    if len(new_candidates) > 0:
529
 
        # If there are any non-hidden formats that match, only return those to
530
 
        # avoid listing hidden formats except when only a hidden format will
531
 
        # do.
532
 
        candidates = new_candidates
533
 
    return ' or '.join(candidates)
534
 
 
535
 
 
536
 
class InfoHooks(_mod_hooks.Hooks):
537
 
    """Hooks for the info command."""
538
 
 
539
 
    def __init__(self):
540
 
        super(InfoHooks, self).__init__("breezy.info", "hooks")
541
 
        self.add_hook(
542
 
            'repository',
543
 
            "Invoked when displaying the statistics for a repository. "
544
 
            "repository is called with a statistics dictionary as returned "
545
 
            "by the repository and a file-like object to write to.", (1, 15))
546
 
 
547
 
 
548
 
hooks = InfoHooks()
 
202
    if repository.bzrdir.root_transport.listable():
 
203
        print
 
204
        print 'Revision store:'
 
205
        c, t = repository._revision_store.total_size(repository.get_transaction())
 
206
        print '  %8d revision%s' % (c, plural(c))
 
207
        print '  %8d KiB' % (t/1024)
 
208
 
 
209
 
 
210
@deprecated_function(zero_eight)
 
211
def show_info(b):
 
212
    """Please see show_bzrdir_info."""
 
213
    return show_bzrdir_info(b.bzrdir)
 
214
 
 
215
 
 
216
def show_bzrdir_info(a_bzrdir, verbose=False):
 
217
    """Output to stdout the 'info' for a_bzrdir."""
 
218
    try:
 
219
        working = a_bzrdir.open_workingtree()
 
220
        working.lock_read()
 
221
        try:
 
222
            show_tree_info(working, verbose)
 
223
        finally:
 
224
            working.unlock()
 
225
        return
 
226
    except (NoWorkingTree, NotLocalUrl):
 
227
        pass
 
228
 
 
229
    try:
 
230
        branch = a_bzrdir.open_branch()
 
231
        branch.lock_read()
 
232
        try:
 
233
            show_branch_info(branch, verbose)
 
234
        finally:
 
235
            branch.unlock()
 
236
        return
 
237
    except NotBranchError:
 
238
        pass
 
239
 
 
240
    try:
 
241
        repository = a_bzrdir.open_repository()
 
242
        repository.lock_read()
 
243
        try:
 
244
            show_repository_info(repository, verbose)
 
245
        finally:
 
246
            repository.unlock()
 
247
        return
 
248
    except NoRepositoryPresent:
 
249
        pass
 
250
 
 
251
    # Return silently, cmd_info returns NotBranchError if no bzrdir
 
252
    # could be opened.
 
253
 
 
254
 
 
255
def show_tree_info(working, verbose):
 
256
    """Output to stdout the 'info' for working."""
 
257
    branch = working.branch
 
258
    repository = branch.repository
 
259
    control = working.bzrdir
 
260
 
 
261
    _show_location_info(repository, branch, working)
 
262
    _show_format_info(control, repository, branch, working)
 
263
    _show_missing_revisions_branch(branch)
 
264
    _show_missing_revisions_working(working)
 
265
    _show_working_stats(working)
 
266
    _show_branch_stats(branch, verbose)
 
267
    _show_repository_stats(repository)
 
268
 
 
269
 
 
270
def show_branch_info(branch, verbose):
 
271
    """Output to stdout the 'info' for branch."""
 
272
    repository = branch.repository
 
273
    control = branch.bzrdir
 
274
 
 
275
    _show_location_info(repository, branch)
 
276
    _show_format_info(control, repository, branch)
 
277
    _show_missing_revisions_branch(branch)
 
278
    _show_branch_stats(branch, verbose)
 
279
    _show_repository_stats(repository)
 
280
 
 
281
 
 
282
def show_repository_info(repository, verbose):
 
283
    """Output to stdout the 'info' for branch."""
 
284
    control = repository.bzrdir
 
285
 
 
286
    _show_location_info(repository)
 
287
    _show_format_info(control, repository)
 
288
    _show_repository_info(repository)
 
289
    _show_repository_stats(repository)