~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/info.py

  • Committer: Martin Pool
  • Date: 2005-06-30 08:40:59 UTC
  • mto: This revision was merged to the branch mainline in revision 852.
  • Revision ID: mbp@sourcefrog.net-20050630084059-d6eb6cb46972365b
Rename Weave.get_included to inclusions and getiter to get_iter

Refactor annotate() code 

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
 
from sets import Set
20
 
import time
21
 
 
22
 
import bzrlib
23
 
from osutils import format_date
24
 
 
25
 
def show_info(b):
26
 
    # TODO: Maybe show space used by working tree, versioned files,
27
 
    # unknown files, text store.
28
 
    
29
 
    print 'branch format:', b.controlfile('branch-format', 'r').readline().rstrip('\n')
30
 
 
31
 
    def plural(n, base='', pl=None):
32
 
        if n == 1:
33
 
            return base
34
 
        elif pl != None:
35
 
            return pl
36
 
        else:
37
 
            return 's'
38
 
 
39
 
    count_version_dirs = 0
40
 
 
41
 
    count_status = {'A': 0, 'D': 0, 'M': 0, 'R': 0, '?': 0, 'I': 0, '.': 0}
42
 
    for st_tup in bzrlib.diff_trees(b.basis_tree(), b.working_tree()):
43
 
        fs = st_tup[0]
44
 
        count_status[fs] += 1
45
 
        if fs not in ['I', '?'] and st_tup[4] == 'directory':
46
 
            count_version_dirs += 1
47
 
 
48
 
    print
49
 
    print 'in the working tree:'
50
 
    for name, fs in (('unchanged', '.'),
51
 
                     ('modified', 'M'), ('added', 'A'), ('removed', 'D'),
52
 
                     ('renamed', 'R'), ('unknown', '?'), ('ignored', 'I'),
53
 
                     ):
54
 
        print '  %8d %s' % (count_status[fs], name)
55
 
    print '  %8d versioned subdirector%s' % (count_version_dirs,
56
 
                                             plural(count_version_dirs, 'y', 'ies'))
57
 
 
58
 
    print
59
 
    print 'branch history:'
60
 
    history = b.revision_history()
61
 
    revno = len(history)
62
 
    print '  %8d revision%s' % (revno, plural(revno))
63
 
    committers = Set()
64
 
    for rev in history:
65
 
        committers.add(b.get_revision(rev).committer)
66
 
    print '  %8d committer%s' % (len(committers), plural(len(committers)))
67
 
    if revno > 0:
68
 
        firstrev = b.get_revision(history[0])
69
 
        age = int((time.time() - firstrev.timestamp) / 3600 / 24)
70
 
        print '  %8d day%s old' % (age, plural(age))
71
 
        print '   first revision: %s' % format_date(firstrev.timestamp,
72
 
                                                    firstrev.timezone)
73
 
 
74
 
        lastrev = b.get_revision(history[-1])
75
 
        print '  latest revision: %s' % format_date(lastrev.timestamp,
76
 
                                                    lastrev.timezone)
77
 
 
78
 
    print
79
 
    print 'text store:'
80
 
    c, t = b.text_store.total_size()
81
 
    print '  %8d file texts' % c
82
 
    print '  %8d kB' % (t/1024)
83
 
 
84
 
    print
85
 
    print 'revision store:'
86
 
    c, t = b.revision_store.total_size()
87
 
    print '  %8d revisions' % c
88
 
    print '  %8d kB' % (t/1024)
89
 
 
90
 
 
91
 
    print
92
 
    print 'inventory store:'
93
 
    c, t = b.inventory_store.total_size()
94
 
    print '  %8d inventories' % c
95
 
    print '  %8d kB' % (t/1024)
96