~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
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
25
from bzrlib.missing import find_unmerged
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
26
from bzrlib.osutils import format_date
1534.5.1 by Robert Collins
Give info some reasonable output and tests.
27
from bzrlib.symbol_versioning import *
77 by mbp at sourcefrog
- split info command out into separate file
28
462 by Martin Pool
- New form 'file_id in tree' to check if the file is present
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
1563.2.28 by Robert Collins
Add total_size to the revision_store api.
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
1534.5.1 by Robert Collins
Give info some reasonable output and tests.
47
@deprecated_function(zero_eight)
77 by mbp at sourcefrog
- split info command out into separate file
48
def show_info(b):
1534.5.1 by Robert Collins
Give info some reasonable output and tests.
49
    """Please see show_bzrdir_info."""
50
    return show_bzrdir_info(b.bzrdir)
51
1563.2.28 by Robert Collins
Add total_size to the revision_store api.
52
1534.5.1 by Robert Collins
Give info some reasonable output and tests.
53
def show_bzrdir_info(a_bzrdir):
54
    """Output to stdout the 'info' for a_bzrdir."""
55
56
    working = a_bzrdir.open_workingtree()
1563.2.28 by Robert Collins
Add total_size to the revision_store api.
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
462 by Martin Pool
- New form 'file_id in tree' to check if the file is present
68
    
1534.5.1 by Robert Collins
Give info some reasonable output and tests.
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
77 by mbp at sourcefrog
- split info command out into separate file
78
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
79
    if b.get_bound_location():
80
        print 'bound to branch:',  b.get_bound_location()
77 by mbp at sourcefrog
- split info command out into separate file
81
82
    count_version_dirs = 0
83
1534.4.35 by Robert Collins
Give branch its own basis tree and last_revision methods; deprecated branch.working_tree()
84
    basis = working.basis_tree()
462 by Martin Pool
- New form 'file_id in tree' to check if the file is present
85
    work_inv = working.inventory
470 by Martin Pool
- remove dead code for cmd_compare_trees
86
    delta = diff.compare_trees(basis, working, want_unchanged=True)
1534.5.1 by Robert Collins
Give info some reasonable output and tests.
87
    history = b.revision_history()
462 by Martin Pool
- New form 'file_id in tree' to check if the file is present
88
    
77 by mbp at sourcefrog
- split info command out into separate file
89
    print
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
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
1534.5.1 by Robert Collins
Give info some reasonable output and tests.
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))
77 by mbp at sourcefrog
- split info command out into separate file
106
    print 'in the working tree:'
463 by Martin Pool
- compare_trees() also reports unchanged files
107
    print '  %8s unchanged' % len(delta.unchanged)
462 by Martin Pool
- New form 'file_id in tree' to check if the file is present
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'))
77 by mbp at sourcefrog
- split info command out into separate file
130
131
    print
132
    print 'branch history:'
133
    revno = len(history)
111 by mbp at sourcefrog
Make fields wider in 'bzr info' output to accomodate big trees
134
    print '  %8d revision%s' % (revno, plural(revno))
540 by Martin Pool
- use builtin set object in python2.4
135
    committers = {}
77 by mbp at sourcefrog
- split info command out into separate file
136
    for rev in history:
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
137
        committers[b.repository.get_revision(rev).committer] = True
111 by mbp at sourcefrog
Make fields wider in 'bzr info' output to accomodate big trees
138
    print '  %8d committer%s' % (len(committers), plural(len(committers)))
77 by mbp at sourcefrog
- split info command out into separate file
139
    if revno > 0:
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
140
        firstrev = b.repository.get_revision(history[0])
77 by mbp at sourcefrog
- split info command out into separate file
141
        age = int((time.time() - firstrev.timestamp) / 3600 / 24)
111 by mbp at sourcefrog
Make fields wider in 'bzr info' output to accomodate big trees
142
        print '  %8d day%s old' % (age, plural(age))
78 by mbp at sourcefrog
align fields in info output
143
        print '   first revision: %s' % format_date(firstrev.timestamp,
144
                                                    firstrev.timezone)
77 by mbp at sourcefrog
- split info command out into separate file
145
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
146
        lastrev = b.repository.get_revision(history[-1])
77 by mbp at sourcefrog
- split info command out into separate file
147
        print '  latest revision: %s' % format_date(lastrev.timestamp,
148
                                                    lastrev.timezone)
80 by mbp at sourcefrog
show_info: Show number of entries in the branch stores
149
1286 by Martin Pool
- stub out display of store size in info command
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)
80 by mbp at sourcefrog
show_info: Show number of entries in the branch stores
155
156
    print
157
    print 'revision store:'
1563.2.28 by Robert Collins
Add total_size to the revision_store api.
158
    c, t = b.repository._revision_store.total_size(b.repository.get_transaction())
1534.5.1 by Robert Collins
Give info some reasonable output and tests.
159
    print '  %8d revision%s' % (c, plural(c))
111 by mbp at sourcefrog
Make fields wider in 'bzr info' output to accomodate big trees
160
    print '  %8d kB' % (t/1024)
81 by mbp at sourcefrog
show space usage for various stores in the info command
161
80 by mbp at sourcefrog
show_info: Show number of entries in the branch stores
162
1286 by Martin Pool
- stub out display of store size in info command
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)
81 by mbp at sourcefrog
show space usage for various stores in the info command
168
1611.1.1 by Olaf Conradi
Add parent location to info command (Closes feature bug #33364).
169
    loc = b.get_parent()
170
    if loc is not None:
171
        print
172
        print 'parent location:'
173
        print '  %s' % loc
174