~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/info.py

  • Committer: Martin Pool
  • Date: 2005-05-10 03:55:34 UTC
  • Revision ID: mbp@sourcefrog.net-20050510035534-643062e821052ac5
- Add fortune-cookie external plugin demonstration

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
from sets import Set
19
20
import time
20
21
 
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
 
 
 
22
import bzrlib
 
23
from osutils import format_date
32
24
 
33
25
def show_info(b):
34
 
    import diff
35
 
    
36
26
    print 'branch format:', b.controlfile('branch-format', 'r').readline().rstrip('\n')
37
27
 
38
28
    def plural(n, base='', pl=None):
45
35
 
46
36
    count_version_dirs = 0
47
37
 
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
 
    
 
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
 
53
45
    print
54
46
    print 'in the working tree:'
55
 
    print '  %8s unchanged' % len(delta.unchanged)
56
 
    print '  %8d modified' % len(delta.modified)
57
 
    print '  %8d added' % len(delta.added)
58
 
    print '  %8d removed' % len(delta.removed)
59
 
    print '  %8d renamed' % len(delta.renamed)
60
 
 
61
 
    ignore_cnt = unknown_cnt = 0
62
 
    for path in working.extras():
63
 
        if working.is_ignored(path):
64
 
            ignore_cnt += 1
65
 
        else:
66
 
            unknown_cnt += 1
67
 
 
68
 
    print '  %8d unknown' % unknown_cnt
69
 
    print '  %8d ignored' % ignore_cnt
70
 
 
71
 
    dir_cnt = 0
72
 
    for file_id in work_inv:
73
 
        if work_inv.get_file_kind(file_id) == 'directory':
74
 
            dir_cnt += 1
75
 
    print '  %8d versioned %s' \
76
 
          % (dir_cnt,
77
 
             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'))
78
54
 
79
55
    print
80
56
    print 'branch history:'
81
57
    history = b.revision_history()
82
58
    revno = len(history)
83
59
    print '  %8d revision%s' % (revno, plural(revno))
84
 
    committers = {}
 
60
    committers = Set()
85
61
    for rev in history:
86
 
        committers[b.get_revision(rev).committer] = True
 
62
        committers.add(b.get_revision(rev).committer)
87
63
    print '  %8d committer%s' % (len(committers), plural(len(committers)))
88
64
    if revno > 0:
89
65
        firstrev = b.get_revision(history[0])
96
72
        print '  latest revision: %s' % format_date(lastrev.timestamp,
97
73
                                                    lastrev.timezone)
98
74
 
99
 
#     print
100
 
#     print 'text store:'
101
 
#     c, t = b.text_store.total_size()
102
 
#     print '  %8d file texts' % c
103
 
#     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)
104
80
 
105
81
    print
106
82
    print 'revision store:'
109
85
    print '  %8d kB' % (t/1024)
110
86
 
111
87
 
112
 
#     print
113
 
#     print 'inventory store:'
114
 
#     c, t = b.inventory_store.total_size()
115
 
#     print '  %8d inventories' % c
116
 
#     print '  %8d kB' % (t/1024)
 
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)
117
93