~bzr-pqm/bzr/bzr.dev

77 by mbp at sourcefrog
- split info command out into separate file
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
import time
20
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
21
from bzrlib.osutils import format_date
1534.4.35 by Robert Collins
Give branch its own basis tree and last_revision methods; deprecated branch.working_tree()
22
from bzrlib.workingtree import WorkingTree
77 by mbp at sourcefrog
- split info command out into separate file
23
462 by Martin Pool
- New form 'file_id in tree' to check if the file is present
24
25
def _countiter(it):
26
    # surely there's a builtin for this?
27
    i = 0
28
    for j in it:
29
        i += 1
30
    return i        
31
32
33
77 by mbp at sourcefrog
- split info command out into separate file
34
def show_info(b):
462 by Martin Pool
- New form 'file_id in tree' to check if the file is present
35
    import diff
36
    
1185.65.29 by Robert Collins
Implement final review suggestions.
37
    print 'branch format:', b.control_files.get_utf8(
38
        'branch-format').readline().rstrip('\n')
77 by mbp at sourcefrog
- split info command out into separate file
39
40
    def plural(n, base='', pl=None):
41
        if n == 1:
42
            return base
187 by mbp at sourcefrog
fix inverted sense introduced in previous pychecker fixup
43
        elif pl != None:
77 by mbp at sourcefrog
- split info command out into separate file
44
            return pl
45
        else:
46
            return 's'
47
48
    count_version_dirs = 0
49
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
50
    working = b.bzrdir.open_workingtree()
1534.4.35 by Robert Collins
Give branch its own basis tree and last_revision methods; deprecated branch.working_tree()
51
    basis = working.basis_tree()
462 by Martin Pool
- New form 'file_id in tree' to check if the file is present
52
    work_inv = working.inventory
470 by Martin Pool
- remove dead code for cmd_compare_trees
53
    delta = diff.compare_trees(basis, working, want_unchanged=True)
462 by Martin Pool
- New form 'file_id in tree' to check if the file is present
54
    
77 by mbp at sourcefrog
- split info command out into separate file
55
    print
56
    print 'in the working tree:'
463 by Martin Pool
- compare_trees() also reports unchanged files
57
    print '  %8s unchanged' % len(delta.unchanged)
462 by Martin Pool
- New form 'file_id in tree' to check if the file is present
58
    print '  %8d modified' % len(delta.modified)
59
    print '  %8d added' % len(delta.added)
60
    print '  %8d removed' % len(delta.removed)
61
    print '  %8d renamed' % len(delta.renamed)
62
63
    ignore_cnt = unknown_cnt = 0
64
    for path in working.extras():
65
        if working.is_ignored(path):
66
            ignore_cnt += 1
67
        else:
68
            unknown_cnt += 1
69
70
    print '  %8d unknown' % unknown_cnt
71
    print '  %8d ignored' % ignore_cnt
72
73
    dir_cnt = 0
74
    for file_id in work_inv:
75
        if work_inv.get_file_kind(file_id) == 'directory':
76
            dir_cnt += 1
77
    print '  %8d versioned %s' \
78
          % (dir_cnt,
79
             plural(dir_cnt, 'subdirectory', 'subdirectories'))
77 by mbp at sourcefrog
- split info command out into separate file
80
81
    print
82
    print 'branch history:'
83
    history = b.revision_history()
84
    revno = len(history)
111 by mbp at sourcefrog
Make fields wider in 'bzr info' output to accomodate big trees
85
    print '  %8d revision%s' % (revno, plural(revno))
540 by Martin Pool
- use builtin set object in python2.4
86
    committers = {}
77 by mbp at sourcefrog
- split info command out into separate file
87
    for rev in history:
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
88
        committers[b.repository.get_revision(rev).committer] = True
111 by mbp at sourcefrog
Make fields wider in 'bzr info' output to accomodate big trees
89
    print '  %8d committer%s' % (len(committers), plural(len(committers)))
77 by mbp at sourcefrog
- split info command out into separate file
90
    if revno > 0:
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
91
        firstrev = b.repository.get_revision(history[0])
77 by mbp at sourcefrog
- split info command out into separate file
92
        age = int((time.time() - firstrev.timestamp) / 3600 / 24)
111 by mbp at sourcefrog
Make fields wider in 'bzr info' output to accomodate big trees
93
        print '  %8d day%s old' % (age, plural(age))
78 by mbp at sourcefrog
align fields in info output
94
        print '   first revision: %s' % format_date(firstrev.timestamp,
95
                                                    firstrev.timezone)
77 by mbp at sourcefrog
- split info command out into separate file
96
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
97
        lastrev = b.repository.get_revision(history[-1])
77 by mbp at sourcefrog
- split info command out into separate file
98
        print '  latest revision: %s' % format_date(lastrev.timestamp,
99
                                                    lastrev.timezone)
80 by mbp at sourcefrog
show_info: Show number of entries in the branch stores
100
1286 by Martin Pool
- stub out display of store size in info command
101
#     print
102
#     print 'text store:'
103
#     c, t = b.text_store.total_size()
104
#     print '  %8d file texts' % c
105
#     print '  %8d kB' % (t/1024)
80 by mbp at sourcefrog
show_info: Show number of entries in the branch stores
106
107
    print
108
    print 'revision store:'
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
109
    c, t = b.repository.revision_store.total_size()
111 by mbp at sourcefrog
Make fields wider in 'bzr info' output to accomodate big trees
110
    print '  %8d revisions' % c
111
    print '  %8d kB' % (t/1024)
81 by mbp at sourcefrog
show space usage for various stores in the info command
112
80 by mbp at sourcefrog
show_info: Show number of entries in the branch stores
113
1286 by Martin Pool
- stub out display of store size in info command
114
#     print
115
#     print 'inventory store:'
116
#     c, t = b.inventory_store.total_size()
117
#     print '  %8d inventories' % c
118
#     print '  %8d kB' % (t/1024)
81 by mbp at sourcefrog
show space usage for various stores in the info command
119