~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/info.py

  • Committer: Robert Collins
  • Date: 2005-10-18 05:26:22 UTC
  • mto: This revision was merged to the branch mainline in revision 1463.
  • Revision ID: robertc@robertcollins.net-20051018052622-653d638c9e26fde4
fix broken tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
# along with this program; if not, write to the Free Software
17
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
 
19
 
__all__ = ['show_bzrdir_info']
20
 
 
21
19
import time
22
20
 
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
 
import bzrlib.osutils as osutils
29
 
from bzrlib.symbol_versioning import *
30
 
 
31
 
 
32
 
def plural(n, base='', pl=None):
33
 
    if n == 1:
34
 
        return base
35
 
    elif pl != None:
36
 
        return pl
37
 
    else:
38
 
        return 's'
39
 
 
40
 
 
41
 
def _repo_relpath(repo_path, path):
42
 
    """Return path with common prefix of repository path removed.
43
 
 
44
 
    If path is not part of the repository, the original path is returned.
45
 
    If path is equal to the repository, the current directory marker '.' is
46
 
    returned.
47
 
    """
48
 
    path = osutils.normalizepath(path)
49
 
    repo_path = osutils.normalizepath(repo_path)
50
 
    if path == repo_path:
51
 
        return '.'
52
 
    if osutils.is_inside(repo_path, path):
53
 
        return osutils.relpath(repo_path, path)
54
 
    return path
55
 
 
56
 
 
57
 
def _show_location_info(repository, branch=None, working=None):
58
 
    """Show known locations for working, branch and repository."""
59
 
    repository_path = repository.bzrdir.root_transport.base
60
 
    print 'Location:'
61
 
    if working and branch:
62
 
        working_path = working.bzrdir.root_transport.base
63
 
        branch_path = branch.bzrdir.root_transport.base
64
 
        if working_path != branch_path:
65
 
            # lightweight checkout
66
 
            print '  light checkout root: %s' % working_path
67
 
            if repository.is_shared():
68
 
                # lightweight checkout of branch in shared repository
69
 
                print '    shared repository: %s' % repository_path
70
 
                print '    repository branch: %s' % (
71
 
                    _repo_relpath(repository_path, branch_path))
72
 
            else:
73
 
                # lightweight checkout of standalone branch
74
 
                print '   checkout of branch: %s' % branch_path
75
 
        elif repository.is_shared():
76
 
            # branch with tree inside shared repository
77
 
            print '    shared repository: %s' % repository_path
78
 
            print '  repository checkout: %s' % (
79
 
                _repo_relpath(repository_path, branch_path))
80
 
        elif branch.get_bound_location():
81
 
            # normal checkout
82
 
            print '       checkout root: %s' % working_path
83
 
            print '  checkout of branch: %s' % branch.get_bound_location()
 
21
from bzrlib.osutils import format_date
 
22
 
 
23
 
 
24
def _countiter(it):
 
25
    # surely there's a builtin for this?
 
26
    i = 0
 
27
    for j in it:
 
28
        i += 1
 
29
    return i        
 
30
 
 
31
 
 
32
 
 
33
def show_info(b):
 
34
    import diff
 
35
    
 
36
    print 'branch format:', b.controlfile('branch-format', 'r').readline().rstrip('\n')
 
37
 
 
38
    def plural(n, base='', pl=None):
 
39
        if n == 1:
 
40
            return base
 
41
        elif pl != None:
 
42
            return pl
84
43
        else:
85
 
            # standalone
86
 
            print '  branch root: %s' % working_path
87
 
    elif branch:
88
 
        # branch is part of shared repository
89
 
        assert repository.is_shared()
90
 
        branch_path = branch.bzrdir.root_transport.base
91
 
        print '  shared repository: %s' % repository_path
92
 
        print '  repository branch: %s' % (
93
 
            _repo_relpath(repository_path, branch_path))
94
 
    else:
95
 
        # shared repository
96
 
        assert repository.is_shared()
97
 
        print '  shared repository: %s' % repository_path
98
 
 
99
 
 
100
 
def _show_related_info(branch):
101
 
    """Show parent and push location of branch."""
102
 
    if branch.get_parent() or branch.get_push_location():
103
 
        print
104
 
        print 'Related branches:'
105
 
        if branch.get_parent():
106
 
            if branch.get_push_location():
107
 
                print '      parent branch: %s' % branch.get_parent()
108
 
            else:
109
 
                print '  parent branch: %s' % branch.get_parent()
110
 
        if branch.get_push_location():
111
 
            print '  publish to branch: %s' % branch.get_push_location()
112
 
 
113
 
 
114
 
def _show_format_info(control=None, repository=None, branch=None, working=None):
115
 
    """Show known formats for control, working, branch and repository."""
116
 
    print
117
 
    print 'Format:'
118
 
    if control:
119
 
        print '       control: %s' % control._format.get_format_description()
120
 
    if working:
121
 
        print '  working tree: %s' % working._format.get_format_description()
122
 
    if branch:
123
 
        print '        branch: %s' % branch._format.get_format_description()
124
 
    if repository:
125
 
        print '    repository: %s' % repository._format.get_format_description()
126
 
 
127
 
 
128
 
def _show_locking_info(repository, branch=None, working=None):
129
 
    """Show locking status of working, branch and repository."""
130
 
    if (repository.get_physical_lock_status() or
131
 
        (branch and branch.get_physical_lock_status()) or
132
 
        (working and working.get_physical_lock_status())):
133
 
        print
134
 
        print 'Lock status:'
135
 
        if working:
136
 
            if working.get_physical_lock_status():
137
 
                status = 'locked'
138
 
            else:
139
 
                status = 'unlocked'
140
 
            print '  working tree: %s' % status
141
 
        if branch:
142
 
            if branch.get_physical_lock_status():
143
 
                status = 'locked'
144
 
            else:
145
 
                status = 'unlocked'
146
 
            print '        branch: %s' % status
147
 
        if repository:
148
 
            if repository.get_physical_lock_status():
149
 
                status = 'locked'
150
 
            else:
151
 
                status = 'unlocked'
152
 
            print '    repository: %s' % status
153
 
 
154
 
 
155
 
def _show_missing_revisions_branch(branch):
156
 
    """Show missing master revisions in branch."""
157
 
    # Try with inaccessible branch ?
158
 
    master = branch.get_master_branch()
159
 
    if master:
160
 
        local_extra, remote_extra = find_unmerged(branch, master)
161
 
        if remote_extra:
162
 
            print
163
 
            print 'Branch is out of date: missing %d revision%s.' % (
164
 
                len(remote_extra), plural(len(remote_extra)))
165
 
 
166
 
 
167
 
def _show_missing_revisions_working(working):
168
 
    """Show missing revisions in working tree."""
169
 
    branch = working.branch
170
 
    basis = working.basis_tree()
171
 
    work_inv = working.inventory
172
 
    delta = diff.compare_trees(basis, working, want_unchanged=True)
173
 
    history = branch.revision_history()
174
 
    tree_last_id = working.last_revision()
175
 
 
176
 
    if len(history) and tree_last_id != history[-1]:
177
 
        tree_last_revno = branch.revision_id_to_revno(tree_last_id)
178
 
        missing_count = len(history) - tree_last_revno
179
 
        print
180
 
        print 'Working tree is out of date: missing %d revision%s.' % (
181
 
            missing_count, plural(missing_count))
182
 
 
183
 
 
184
 
def _show_working_stats(working):
185
 
    """Show statistics about a working tree."""
186
 
    basis = working.basis_tree()
187
 
    work_inv = working.inventory
188
 
    delta = diff.compare_trees(basis, working, want_unchanged=True)
189
 
 
190
 
    print
191
 
    print 'In the working tree:'
 
44
            return 's'
 
45
 
 
46
    count_version_dirs = 0
 
47
 
 
48
    basis = b.basis_tree()
 
49
    working = b.working_tree()
 
50
    work_inv = working.inventory
 
51
    delta = diff.compare_trees(basis, working, want_unchanged=True)
 
52
    
 
53
    print
 
54
    print 'in the working tree:'
192
55
    print '  %8s unchanged' % len(delta.unchanged)
193
56
    print '  %8d modified' % len(delta.modified)
194
57
    print '  %8d added' % len(delta.added)
201
64
            ignore_cnt += 1
202
65
        else:
203
66
            unknown_cnt += 1
 
67
 
204
68
    print '  %8d unknown' % unknown_cnt
205
69
    print '  %8d ignored' % ignore_cnt
206
70
 
212
76
          % (dir_cnt,
213
77
             plural(dir_cnt, 'subdirectory', 'subdirectories'))
214
78
 
215
 
 
216
 
def _show_branch_stats(branch, verbose):
217
 
    """Show statistics about a branch."""
218
 
    repository = branch.repository
219
 
    history = branch.revision_history()
220
 
 
221
79
    print
222
 
    print 'Branch history:'
 
80
    print 'branch history:'
 
81
    history = b.revision_history()
223
82
    revno = len(history)
224
83
    print '  %8d revision%s' % (revno, plural(revno))
225
 
    if verbose:
226
 
        committers = {}
227
 
        for rev in history:
228
 
            committers[repository.get_revision(rev).committer] = True
229
 
        print '  %8d committer%s' % (len(committers), plural(len(committers)))
 
84
    committers = {}
 
85
    for rev in history:
 
86
        committers[b.get_revision(rev).committer] = True
 
87
    print '  %8d committer%s' % (len(committers), plural(len(committers)))
230
88
    if revno > 0:
231
 
        firstrev = repository.get_revision(history[0])
 
89
        firstrev = b.get_revision(history[0])
232
90
        age = int((time.time() - firstrev.timestamp) / 3600 / 24)
233
91
        print '  %8d day%s old' % (age, plural(age))
234
 
        print '   first revision: %s' % osutils.format_date(firstrev.timestamp,
235
 
                                                            firstrev.timezone)
 
92
        print '   first revision: %s' % format_date(firstrev.timestamp,
 
93
                                                    firstrev.timezone)
236
94
 
237
 
        lastrev = repository.get_revision(history[-1])
238
 
        print '  latest revision: %s' % osutils.format_date(lastrev.timestamp,
239
 
                                                            lastrev.timezone)
 
95
        lastrev = b.get_revision(history[-1])
 
96
        print '  latest revision: %s' % format_date(lastrev.timestamp,
 
97
                                                    lastrev.timezone)
240
98
 
241
99
#     print
242
 
#     print 'Text store:'
243
 
#     c, t = branch.text_store.total_size()
 
100
#     print 'text store:'
 
101
#     c, t = b.text_store.total_size()
244
102
#     print '  %8d file texts' % c
245
 
#     print '  %8d KiB' % (t/1024)
 
103
#     print '  %8d kB' % (t/1024)
 
104
 
 
105
    print
 
106
    print 'revision store:'
 
107
    c, t = b.revision_store.total_size()
 
108
    print '  %8d revisions' % c
 
109
    print '  %8d kB' % (t/1024)
 
110
 
246
111
 
247
112
#     print
248
 
#     print 'Inventory store:'
249
 
#     c, t = branch.inventory_store.total_size()
 
113
#     print 'inventory store:'
 
114
#     c, t = b.inventory_store.total_size()
250
115
#     print '  %8d inventories' % c
251
 
#     print '  %8d KiB' % (t/1024)
252
 
 
253
 
 
254
 
def _show_repository_info(repository):
255
 
    """Show settings of a repository."""
256
 
    if repository.make_working_trees():
257
 
        print
258
 
        print 'Create working tree for new branches inside the repository.'
259
 
 
260
 
 
261
 
def _show_repository_stats(repository):
262
 
    """Show statistics about a repository."""
263
 
    if repository.bzrdir.root_transport.listable():
264
 
        print
265
 
        print 'Revision store:'
266
 
        c, t = repository._revision_store.total_size(repository.get_transaction())
267
 
        print '  %8d revision%s' % (c, plural(c))
268
 
        print '  %8d KiB' % (t/1024)
269
 
 
270
 
 
271
 
@deprecated_function(zero_eight)
272
 
def show_info(b):
273
 
    """Please see show_bzrdir_info."""
274
 
    return show_bzrdir_info(b.bzrdir)
275
 
 
276
 
 
277
 
def show_bzrdir_info(a_bzrdir, verbose=False):
278
 
    """Output to stdout the 'info' for a_bzrdir."""
279
 
    try:
280
 
        working = a_bzrdir.open_workingtree()
281
 
        working.lock_read()
282
 
        try:
283
 
            show_tree_info(working, verbose)
284
 
        finally:
285
 
            working.unlock()
286
 
        return
287
 
    except (NoWorkingTree, NotLocalUrl):
288
 
        pass
289
 
 
290
 
    try:
291
 
        branch = a_bzrdir.open_branch()
292
 
        branch.lock_read()
293
 
        try:
294
 
            show_branch_info(branch, verbose)
295
 
        finally:
296
 
            branch.unlock()
297
 
        return
298
 
    except NotBranchError:
299
 
        pass
300
 
 
301
 
    try:
302
 
        repository = a_bzrdir.open_repository()
303
 
        repository.lock_read()
304
 
        try:
305
 
            show_repository_info(repository, verbose)
306
 
        finally:
307
 
            repository.unlock()
308
 
        return
309
 
    except NoRepositoryPresent:
310
 
        pass
311
 
 
312
 
    # Return silently, cmd_info already returned NotBranchError if no bzrdir
313
 
    # could be opened.
314
 
 
315
 
 
316
 
def show_tree_info(working, verbose):
317
 
    """Output to stdout the 'info' for working."""
318
 
    branch = working.branch
319
 
    repository = branch.repository
320
 
    control = working.bzrdir
321
 
 
322
 
    _show_location_info(repository, branch, working)
323
 
    _show_related_info(branch)
324
 
    _show_format_info(control, repository, branch, working)
325
 
    _show_locking_info(repository, branch, working)
326
 
    _show_missing_revisions_branch(branch)
327
 
    _show_missing_revisions_working(working)
328
 
    _show_working_stats(working)
329
 
    _show_branch_stats(branch, verbose)
330
 
    _show_repository_stats(repository)
331
 
 
332
 
 
333
 
def show_branch_info(branch, verbose):
334
 
    """Output to stdout the 'info' for branch."""
335
 
    repository = branch.repository
336
 
    control = branch.bzrdir
337
 
 
338
 
    _show_location_info(repository, branch)
339
 
    _show_related_info(branch)
340
 
    _show_format_info(control, repository, branch)
341
 
    _show_locking_info(repository, branch)
342
 
    _show_missing_revisions_branch(branch)
343
 
    _show_branch_stats(branch, verbose)
344
 
    _show_repository_stats(repository)
345
 
 
346
 
 
347
 
def show_repository_info(repository, verbose):
348
 
    """Output to stdout the 'info' for repository."""
349
 
    control = repository.bzrdir
350
 
 
351
 
    _show_location_info(repository)
352
 
    _show_format_info(control, repository)
353
 
    _show_locking_info(repository)
354
 
    _show_repository_info(repository)
355
 
    _show_repository_stats(repository)
 
116
#     print '  %8d kB' % (t/1024)
 
117