/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
1534.5.1 by Robert Collins
Give info some reasonable output and tests.
38
@deprecated_function(zero_eight)
77 by mbp at sourcefrog
- split info command out into separate file
39
def show_info(b):
1534.5.1 by Robert Collins
Give info some reasonable output and tests.
40
    """Please see show_bzrdir_info."""
41
    return show_bzrdir_info(b.bzrdir)
42
43
def show_bzrdir_info(a_bzrdir):
44
    """Output to stdout the 'info' for a_bzrdir."""
45
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
46
    def plural(n, base='', pl=None):
47
        if n == 1:
48
            return base
49
        elif pl != None:
50
            return pl
51
        else:
52
            return 's'
53
1534.5.1 by Robert Collins
Give info some reasonable output and tests.
54
    working = a_bzrdir.open_workingtree()
55
    b = a_bzrdir.open_branch()
462 by Martin Pool
- New form 'file_id in tree' to check if the file is present
56
    
1534.5.1 by Robert Collins
Give info some reasonable output and tests.
57
    if working.bzrdir != b.bzrdir:
58
        print 'working tree format:', working._format
59
        print 'branch location:', b.bzrdir.root_transport.base
60
    try:
61
        b._format.get_format_string()
62
        format = b._format
63
    except NotImplementedError:
64
        format = b.bzrdir._format
65
    print 'branch format:', format
77 by mbp at sourcefrog
- split info command out into separate file
66
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
67
    if b.get_bound_location():
68
        print 'bound to branch:',  b.get_bound_location()
77 by mbp at sourcefrog
- split info command out into separate file
69
70
    count_version_dirs = 0
71
1534.4.35 by Robert Collins
Give branch its own basis tree and last_revision methods; deprecated branch.working_tree()
72
    basis = working.basis_tree()
462 by Martin Pool
- New form 'file_id in tree' to check if the file is present
73
    work_inv = working.inventory
470 by Martin Pool
- remove dead code for cmd_compare_trees
74
    delta = diff.compare_trees(basis, working, want_unchanged=True)
1534.5.1 by Robert Collins
Give info some reasonable output and tests.
75
    history = b.revision_history()
462 by Martin Pool
- New form 'file_id in tree' to check if the file is present
76
    
77 by mbp at sourcefrog
- split info command out into separate file
77
    print
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
78
    # Try with inaccessible branch ?
79
    master = b.get_master_branch()
80
    if master:
81
        local_extra, remote_extra = find_unmerged(b, b.get_master_branch())
82
        if remote_extra:
83
            print 'Branch is out of date: missing %d revision%s.' % (
84
                len(remote_extra), plural(len(remote_extra)))
85
1534.5.1 by Robert Collins
Give info some reasonable output and tests.
86
    if len(history) and working.last_revision() != history[-1]:
87
        try:
88
            missing_count = len(history) - history.index(working.last_revision())
89
        except ValueError:
90
            # consider it all out of date
91
            missing_count = len(history)
92
        print 'Working tree is out of date: missing %d revision%s.' % (
93
            missing_count, plural(missing_count))
77 by mbp at sourcefrog
- split info command out into separate file
94
    print 'in the working tree:'
463 by Martin Pool
- compare_trees() also reports unchanged files
95
    print '  %8s unchanged' % len(delta.unchanged)
462 by Martin Pool
- New form 'file_id in tree' to check if the file is present
96
    print '  %8d modified' % len(delta.modified)
97
    print '  %8d added' % len(delta.added)
98
    print '  %8d removed' % len(delta.removed)
99
    print '  %8d renamed' % len(delta.renamed)
100
101
    ignore_cnt = unknown_cnt = 0
102
    for path in working.extras():
103
        if working.is_ignored(path):
104
            ignore_cnt += 1
105
        else:
106
            unknown_cnt += 1
107
108
    print '  %8d unknown' % unknown_cnt
109
    print '  %8d ignored' % ignore_cnt
110
111
    dir_cnt = 0
112
    for file_id in work_inv:
113
        if work_inv.get_file_kind(file_id) == 'directory':
114
            dir_cnt += 1
115
    print '  %8d versioned %s' \
116
          % (dir_cnt,
117
             plural(dir_cnt, 'subdirectory', 'subdirectories'))
77 by mbp at sourcefrog
- split info command out into separate file
118
119
    print
120
    print 'branch history:'
121
    revno = len(history)
111 by mbp at sourcefrog
Make fields wider in 'bzr info' output to accomodate big trees
122
    print '  %8d revision%s' % (revno, plural(revno))
540 by Martin Pool
- use builtin set object in python2.4
123
    committers = {}
77 by mbp at sourcefrog
- split info command out into separate file
124
    for rev in history:
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
125
        committers[b.repository.get_revision(rev).committer] = True
111 by mbp at sourcefrog
Make fields wider in 'bzr info' output to accomodate big trees
126
    print '  %8d committer%s' % (len(committers), plural(len(committers)))
77 by mbp at sourcefrog
- split info command out into separate file
127
    if revno > 0:
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
128
        firstrev = b.repository.get_revision(history[0])
77 by mbp at sourcefrog
- split info command out into separate file
129
        age = int((time.time() - firstrev.timestamp) / 3600 / 24)
111 by mbp at sourcefrog
Make fields wider in 'bzr info' output to accomodate big trees
130
        print '  %8d day%s old' % (age, plural(age))
78 by mbp at sourcefrog
align fields in info output
131
        print '   first revision: %s' % format_date(firstrev.timestamp,
132
                                                    firstrev.timezone)
77 by mbp at sourcefrog
- split info command out into separate file
133
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
134
        lastrev = b.repository.get_revision(history[-1])
77 by mbp at sourcefrog
- split info command out into separate file
135
        print '  latest revision: %s' % format_date(lastrev.timestamp,
136
                                                    lastrev.timezone)
80 by mbp at sourcefrog
show_info: Show number of entries in the branch stores
137
1286 by Martin Pool
- stub out display of store size in info command
138
#     print
139
#     print 'text store:'
140
#     c, t = b.text_store.total_size()
141
#     print '  %8d file texts' % c
142
#     print '  %8d kB' % (t/1024)
80 by mbp at sourcefrog
show_info: Show number of entries in the branch stores
143
144
    print
145
    print 'revision store:'
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
146
    c, t = b.repository.revision_store.total_size()
1534.5.1 by Robert Collins
Give info some reasonable output and tests.
147
    print '  %8d revision%s' % (c, plural(c))
111 by mbp at sourcefrog
Make fields wider in 'bzr info' output to accomodate big trees
148
    print '  %8d kB' % (t/1024)
81 by mbp at sourcefrog
show space usage for various stores in the info command
149
80 by mbp at sourcefrog
show_info: Show number of entries in the branch stores
150
1286 by Martin Pool
- stub out display of store size in info command
151
#     print
152
#     print 'inventory store:'
153
#     c, t = b.inventory_store.total_size()
154
#     print '  %8d inventories' % c
155
#     print '  %8d kB' % (t/1024)
81 by mbp at sourcefrog
show space usage for various stores in the info command
156