~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/info.py

  • Committer: Martin Pool
  • Date: 2005-05-09 03:03:55 UTC
  • Revision ID: mbp@sourcefrog.net-20050509030355-ad6ab558d1362959
- Don't give an error if the trace file can't be opened

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
 
 
 
19
from sets import Set
21
20
import time
22
21
 
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)
 
22
import bzrlib
 
23
from osutils import format_date
 
24
 
48
25
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
 
    b = working.branch
68
 
    
69
 
    if working.bzrdir != b.bzrdir:
70
 
        print 'working tree format:', working._format
71
 
        print 'branch location:', b.bzrdir.root_transport.base
72
 
    try:
73
 
        b._format.get_format_string()
74
 
        format = b._format
75
 
    except NotImplementedError:
76
 
        format = b.bzrdir._format
77
 
    print 'branch format:', format
78
 
 
79
 
    if b.get_bound_location():
80
 
        print 'bound to branch:',  b.get_bound_location()
 
26
    print 'branch format:', b.controlfile('branch-format', 'r').readline().rstrip('\n')
 
27
 
 
28
    def plural(n, base='', pl=None):
 
29
        if n == 1:
 
30
            return base
 
31
        elif pl != None:
 
32
            return pl
 
33
        else:
 
34
            return 's'
81
35
 
82
36
    count_version_dirs = 0
83
37
 
84
 
    basis = working.basis_tree()
85
 
    work_inv = working.inventory
86
 
    delta = diff.compare_trees(basis, working, want_unchanged=True)
87
 
    history = b.revision_history()
88
 
    
 
38
    count_status = {'A': 0, 'D': 0, 'M': 0, 'R': 0, '?': 0, 'I': 0, '.': 0}
 
39
    for st_tup in bzrlib.diff_trees(b.basis_tree(), b.working_tree()):
 
40
        fs = st_tup[0]
 
41
        count_status[fs] += 1
 
42
        if fs not in ['I', '?'] and st_tup[4] == 'directory':
 
43
            count_version_dirs += 1
 
44
 
89
45
    print
90
 
    # Try with inaccessible branch ?
91
 
    master = b.get_master_branch()
92
 
    if master:
93
 
        local_extra, remote_extra = find_unmerged(b, b.get_master_branch())
94
 
        if remote_extra:
95
 
            print 'Branch is out of date: missing %d revision%s.' % (
96
 
                len(remote_extra), plural(len(remote_extra)))
97
 
 
98
 
    if len(history) and working.last_revision() != history[-1]:
99
 
        try:
100
 
            missing_count = len(history) - history.index(working.last_revision())
101
 
        except ValueError:
102
 
            # consider it all out of date
103
 
            missing_count = len(history)
104
 
        print 'Working tree is out of date: missing %d revision%s.' % (
105
 
            missing_count, plural(missing_count))
106
46
    print 'in the working tree:'
107
 
    print '  %8s unchanged' % len(delta.unchanged)
108
 
    print '  %8d modified' % len(delta.modified)
109
 
    print '  %8d added' % len(delta.added)
110
 
    print '  %8d removed' % len(delta.removed)
111
 
    print '  %8d renamed' % len(delta.renamed)
112
 
 
113
 
    ignore_cnt = unknown_cnt = 0
114
 
    for path in working.extras():
115
 
        if working.is_ignored(path):
116
 
            ignore_cnt += 1
117
 
        else:
118
 
            unknown_cnt += 1
119
 
 
120
 
    print '  %8d unknown' % unknown_cnt
121
 
    print '  %8d ignored' % ignore_cnt
122
 
 
123
 
    dir_cnt = 0
124
 
    for file_id in work_inv:
125
 
        if work_inv.get_file_kind(file_id) == 'directory':
126
 
            dir_cnt += 1
127
 
    print '  %8d versioned %s' \
128
 
          % (dir_cnt,
129
 
             plural(dir_cnt, 'subdirectory', 'subdirectories'))
 
47
    for name, fs in (('unchanged', '.'),
 
48
                     ('modified', 'M'), ('added', 'A'), ('removed', 'D'),
 
49
                     ('renamed', 'R'), ('unknown', '?'), ('ignored', 'I'),
 
50
                     ):
 
51
        print '  %8d %s' % (count_status[fs], name)
 
52
    print '  %8d versioned subdirector%s' % (count_version_dirs,
 
53
                                             plural(count_version_dirs, 'y', 'ies'))
130
54
 
131
55
    print
132
56
    print 'branch history:'
 
57
    history = b.revision_history()
133
58
    revno = len(history)
134
59
    print '  %8d revision%s' % (revno, plural(revno))
135
 
    committers = {}
 
60
    committers = Set()
136
61
    for rev in history:
137
 
        committers[b.repository.get_revision(rev).committer] = True
 
62
        committers.add(b.get_revision(rev).committer)
138
63
    print '  %8d committer%s' % (len(committers), plural(len(committers)))
139
64
    if revno > 0:
140
 
        firstrev = b.repository.get_revision(history[0])
 
65
        firstrev = b.get_revision(history[0])
141
66
        age = int((time.time() - firstrev.timestamp) / 3600 / 24)
142
67
        print '  %8d day%s old' % (age, plural(age))
143
68
        print '   first revision: %s' % format_date(firstrev.timestamp,
144
69
                                                    firstrev.timezone)
145
70
 
146
 
        lastrev = b.repository.get_revision(history[-1])
 
71
        lastrev = b.get_revision(history[-1])
147
72
        print '  latest revision: %s' % format_date(lastrev.timestamp,
148
73
                                                    lastrev.timezone)
149
74
 
150
 
#     print
151
 
#     print 'text store:'
152
 
#     c, t = b.text_store.total_size()
153
 
#     print '  %8d file texts' % c
154
 
#     print '  %8d kB' % (t/1024)
 
75
    print
 
76
    print 'text store:'
 
77
    c, t = b.text_store.total_size()
 
78
    print '  %8d file texts' % c
 
79
    print '  %8d kB' % (t/1024)
155
80
 
156
81
    print
157
82
    print 'revision store:'
158
 
    c, t = b.repository._revision_store.total_size(b.repository.get_transaction())
159
 
    print '  %8d revision%s' % (c, plural(c))
160
 
    print '  %8d kB' % (t/1024)
161
 
 
162
 
 
163
 
#     print
164
 
#     print 'inventory store:'
165
 
#     c, t = b.inventory_store.total_size()
166
 
#     print '  %8d inventories' % c
167
 
#     print '  %8d kB' % (t/1024)
168
 
 
169
 
    loc = b.get_parent()
170
 
    if loc is not None:
171
 
        print
172
 
        print 'parent location:'
173
 
        print '  %s' % loc
 
83
    c, t = b.revision_store.total_size()
 
84
    print '  %8d revisions' % c
 
85
    print '  %8d kB' % (t/1024)
 
86
 
 
87
 
 
88
    print
 
89
    print 'inventory store:'
 
90
    c, t = b.inventory_store.total_size()
 
91
    print '  %8d inventories' % c
 
92
    print '  %8d kB' % (t/1024)
174
93