/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

New call get_format_description to give a user-friendly description of a
format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2004, 2005 by Martin Pool
 
2
# Copyright (C) 2005 by Canonical Ltd
 
3
 
 
4
 
 
5
# This program is free software; you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License as published by
 
7
# the Free Software Foundation; either version 2 of the License, or
 
8
# (at your option) any later version.
 
9
 
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU General Public License for more details.
 
14
 
 
15
# You should have received a copy of the GNU General Public License
 
16
# along with this program; if not, write to the Free Software
 
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 
 
19
__all__ = ['show_bzrdir_info']
 
20
 
 
21
import time
 
22
 
 
23
 
 
24
import bzrlib.diff as diff
 
25
from bzrlib.missing import find_unmerged
 
26
from bzrlib.osutils import format_date
 
27
from bzrlib.symbol_versioning import *
 
28
 
 
29
 
 
30
def _countiter(it):
 
31
    # surely there's a builtin for this?
 
32
    i = 0
 
33
    for j in it:
 
34
        i += 1
 
35
    return i        
 
36
 
 
37
 
 
38
def plural(n, base='', pl=None):
 
39
    if n == 1:
 
40
        return base
 
41
    elif pl != None:
 
42
        return pl
 
43
    else:
 
44
        return 's'
 
45
 
 
46
 
 
47
@deprecated_function(zero_eight)
 
48
def show_info(b):
 
49
    """Please see show_bzrdir_info."""
 
50
    return show_bzrdir_info(b.bzrdir)
 
51
 
 
52
 
 
53
def show_bzrdir_info(a_bzrdir):
 
54
    """Output to stdout the 'info' for a_bzrdir."""
 
55
 
 
56
    working = a_bzrdir.open_workingtree()
 
57
    working.lock_read()
 
58
    try:
 
59
        show_tree_info(working)
 
60
    finally:
 
61
        working.unlock()
 
62
 
 
63
 
 
64
def show_tree_info(working):
 
65
    """Output to stdout the 'info' for working."""
 
66
 
 
67
    branch = working.branch
 
68
    repository = branch.repository
 
69
    control_format = working.bzrdir._format.get_format_description()
 
70
    working_format = working._format.get_format_description()
 
71
    branch_format = branch._format.get_format_description()
 
72
    repository_format = repository._format.get_format_description()
 
73
 
 
74
    print 'Location:'
 
75
    if working.bzrdir != branch.bzrdir:
 
76
        # Lightweight checkout
 
77
        print '       checkout root: %s' % (
 
78
            working.bzrdir.root_transport.base)
 
79
        print '  checkout of branch: %s' % (
 
80
            branch.bzrdir.root_transport.base)
 
81
    else:
 
82
        # Standalone or bound branch (normal checkout)
 
83
        print '         branch root: %s' % (
 
84
            branch.bzrdir.root_transport.base)
 
85
        if branch.get_bound_location():
 
86
            print '     bound to branch: %s' % branch.get_bound_location()
 
87
 
 
88
    if repository.bzrdir != branch.bzrdir:
 
89
        if repository.is_shared():
 
90
            print '   shared repository: %s' % (
 
91
                repository.bzrdir.root_transport.base)
 
92
        else:
 
93
            print '          repository: %s' % (
 
94
                repository.bzrdir.root_transport.base)
 
95
 
 
96
    if branch.get_parent():
 
97
        print '       parent branch: %s' % branch.get_parent()
 
98
    if branch.get_push_location():
 
99
        print '      push to branch: %s' % branch.get_push_location()
 
100
 
 
101
    print
 
102
    print 'Format:'
 
103
    print '       control: %s' % control_format
 
104
    print '  working tree: %s' % working_format
 
105
    print '        branch: %s' % branch_format
 
106
    print '    repository: %s' % repository_format
 
107
 
 
108
    basis = working.basis_tree()
 
109
    work_inv = working.inventory
 
110
    delta = diff.compare_trees(basis, working, want_unchanged=True)
 
111
    history = branch.revision_history()
 
112
    
 
113
    print
 
114
    # Try with inaccessible branch ?
 
115
    master = branch.get_master_branch()
 
116
    if master:
 
117
        local_extra, remote_extra = find_unmerged(branch, master)
 
118
        if remote_extra:
 
119
            print 'Branch is out of date: missing %d revision%s.' % (
 
120
                len(remote_extra), plural(len(remote_extra)))
 
121
            print
 
122
 
 
123
    tree_last_id = working.last_revision()
 
124
    if len(history) and tree_last_id != history[-1]:
 
125
        tree_last_revno = branch.revision_id_to_revno(tree_last_id)
 
126
        missing_count = len(history) - tree_last_revno
 
127
        print 'Working tree is out of date: missing %d revision%s.' % (
 
128
            missing_count, plural(missing_count))
 
129
        print
 
130
 
 
131
    print 'In the working tree:'
 
132
    print '  %8s unchanged' % len(delta.unchanged)
 
133
    print '  %8d modified' % len(delta.modified)
 
134
    print '  %8d added' % len(delta.added)
 
135
    print '  %8d removed' % len(delta.removed)
 
136
    print '  %8d renamed' % len(delta.renamed)
 
137
 
 
138
    ignore_cnt = unknown_cnt = 0
 
139
    for path in working.extras():
 
140
        if working.is_ignored(path):
 
141
            ignore_cnt += 1
 
142
        else:
 
143
            unknown_cnt += 1
 
144
    print '  %8d unknown' % unknown_cnt
 
145
    print '  %8d ignored' % ignore_cnt
 
146
 
 
147
    dir_cnt = 0
 
148
    for file_id in work_inv:
 
149
        if work_inv.get_file_kind(file_id) == 'directory':
 
150
            dir_cnt += 1
 
151
    print '  %8d versioned %s' \
 
152
          % (dir_cnt,
 
153
             plural(dir_cnt, 'subdirectory', 'subdirectories'))
 
154
 
 
155
    print
 
156
    print 'Branch history:'
 
157
    revno = len(history)
 
158
    print '  %8d revision%s' % (revno, plural(revno))
 
159
    committers = {}
 
160
    for rev in history:
 
161
        committers[repository.get_revision(rev).committer] = True
 
162
    print '  %8d committer%s' % (len(committers), plural(len(committers)))
 
163
    if revno > 0:
 
164
        firstrev = repository.get_revision(history[0])
 
165
        age = int((time.time() - firstrev.timestamp) / 3600 / 24)
 
166
        print '  %8d day%s old' % (age, plural(age))
 
167
        print '   first revision: %s' % format_date(firstrev.timestamp,
 
168
                                                    firstrev.timezone)
 
169
 
 
170
        lastrev = repository.get_revision(history[-1])
 
171
        print '  latest revision: %s' % format_date(lastrev.timestamp,
 
172
                                                    lastrev.timezone)
 
173
 
 
174
#     print
 
175
#     print 'Text store:'
 
176
#     c, t = branch.text_store.total_size()
 
177
#     print '  %8d file texts' % c
 
178
#     print '  %8d KiB' % (t/1024)
 
179
 
 
180
    print
 
181
    print 'Revision store:'
 
182
    c, t = repository._revision_store.total_size(repository.get_transaction())
 
183
    print '  %8d revision%s' % (c, plural(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)