/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2395.1.1 by Martin Pool
rename 'revision store' to 'repository' in bzr info
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
1685.1.60 by Martin Pool
[broken] NotBranchError should unescape the url if possible
2
# 
77 by mbp at sourcefrog
- split info command out into separate file
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
2052.3.1 by John Arbash Meinel
Add tests to cleanup the copyright of all source files
7
#
77 by mbp at sourcefrog
- split info command out into separate file
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
2052.3.1 by John Arbash Meinel
Add tests to cleanup the copyright of all source files
12
#
77 by mbp at sourcefrog
- split info command out into separate file
13
# You should have received a copy of the GNU General Public License
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
16
1534.5.1 by Robert Collins
Give info some reasonable output and tests.
17
__all__ = ['show_bzrdir_info']
18
1551.15.41 by Aaron Bentley
Make info provide more related brances, and format all branches nicely
19
import os
77 by mbp at sourcefrog
- split info command out into separate file
20
import time
1551.15.43 by Aaron Bentley
Provide ways of getting at unicode-clean output
21
import sys
1534.5.1 by Robert Collins
Give info some reasonable output and tests.
22
1551.9.22 by Aaron Bentley
Use urlutils for info. Fixes bug #76229
23
from bzrlib import (
2363.5.5 by Aaron Bentley
add info.describe_format
24
    bzrdir,
1551.9.22 by Aaron Bentley
Use urlutils for info. Fixes bug #76229
25
    diff,
1551.15.41 by Aaron Bentley
Make info provide more related brances, and format all branches nicely
26
    errors,
1551.9.22 by Aaron Bentley
Use urlutils for info. Fixes bug #76229
27
    osutils,
28
    urlutils,
29
    )
1624.3.21 by Olaf Conradi
Make bzr info command work on both local and remote locations. Support
30
from bzrlib.errors import (NoWorkingTree, NotBranchError,
31
                           NoRepositoryPresent, NotLocalUrl)
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
32
from bzrlib.missing import find_unmerged
2258.1.1 by Robert Collins
Move info branch statistics gathering into the repository to allow smart server optimisation (Robert Collins).
33
from bzrlib.symbol_versioning import (deprecated_function,
2696.1.1 by Martin Pool
Remove things deprecated in 0.11 and earlier
34
        zero_eighteen)
77 by mbp at sourcefrog
- split info command out into separate file
35
462 by Martin Pool
- New form 'file_id in tree' to check if the file is present
36
1563.2.28 by Robert Collins
Add total_size to the revision_store api.
37
def plural(n, base='', pl=None):
38
    if n == 1:
39
        return base
1963.2.6 by Robey Pointer
pychecker is on crack; go back to using 'is None'.
40
    elif pl is not None:
1563.2.28 by Robert Collins
Add total_size to the revision_store api.
41
        return pl
42
    else:
43
        return 's'
44
45
1551.15.41 by Aaron Bentley
Make info provide more related brances, and format all branches nicely
46
class LocationList(object):
47
48
    def __init__(self, base_path):
1551.15.43 by Aaron Bentley
Provide ways of getting at unicode-clean output
49
        self.locs = []
1551.15.41 by Aaron Bentley
Make info provide more related brances, and format all branches nicely
50
        self.base_path = base_path
51
52
    def add_url(self, label, url):
1551.15.43 by Aaron Bentley
Provide ways of getting at unicode-clean output
53
        """Add a URL to the list, converting it to a path if possible"""
1551.15.41 by Aaron Bentley
Make info provide more related brances, and format all branches nicely
54
        if url is None:
55
            return
1551.15.43 by Aaron Bentley
Provide ways of getting at unicode-clean output
56
        try:
57
            path = urlutils.local_path_from_url(url)
58
        except errors.InvalidURL:
59
            self.locs.append((label, url))
60
        else:
1551.15.41 by Aaron Bentley
Make info provide more related brances, and format all branches nicely
61
            self.add_path(label, path)
2363.5.18 by Aaron Bentley
Get all tests passing
62
63
    def add_path(self, label, path):
1551.15.43 by Aaron Bentley
Provide ways of getting at unicode-clean output
64
        """Add a path, converting it to a relative path if possible"""
1551.15.41 by Aaron Bentley
Make info provide more related brances, and format all branches nicely
65
        try:
66
            path = osutils.relpath(self.base_path, path)
67
        except errors.PathNotChild:
68
            pass
69
        else:
70
            if path == '':
71
                path = '.'
72
        if path != '/':
73
            path = path.rstrip('/')
1551.15.43 by Aaron Bentley
Provide ways of getting at unicode-clean output
74
        self.locs.append((label, path))
2363.5.18 by Aaron Bentley
Get all tests passing
75
1551.15.43 by Aaron Bentley
Provide ways of getting at unicode-clean output
76
    def get_lines(self):
77
        max_len = max(len(l) for l, u in self.locs)
78
        return ["  %*s: %s\n" % (max_len, l, u) for l, u in self.locs ]
2363.5.18 by Aaron Bentley
Get all tests passing
79
80
81
def gather_location_info(repository, branch=None, working=None):
82
    locs = {}
1694.2.6 by Martin Pool
[merge] bzr.dev
83
    repository_path = repository.bzrdir.root_transport.base
2363.5.18 by Aaron Bentley
Get all tests passing
84
    if branch is not None:
85
        branch_path = branch.bzrdir.root_transport.base
86
        master_path = branch.get_bound_location()
87
        if master_path is None:
88
            master_path = branch_path
89
    else:
90
        branch_path = None
91
        master_path = None
92
    if working:
1694.2.6 by Martin Pool
[merge] bzr.dev
93
        working_path = working.bzrdir.root_transport.base
94
        if working_path != branch_path:
2363.5.18 by Aaron Bentley
Get all tests passing
95
            locs['light checkout root'] = working_path
96
        if master_path != branch_path:
1694.2.6 by Martin Pool
[merge] bzr.dev
97
            if repository.is_shared():
2363.5.18 by Aaron Bentley
Get all tests passing
98
                locs['repository checkout root'] = branch_path
1694.2.6 by Martin Pool
[merge] bzr.dev
99
            else:
2363.5.18 by Aaron Bentley
Get all tests passing
100
                locs['checkout root'] = branch_path
101
        if working_path != master_path:
102
            locs['checkout of branch'] = master_path
1694.2.6 by Martin Pool
[merge] bzr.dev
103
        elif repository.is_shared():
1551.15.41 by Aaron Bentley
Make info provide more related brances, and format all branches nicely
104
            locs['repository branch'] = branch_path
2363.5.18 by Aaron Bentley
Get all tests passing
105
        elif branch_path is not None:
1694.2.6 by Martin Pool
[merge] bzr.dev
106
            # standalone
2363.5.18 by Aaron Bentley
Get all tests passing
107
            locs['branch root'] = branch_path
108
    else:
109
        working_path = None
1624.3.48 by Olaf Conradi
Add info on standalone branches without a working tree.
110
        if repository.is_shared():
2363.5.18 by Aaron Bentley
Get all tests passing
111
            # lightweight checkout of branch in shared repository
112
            if branch_path is not None:
1551.15.41 by Aaron Bentley
Make info provide more related brances, and format all branches nicely
113
                locs['repository branch'] = branch_path
2363.5.18 by Aaron Bentley
Get all tests passing
114
        elif branch_path is not None:
115
            # standalone
116
            locs['branch root'] = branch_path
2363.5.19 by Aaron Bentley
Add support for bound branches
117
            if master_path != branch_path:
118
                locs['bound to branch'] = master_path
1624.3.48 by Olaf Conradi
Add info on standalone branches without a working tree.
119
        else:
2363.5.18 by Aaron Bentley
Get all tests passing
120
            locs['repository'] = repository_path
121
    if repository.is_shared():
122
        # lightweight checkout of branch in shared repository
123
        locs['shared repository'] = repository_path
2363.5.23 by Aaron Bentley
Output 2-tuples from gather_locations
124
    order = ['light checkout root', 'repository checkout root',
125
             'checkout root', 'checkout of branch', 'shared repository',
126
             'repository', 'repository branch', 'branch root',
127
             'bound to branch']
128
    return [(n, locs[n]) for n in order if n in locs]
2363.5.18 by Aaron Bentley
Get all tests passing
129
130
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
131
def _show_location_info(locs, outfile):
2363.5.18 by Aaron Bentley
Get all tests passing
132
    """Show known locations for working, branch and repository."""
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
133
    print >> outfile, 'Location:'
2804.4.3 by Alexander Belchenko
fix for test_info-tests: using osutils.getcwd instead of os.getcwd (sigh)
134
    path_list = LocationList(osutils.getcwd())
2363.5.23 by Aaron Bentley
Output 2-tuples from gather_locations
135
    for name, loc in locs:
136
        path_list.add_url(name, loc)
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
137
    outfile.writelines(path_list.get_lines())
138
1694.2.6 by Martin Pool
[merge] bzr.dev
139
1551.15.41 by Aaron Bentley
Make info provide more related brances, and format all branches nicely
140
def _gather_related_branches(branch):
2804.4.3 by Alexander Belchenko
fix for test_info-tests: using osutils.getcwd instead of os.getcwd (sigh)
141
    locs = LocationList(osutils.getcwd())
1551.15.41 by Aaron Bentley
Make info provide more related brances, and format all branches nicely
142
    locs.add_url('public branch', branch.get_public_branch())
143
    locs.add_url('push branch', branch.get_push_location())
144
    locs.add_url('parent branch', branch.get_parent())
145
    locs.add_url('submit branch', branch.get_submit_branch())
146
    return locs
1694.2.6 by Martin Pool
[merge] bzr.dev
147
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
148
1551.15.43 by Aaron Bentley
Provide ways of getting at unicode-clean output
149
def _show_related_info(branch, outfile):
1694.2.6 by Martin Pool
[merge] bzr.dev
150
    """Show parent and push location of branch."""
1551.15.41 by Aaron Bentley
Make info provide more related brances, and format all branches nicely
151
    locs = _gather_related_branches(branch)
1551.15.43 by Aaron Bentley
Provide ways of getting at unicode-clean output
152
    if len(locs.locs) > 0:
153
        print >> outfile
154
        print >> outfile, 'Related branches:'
155
        outfile.writelines(locs.get_lines())
1624.3.21 by Olaf Conradi
Make bzr info command work on both local and remote locations. Support
156
157
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
158
def _show_format_info(control=None, repository=None, branch=None,
159
                      working=None, outfile=None):
1624.3.21 by Olaf Conradi
Make bzr info command work on both local and remote locations. Support
160
    """Show known formats for control, working, branch and repository."""
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
161
    print >> outfile
162
    print >> outfile, 'Format:'
1624.3.21 by Olaf Conradi
Make bzr info command work on both local and remote locations. Support
163
    if control:
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
164
        print >> outfile, '       control: %s' % \
165
            control._format.get_format_description()
1624.3.21 by Olaf Conradi
Make bzr info command work on both local and remote locations. Support
166
    if working:
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
167
        print >> outfile, '  working tree: %s' % \
168
            working._format.get_format_description()
1624.3.21 by Olaf Conradi
Make bzr info command work on both local and remote locations. Support
169
    if branch:
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
170
        print >> outfile, '        branch: %s' % \
171
            branch._format.get_format_description()
1624.3.21 by Olaf Conradi
Make bzr info command work on both local and remote locations. Support
172
    if repository:
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
173
        print >> outfile, '    repository: %s' % \
174
            repository._format.get_format_description()
175
176
177
def _show_locking_info(repository, branch=None, working=None, outfile=None):
1694.2.6 by Martin Pool
[merge] bzr.dev
178
    """Show locking status of working, branch and repository."""
179
    if (repository.get_physical_lock_status() or
180
        (branch and branch.get_physical_lock_status()) or
181
        (working and working.get_physical_lock_status())):
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
182
        print >> outfile
183
        print >> outfile, 'Lock status:'
1694.2.6 by Martin Pool
[merge] bzr.dev
184
        if working:
185
            if working.get_physical_lock_status():
186
                status = 'locked'
187
            else:
188
                status = 'unlocked'
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
189
            print >> outfile, '  working tree: %s' % status
1694.2.6 by Martin Pool
[merge] bzr.dev
190
        if branch:
191
            if branch.get_physical_lock_status():
192
                status = 'locked'
193
            else:
194
                status = 'unlocked'
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
195
            print >> outfile, '        branch: %s' % status
1694.2.6 by Martin Pool
[merge] bzr.dev
196
        if repository:
197
            if repository.get_physical_lock_status():
198
                status = 'locked'
199
            else:
200
                status = 'unlocked'
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
201
            print >> outfile, '    repository: %s' % status
202
203
204
def _show_missing_revisions_branch(branch, outfile):
1624.3.21 by Olaf Conradi
Make bzr info command work on both local and remote locations. Support
205
    """Show missing master revisions in branch."""
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
206
    # Try with inaccessible branch ?
1624.3.2 by Olaf Conradi
Implemented table of constructs from BzrInfo specification.
207
    master = branch.get_master_branch()
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
208
    if master:
1624.3.2 by Olaf Conradi
Implemented table of constructs from BzrInfo specification.
209
        local_extra, remote_extra = find_unmerged(branch, master)
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
210
        if remote_extra:
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
211
            print >> outfile
212
            print >> outfile, ('Branch is out of date: missing %d ' +
213
                               'revision%s.') % (len(remote_extra),
214
                                                 plural(len(remote_extra)))
215
216
217
def _show_missing_revisions_working(working, outfile):
1624.3.21 by Olaf Conradi
Make bzr info command work on both local and remote locations. Support
218
    """Show missing revisions in working tree."""
219
    branch = working.branch
220
    basis = working.basis_tree()
221
    work_inv = working.inventory
2249.4.2 by Wouter van Heyst
Convert callers of Branch.revision_history() to Branch.last_revision_info() where sensible.
222
    branch_revno, branch_last_revision = branch.last_revision_info()
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
223
    try:
224
        tree_last_id = working.get_parent_ids()[0]
225
    except IndexError:
226
        tree_last_id = None
1624.3.21 by Olaf Conradi
Make bzr info command work on both local and remote locations. Support
227
2249.4.2 by Wouter van Heyst
Convert callers of Branch.revision_history() to Branch.last_revision_info() where sensible.
228
    if branch_revno and tree_last_id != branch_last_revision:
1624.3.11 by Olaf Conradi
Test cases exposed a bug in missing revisions count of working tree. It
229
        tree_last_revno = branch.revision_id_to_revno(tree_last_id)
2249.4.2 by Wouter van Heyst
Convert callers of Branch.revision_history() to Branch.last_revision_info() where sensible.
230
        missing_count = branch_revno - tree_last_revno
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
231
        print >> outfile
232
        print >> outfile, ('Working tree is out of date: missing %d ' +
233
                           'revision%s.') % (missing_count,
234
                                             plural(missing_count))
235
236
237
def _show_working_stats(working, outfile):
1624.3.21 by Olaf Conradi
Make bzr info command work on both local and remote locations. Support
238
    """Show statistics about a working tree."""
239
    basis = working.basis_tree()
240
    work_inv = working.inventory
1852.10.3 by Robert Collins
Remove all uses of compare_trees and replace with Tree.changes_from throughout bzrlib.
241
    delta = working.changes_from(basis, want_unchanged=True)
1624.3.21 by Olaf Conradi
Make bzr info command work on both local and remote locations. Support
242
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
243
    print >> outfile
244
    print >> outfile, 'In the working tree:'
245
    print >> outfile, '  %8s unchanged' % len(delta.unchanged)
246
    print >> outfile, '  %8d modified' % len(delta.modified)
247
    print >> outfile, '  %8d added' % len(delta.added)
248
    print >> outfile, '  %8d removed' % len(delta.removed)
249
    print >> outfile, '  %8d renamed' % len(delta.renamed)
462 by Martin Pool
- New form 'file_id in tree' to check if the file is present
250
251
    ignore_cnt = unknown_cnt = 0
252
    for path in working.extras():
253
        if working.is_ignored(path):
254
            ignore_cnt += 1
255
        else:
256
            unknown_cnt += 1
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
257
    print >> outfile, '  %8d unknown' % unknown_cnt
258
    print >> outfile, '  %8d ignored' % ignore_cnt
462 by Martin Pool
- New form 'file_id in tree' to check if the file is present
259
260
    dir_cnt = 0
1731.1.39 by Aaron Bentley
Reject removing is_root
261
    for file_id in work_inv:
262
        if (work_inv.get_file_kind(file_id) == 'directory' and 
263
            not work_inv.is_root(file_id)):
264
            dir_cnt += 1
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
265
    print >> outfile, '  %8d versioned %s' \
462 by Martin Pool
- New form 'file_id in tree' to check if the file is present
266
          % (dir_cnt,
267
             plural(dir_cnt, 'subdirectory', 'subdirectories'))
77 by mbp at sourcefrog
- split info command out into separate file
268
1624.3.21 by Olaf Conradi
Make bzr info command work on both local and remote locations. Support
269
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
270
def _show_branch_stats(branch, verbose, outfile):
1624.3.21 by Olaf Conradi
Make bzr info command work on both local and remote locations. Support
271
    """Show statistics about a branch."""
2258.1.1 by Robert Collins
Move info branch statistics gathering into the repository to allow smart server optimisation (Robert Collins).
272
    revno, head = branch.last_revision_info()
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
273
    print >> outfile
274
    print >> outfile, 'Branch history:'
275
    print >> outfile, '  %8d revision%s' % (revno, plural(revno))
2258.1.1 by Robert Collins
Move info branch statistics gathering into the repository to allow smart server optimisation (Robert Collins).
276
    stats = branch.repository.gather_stats(head, committers=verbose)
1624.3.21 by Olaf Conradi
Make bzr info command work on both local and remote locations. Support
277
    if verbose:
2258.1.1 by Robert Collins
Move info branch statistics gathering into the repository to allow smart server optimisation (Robert Collins).
278
        committers = stats['committers']
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
279
        print >> outfile, '  %8d committer%s' % (committers,
280
            plural(committers))
2258.1.1 by Robert Collins
Move info branch statistics gathering into the repository to allow smart server optimisation (Robert Collins).
281
    if revno:
282
        timestamp, timezone = stats['firstrev']
283
        age = int((time.time() - timestamp) / 3600 / 24)
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
284
        print >> outfile, '  %8d day%s old' % (age, plural(age))
285
        print >> outfile, '   first revision: %s' % osutils.format_date(
286
            timestamp, timezone)
2258.1.1 by Robert Collins
Move info branch statistics gathering into the repository to allow smart server optimisation (Robert Collins).
287
        timestamp, timezone = stats['latestrev']
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
288
        print >> outfile, '  latest revision: %s' % osutils.format_date(
289
            timestamp, timezone)
2258.1.2 by Robert Collins
New version of gather_stats which gathers aggregate data too.
290
    return stats
1624.3.21 by Olaf Conradi
Make bzr info command work on both local and remote locations. Support
291
292
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
293
def _show_repository_info(repository, outfile):
1624.3.21 by Olaf Conradi
Make bzr info command work on both local and remote locations. Support
294
    """Show settings of a repository."""
295
    if repository.make_working_trees():
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
296
        print >> outfile
297
        print >> outfile, ('Create working tree for new branches inside ' +
298
                           'the repository.')
299
300
301
def _show_repository_stats(stats, outfile):
1624.3.21 by Olaf Conradi
Make bzr info command work on both local and remote locations. Support
302
    """Show statistics about a repository."""
2258.1.2 by Robert Collins
New version of gather_stats which gathers aggregate data too.
303
    if 'revisions' in stats or 'size' in stats:
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
304
        print >> outfile
305
        print >> outfile, 'Repository:'
2258.1.2 by Robert Collins
New version of gather_stats which gathers aggregate data too.
306
    if 'revisions' in stats:
307
        revisions = stats['revisions']
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
308
        print >> outfile, '  %8d revision%s' % (revisions, plural(revisions))
2258.1.2 by Robert Collins
New version of gather_stats which gathers aggregate data too.
309
    if 'size' in stats:
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
310
        print >> outfile, '  %8d KiB' % (stats['size']/1024)
1624.3.21 by Olaf Conradi
Make bzr info command work on both local and remote locations. Support
311
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
312
def show_bzrdir_info(a_bzrdir, verbose=False, outfile=None):
2363.5.1 by Aaron Bentley
Unify info display into show_component_info
313
    """Output to stdout the 'info' for a_bzrdir."""
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
314
    if outfile is None:
315
        outfile = sys.stdout
2363.5.1 by Aaron Bentley
Unify info display into show_component_info
316
    try:
2363.5.9 by Aaron Bentley
Merge from bzr.dev
317
        tree = a_bzrdir.open_workingtree(
318
            recommend_upgrade=False)
2363.5.1 by Aaron Bentley
Unify info display into show_component_info
319
    except (NoWorkingTree, NotLocalUrl):
320
        tree = None
321
        try:
322
            branch = a_bzrdir.open_branch()
323
        except NotBranchError:
324
            branch = None
325
            try:
326
                repository = a_bzrdir.open_repository()
327
            except NoRepositoryPresent:
328
                # Return silently; cmd_info already returned NotBranchError
329
                # if no bzrdir could be opened.
330
                return
331
            else:
332
                lockable = repository
333
        else:
334
            repository = branch.repository
335
            lockable = branch
336
    else:
337
        branch = tree.branch
338
        repository = branch.repository
339
        lockable = tree
340
341
    lockable.lock_read()
342
    try:
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
343
        show_component_info(a_bzrdir, repository, branch, tree, verbose,
344
                            outfile)
2363.5.1 by Aaron Bentley
Unify info display into show_component_info
345
    finally:
346
        lockable.unlock()
347
348
349
def show_component_info(control, repository, branch=None, working=None,
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
350
    verbose=1, outfile=None):
2363.5.1 by Aaron Bentley
Unify info display into show_component_info
351
    """Write info about all bzrdir components to stdout"""
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
352
    if outfile is None:
353
        outfile = sys.stdout
2363.5.7 by Aaron Bentley
Make verbose mean what I want
354
    if verbose is False:
355
        verbose = 1
356
    if verbose is True:
357
        verbose = 2
2363.5.6 by Aaron Bentley
Add short format description
358
    layout = describe_layout(repository, branch, working)
359
    format = describe_format(control, repository, branch, working)
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
360
    print >> outfile, "%s (format: %s)" % (layout, format)
361
    _show_location_info(gather_location_info(repository, branch, working),
362
                        outfile)
2584.2.1 by Adeodato Simó
Make `bzr info` show related branches in non-verbose mode.
363
    if branch is not None:
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
364
        _show_related_info(branch, outfile)
2363.5.7 by Aaron Bentley
Make verbose mean what I want
365
    if verbose == 0:
366
        return
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
367
    _show_format_info(control, repository, branch, working, outfile)
368
    _show_locking_info(repository, branch, working, outfile)
2363.5.1 by Aaron Bentley
Unify info display into show_component_info
369
    if branch is not None:
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
370
        _show_missing_revisions_branch(branch, outfile)
2363.5.1 by Aaron Bentley
Unify info display into show_component_info
371
    if working is not None:
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
372
        _show_missing_revisions_working(working, outfile)
373
        _show_working_stats(working, outfile)
2363.5.1 by Aaron Bentley
Unify info display into show_component_info
374
    elif branch is not None:
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
375
        _show_missing_revisions_branch(branch, outfile)
2363.5.1 by Aaron Bentley
Unify info display into show_component_info
376
    if branch is not None:
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
377
        stats = _show_branch_stats(branch, verbose==2, outfile)
2363.5.1 by Aaron Bentley
Unify info display into show_component_info
378
    else:
379
        stats = repository.gather_stats()
380
    if branch is None and working is None:
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
381
        _show_repository_info(repository, outfile)
382
    _show_repository_stats(stats, outfile)
2363.5.1 by Aaron Bentley
Unify info display into show_component_info
383
384
2363.5.2 by Aaron Bentley
Implement layout description
385
def describe_layout(repository=None, branch=None, tree=None):
386
    """Convert a control directory layout into a user-understandable term
387
388
    Common outputs include "Standalone tree", "Repository branch" and
389
    "Checkout".  Uncommon outputs include "Unshared repository with trees"
390
    and "Empty control directory"
391
    """
392
    if repository is None:
393
        return 'Empty control directory'
394
    if branch is None and tree is None:
395
        if repository.is_shared():
396
            phrase = 'Shared repository'
397
        else:
398
            phrase = 'Unshared repository'
399
        if repository.make_working_trees():
400
            phrase += ' with trees'
401
        return phrase
402
    else:
403
        if repository.is_shared():
404
            independence = "Repository "
405
        else:
406
            independence = "Standalone "
407
        if tree is not None:
408
            phrase = "tree"
409
        else:
410
            phrase = "branch"
411
        if branch is None and tree is not None:
412
            phrase = "branchless tree"
413
        else:
414
            if (tree is not None and tree.bzrdir.root_transport.base !=
415
                branch.bzrdir.root_transport.base):
2363.5.4 by Aaron Bentley
Eliminate the concept of a 'repository lightweight checkout'
416
                independence = ''
2363.5.2 by Aaron Bentley
Implement layout description
417
                phrase = "Lightweight checkout"
418
            elif branch.get_bound_location() is not None:
419
                if independence == 'Standalone ':
420
                    independence = ''
421
                if tree is None:
422
                    phrase = "Bound branch"
423
                else:
424
                    phrase = "Checkout"
425
        if independence != "":
426
            phrase = phrase.lower()
427
        return "%s%s" % (independence, phrase)
428
429
2363.5.5 by Aaron Bentley
add info.describe_format
430
def describe_format(control, repository, branch, tree):
431
    """Determine the format of an existing control directory
432
433
    Several candidates may be found.  If so, the names are returned as a
2363.5.17 by Aaron Bentley
Change separator from '/' to 'or'
434
    single string, separated by ' or '.
2363.5.5 by Aaron Bentley
add info.describe_format
435
436
    If no matching candidate is found, "unnamed" is returned.
437
    """
438
    candidates  = []
2363.5.6 by Aaron Bentley
Add short format description
439
    if (branch is not None and tree is not None and
440
        branch.bzrdir.root_transport.base !=
441
        tree.bzrdir.root_transport.base):
442
        branch = None
443
        repository = None
2363.5.5 by Aaron Bentley
add info.describe_format
444
    for key in bzrdir.format_registry.keys():
445
        format = bzrdir.format_registry.make_bzrdir(key)
446
        if isinstance(format, bzrdir.BzrDirMetaFormat1):
447
            if (tree and format.workingtree_format !=
448
                tree._format):
449
                continue
450
            if (branch and format.get_branch_format() !=
451
                branch._format):
452
                continue
453
            if (repository and format.repository_format !=
454
                repository._format):
455
                continue
456
        if format.__class__ is not control._format.__class__:
457
            continue
458
        candidates.append(key)
459
    if len(candidates) == 0:
460
        return 'unnamed'
461
    new_candidates = [c for c in candidates if c != 'default']
462
    if len(new_candidates) > 0:
463
        candidates = new_candidates
2363.5.6 by Aaron Bentley
Add short format description
464
    new_candidates = [c for c in candidates if not
465
        bzrdir.format_registry.get_info(c).hidden]
466
    if len(new_candidates) > 0:
467
        candidates = new_candidates
2363.5.17 by Aaron Bentley
Change separator from '/' to 'or'
468
    return ' or '.join(candidates)
2363.5.5 by Aaron Bentley
add info.describe_format
469
1624.3.21 by Olaf Conradi
Make bzr info command work on both local and remote locations. Support
470
2363.5.26 by Aaron Bentley
fix symbol spelling
471
@deprecated_function(zero_eighteen)
1624.3.21 by Olaf Conradi
Make bzr info command work on both local and remote locations. Support
472
def show_tree_info(working, verbose):
473
    """Output to stdout the 'info' for working."""
474
    branch = working.branch
475
    repository = branch.repository
476
    control = working.bzrdir
2363.5.1 by Aaron Bentley
Unify info display into show_component_info
477
    show_component_info(control, repository, branch, working, verbose)
478
479
2363.5.26 by Aaron Bentley
fix symbol spelling
480
@deprecated_function(zero_eighteen)
1624.3.21 by Olaf Conradi
Make bzr info command work on both local and remote locations. Support
481
def show_branch_info(branch, verbose):
482
    """Output to stdout the 'info' for branch."""
483
    repository = branch.repository
484
    control = branch.bzrdir
2363.5.1 by Aaron Bentley
Unify info display into show_component_info
485
    show_component_info(control, repository, branch, verbose=verbose)
486
487
2363.5.26 by Aaron Bentley
fix symbol spelling
488
@deprecated_function(zero_eighteen)
1624.3.21 by Olaf Conradi
Make bzr info command work on both local and remote locations. Support
489
def show_repository_info(repository, verbose):
1694.2.6 by Martin Pool
[merge] bzr.dev
490
    """Output to stdout the 'info' for repository."""
1624.3.21 by Olaf Conradi
Make bzr info command work on both local and remote locations. Support
491
    control = repository.bzrdir
2363.5.1 by Aaron Bentley
Unify info display into show_component_info
492
    show_component_info(control, repository, verbose=verbose)