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