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 |
|
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
25 |
from bzrlib.errors import (NoWorkingTree, NotBranchError, |
26 |
NoRepositoryPresent, NotLocalUrl) |
|
1587.1.14
by Robert Collins
Make bound branch creation happen via 'checkout' |
27 |
from bzrlib.missing import find_unmerged |
1694.2.6
by Martin Pool
[merge] bzr.dev |
28 |
import bzrlib.osutils as osutils |
1534.5.1
by Robert Collins
Give info some reasonable output and tests. |
29 |
from bzrlib.symbol_versioning import * |
77
by mbp at sourcefrog
- split info command out into separate file |
30 |
|
462
by Martin Pool
- New form 'file_id in tree' to check if the file is present |
31 |
|
1563.2.28
by Robert Collins
Add total_size to the revision_store api. |
32 |
def plural(n, base='', pl=None): |
33 |
if n == 1: |
|
34 |
return base |
|
35 |
elif pl != None: |
|
36 |
return pl |
|
37 |
else: |
|
38 |
return 's' |
|
39 |
||
40 |
||
1694.2.6
by Martin Pool
[merge] bzr.dev |
41 |
def _repo_relpath(repo_path, path): |
42 |
"""Return path with common prefix of repository path removed.
|
|
43 |
||
44 |
If path is not part of the repository, the original path is returned.
|
|
45 |
If path is equal to the repository, the current directory marker '.' is
|
|
46 |
returned.
|
|
47 |
"""
|
|
48 |
path = osutils.normalizepath(path) |
|
49 |
repo_path = osutils.normalizepath(repo_path) |
|
50 |
if path == repo_path: |
|
51 |
return '.' |
|
52 |
if osutils.is_inside(repo_path, path): |
|
53 |
return osutils.relpath(repo_path, path) |
|
54 |
return path |
|
55 |
||
56 |
||
57 |
def _show_location_info(repository, branch=None, working=None): |
|
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
58 |
"""Show known locations for working, branch and repository."""
|
1694.2.6
by Martin Pool
[merge] bzr.dev |
59 |
repository_path = repository.bzrdir.root_transport.base |
1624.3.8
by Olaf Conradi
Adjust formatting. Start sections with a capital letter. |
60 |
print 'Location:' |
1694.2.6
by Martin Pool
[merge] bzr.dev |
61 |
if working and branch: |
62 |
working_path = working.bzrdir.root_transport.base |
|
63 |
branch_path = branch.bzrdir.root_transport.base |
|
64 |
if working_path != branch_path: |
|
65 |
# lightweight checkout
|
|
66 |
print ' light checkout root: %s' % working_path |
|
67 |
if repository.is_shared(): |
|
68 |
# lightweight checkout of branch in shared repository
|
|
69 |
print ' shared repository: %s' % repository_path |
|
70 |
print ' repository branch: %s' % ( |
|
71 |
_repo_relpath(repository_path, branch_path)) |
|
72 |
else: |
|
73 |
# lightweight checkout of standalone branch
|
|
74 |
print ' checkout of branch: %s' % branch_path |
|
75 |
elif repository.is_shared(): |
|
76 |
# branch with tree inside shared repository
|
|
77 |
print ' shared repository: %s' % repository_path |
|
78 |
print ' repository checkout: %s' % ( |
|
79 |
_repo_relpath(repository_path, branch_path)) |
|
80 |
elif branch.get_bound_location(): |
|
81 |
# normal checkout
|
|
82 |
print ' checkout root: %s' % working_path |
|
83 |
print ' checkout of branch: %s' % branch.get_bound_location() |
|
84 |
else: |
|
85 |
# standalone
|
|
86 |
print ' branch root: %s' % working_path |
|
1624.3.33
by Olaf Conradi
Simplified construct detection in location overview a lot. |
87 |
elif branch: |
1694.2.6
by Martin Pool
[merge] bzr.dev |
88 |
branch_path = branch.bzrdir.root_transport.base |
1624.3.48
by Olaf Conradi
Add info on standalone branches without a working tree. |
89 |
if repository.is_shared(): |
90 |
# branch is part of shared repository
|
|
91 |
print ' shared repository: %s' % repository_path |
|
92 |
print ' repository branch: %s' % ( |
|
93 |
_repo_relpath(repository_path, branch_path)) |
|
94 |
else: |
|
95 |
# standalone branch
|
|
96 |
print ' branch root: %s' % branch_path |
|
1694.2.6
by Martin Pool
[merge] bzr.dev |
97 |
else: |
98 |
# shared repository
|
|
99 |
assert repository.is_shared() |
|
100 |
print ' shared repository: %s' % repository_path |
|
101 |
||
102 |
||
103 |
def _show_related_info(branch): |
|
104 |
"""Show parent and push location of branch."""
|
|
105 |
if branch.get_parent() or branch.get_push_location(): |
|
106 |
print
|
|
107 |
print 'Related branches:' |
|
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
108 |
if branch.get_parent(): |
1694.2.6
by Martin Pool
[merge] bzr.dev |
109 |
if branch.get_push_location(): |
110 |
print ' parent branch: %s' % branch.get_parent() |
|
111 |
else: |
|
112 |
print ' parent branch: %s' % branch.get_parent() |
|
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
113 |
if branch.get_push_location(): |
1694.2.6
by Martin Pool
[merge] bzr.dev |
114 |
print ' publish to branch: %s' % branch.get_push_location() |
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
115 |
|
116 |
||
117 |
def _show_format_info(control=None, repository=None, branch=None, working=None): |
|
118 |
"""Show known formats for control, working, branch and repository."""
|
|
1624.3.4
by Olaf Conradi
Simplify construct detection. Make terms in user interface consistent. |
119 |
print
|
1624.3.8
by Olaf Conradi
Adjust formatting. Start sections with a capital letter. |
120 |
print 'Format:' |
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
121 |
if control: |
122 |
print ' control: %s' % control._format.get_format_description() |
|
123 |
if working: |
|
124 |
print ' working tree: %s' % working._format.get_format_description() |
|
125 |
if branch: |
|
126 |
print ' branch: %s' % branch._format.get_format_description() |
|
127 |
if repository: |
|
128 |
print ' repository: %s' % repository._format.get_format_description() |
|
129 |
||
130 |
||
1694.2.6
by Martin Pool
[merge] bzr.dev |
131 |
def _show_locking_info(repository, branch=None, working=None): |
132 |
"""Show locking status of working, branch and repository."""
|
|
133 |
if (repository.get_physical_lock_status() or |
|
134 |
(branch and branch.get_physical_lock_status()) or |
|
135 |
(working and working.get_physical_lock_status())): |
|
136 |
print
|
|
137 |
print 'Lock status:' |
|
138 |
if working: |
|
139 |
if working.get_physical_lock_status(): |
|
140 |
status = 'locked' |
|
141 |
else: |
|
142 |
status = 'unlocked' |
|
143 |
print ' working tree: %s' % status |
|
144 |
if branch: |
|
145 |
if branch.get_physical_lock_status(): |
|
146 |
status = 'locked' |
|
147 |
else: |
|
148 |
status = 'unlocked' |
|
149 |
print ' branch: %s' % status |
|
150 |
if repository: |
|
151 |
if repository.get_physical_lock_status(): |
|
152 |
status = 'locked' |
|
153 |
else: |
|
154 |
status = 'unlocked' |
|
155 |
print ' repository: %s' % status |
|
156 |
||
157 |
||
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
158 |
def _show_missing_revisions_branch(branch): |
159 |
"""Show missing master revisions in branch."""
|
|
1587.1.14
by Robert Collins
Make bound branch creation happen via 'checkout' |
160 |
# Try with inaccessible branch ?
|
1624.3.2
by Olaf Conradi
Implemented table of constructs from BzrInfo specification. |
161 |
master = branch.get_master_branch() |
1587.1.14
by Robert Collins
Make bound branch creation happen via 'checkout' |
162 |
if master: |
1624.3.2
by Olaf Conradi
Implemented table of constructs from BzrInfo specification. |
163 |
local_extra, remote_extra = find_unmerged(branch, master) |
1587.1.14
by Robert Collins
Make bound branch creation happen via 'checkout' |
164 |
if remote_extra: |
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
165 |
print
|
1587.1.14
by Robert Collins
Make bound branch creation happen via 'checkout' |
166 |
print 'Branch is out of date: missing %d revision%s.' % ( |
167 |
len(remote_extra), plural(len(remote_extra))) |
|
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
168 |
|
169 |
||
170 |
def _show_missing_revisions_working(working): |
|
171 |
"""Show missing revisions in working tree."""
|
|
172 |
branch = working.branch |
|
173 |
basis = working.basis_tree() |
|
174 |
work_inv = working.inventory |
|
175 |
delta = diff.compare_trees(basis, working, want_unchanged=True) |
|
176 |
history = branch.revision_history() |
|
1624.3.11
by Olaf Conradi
Test cases exposed a bug in missing revisions count of working tree. It |
177 |
tree_last_id = working.last_revision() |
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
178 |
|
1624.3.11
by Olaf Conradi
Test cases exposed a bug in missing revisions count of working tree. It |
179 |
if len(history) and tree_last_id != history[-1]: |
180 |
tree_last_revno = branch.revision_id_to_revno(tree_last_id) |
|
181 |
missing_count = len(history) - tree_last_revno |
|
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
182 |
print
|
1534.5.1
by Robert Collins
Give info some reasonable output and tests. |
183 |
print 'Working tree is out of date: missing %d revision%s.' % ( |
184 |
missing_count, plural(missing_count)) |
|
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
185 |
|
186 |
||
187 |
def _show_working_stats(working): |
|
188 |
"""Show statistics about a working tree."""
|
|
189 |
basis = working.basis_tree() |
|
190 |
work_inv = working.inventory |
|
191 |
delta = diff.compare_trees(basis, working, want_unchanged=True) |
|
192 |
||
193 |
print
|
|
1624.3.8
by Olaf Conradi
Adjust formatting. Start sections with a capital letter. |
194 |
print 'In the working tree:' |
463
by Martin Pool
- compare_trees() also reports unchanged files |
195 |
print ' %8s unchanged' % len(delta.unchanged) |
462
by Martin Pool
- New form 'file_id in tree' to check if the file is present |
196 |
print ' %8d modified' % len(delta.modified) |
197 |
print ' %8d added' % len(delta.added) |
|
198 |
print ' %8d removed' % len(delta.removed) |
|
199 |
print ' %8d renamed' % len(delta.renamed) |
|
200 |
||
201 |
ignore_cnt = unknown_cnt = 0 |
|
202 |
for path in working.extras(): |
|
203 |
if working.is_ignored(path): |
|
204 |
ignore_cnt += 1 |
|
205 |
else: |
|
206 |
unknown_cnt += 1 |
|
207 |
print ' %8d unknown' % unknown_cnt |
|
208 |
print ' %8d ignored' % ignore_cnt |
|
209 |
||
210 |
dir_cnt = 0 |
|
211 |
for file_id in work_inv: |
|
212 |
if work_inv.get_file_kind(file_id) == 'directory': |
|
213 |
dir_cnt += 1 |
|
214 |
print ' %8d versioned %s' \ |
|
215 |
% (dir_cnt, |
|
216 |
plural(dir_cnt, 'subdirectory', 'subdirectories')) |
|
77
by mbp at sourcefrog
- split info command out into separate file |
217 |
|
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
218 |
|
219 |
def _show_branch_stats(branch, verbose): |
|
220 |
"""Show statistics about a branch."""
|
|
221 |
repository = branch.repository |
|
222 |
history = branch.revision_history() |
|
223 |
||
77
by mbp at sourcefrog
- split info command out into separate file |
224 |
print
|
1624.3.8
by Olaf Conradi
Adjust formatting. Start sections with a capital letter. |
225 |
print 'Branch history:' |
77
by mbp at sourcefrog
- split info command out into separate file |
226 |
revno = len(history) |
111
by mbp at sourcefrog
Make fields wider in 'bzr info' output to accomodate big trees |
227 |
print ' %8d revision%s' % (revno, plural(revno)) |
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
228 |
if verbose: |
229 |
committers = {} |
|
230 |
for rev in history: |
|
231 |
committers[repository.get_revision(rev).committer] = True |
|
232 |
print ' %8d committer%s' % (len(committers), plural(len(committers))) |
|
77
by mbp at sourcefrog
- split info command out into separate file |
233 |
if revno > 0: |
1624.3.17
by Olaf Conradi
Remove indirection in branch.repository as it is available as repository |
234 |
firstrev = repository.get_revision(history[0]) |
77
by mbp at sourcefrog
- split info command out into separate file |
235 |
age = int((time.time() - firstrev.timestamp) / 3600 / 24) |
111
by mbp at sourcefrog
Make fields wider in 'bzr info' output to accomodate big trees |
236 |
print ' %8d day%s old' % (age, plural(age)) |
1694.2.6
by Martin Pool
[merge] bzr.dev |
237 |
print ' first revision: %s' % osutils.format_date(firstrev.timestamp, |
238 |
firstrev.timezone) |
|
77
by mbp at sourcefrog
- split info command out into separate file |
239 |
|
1624.3.17
by Olaf Conradi
Remove indirection in branch.repository as it is available as repository |
240 |
lastrev = repository.get_revision(history[-1]) |
1694.2.6
by Martin Pool
[merge] bzr.dev |
241 |
print ' latest revision: %s' % osutils.format_date(lastrev.timestamp, |
242 |
lastrev.timezone) |
|
80
by mbp at sourcefrog
show_info: Show number of entries in the branch stores |
243 |
|
1286
by Martin Pool
- stub out display of store size in info command |
244 |
# print
|
1624.3.8
by Olaf Conradi
Adjust formatting. Start sections with a capital letter. |
245 |
# print 'Text store:'
|
1624.3.2
by Olaf Conradi
Implemented table of constructs from BzrInfo specification. |
246 |
# c, t = branch.text_store.total_size()
|
1286
by Martin Pool
- stub out display of store size in info command |
247 |
# print ' %8d file texts' % c
|
1624.3.14
by Olaf Conradi
Move to using kibi for binary prefix as per standard IEEE 1541. |
248 |
# print ' %8d KiB' % (t/1024)
|
80
by mbp at sourcefrog
show_info: Show number of entries in the branch stores |
249 |
|
1286
by Martin Pool
- stub out display of store size in info command |
250 |
# print
|
1624.3.8
by Olaf Conradi
Adjust formatting. Start sections with a capital letter. |
251 |
# print 'Inventory store:'
|
1624.3.2
by Olaf Conradi
Implemented table of constructs from BzrInfo specification. |
252 |
# c, t = branch.inventory_store.total_size()
|
1286
by Martin Pool
- stub out display of store size in info command |
253 |
# print ' %8d inventories' % c
|
1624.3.14
by Olaf Conradi
Move to using kibi for binary prefix as per standard IEEE 1541. |
254 |
# print ' %8d KiB' % (t/1024)
|
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
255 |
|
256 |
||
257 |
def _show_repository_info(repository): |
|
258 |
"""Show settings of a repository."""
|
|
259 |
if repository.make_working_trees(): |
|
260 |
print
|
|
261 |
print 'Create working tree for new branches inside the repository.' |
|
262 |
||
263 |
||
264 |
def _show_repository_stats(repository): |
|
265 |
"""Show statistics about a repository."""
|
|
266 |
if repository.bzrdir.root_transport.listable(): |
|
267 |
print
|
|
268 |
print 'Revision store:' |
|
269 |
c, t = repository._revision_store.total_size(repository.get_transaction()) |
|
270 |
print ' %8d revision%s' % (c, plural(c)) |
|
271 |
print ' %8d KiB' % (t/1024) |
|
272 |
||
273 |
||
274 |
@deprecated_function(zero_eight) |
|
275 |
def show_info(b): |
|
276 |
"""Please see show_bzrdir_info."""
|
|
277 |
return show_bzrdir_info(b.bzrdir) |
|
278 |
||
279 |
||
280 |
def show_bzrdir_info(a_bzrdir, verbose=False): |
|
281 |
"""Output to stdout the 'info' for a_bzrdir."""
|
|
282 |
try: |
|
283 |
working = a_bzrdir.open_workingtree() |
|
1624.3.35
by Olaf Conradi
Implemented locking status for formats using LockDir. |
284 |
working.lock_read() |
285 |
try: |
|
286 |
show_tree_info(working, verbose) |
|
287 |
finally: |
|
288 |
working.unlock() |
|
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
289 |
return
|
290 |
except (NoWorkingTree, NotLocalUrl): |
|
291 |
pass
|
|
292 |
||
293 |
try: |
|
294 |
branch = a_bzrdir.open_branch() |
|
1624.3.35
by Olaf Conradi
Implemented locking status for formats using LockDir. |
295 |
branch.lock_read() |
296 |
try: |
|
297 |
show_branch_info(branch, verbose) |
|
298 |
finally: |
|
299 |
branch.unlock() |
|
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
300 |
return
|
301 |
except NotBranchError: |
|
302 |
pass
|
|
303 |
||
304 |
try: |
|
305 |
repository = a_bzrdir.open_repository() |
|
1624.3.35
by Olaf Conradi
Implemented locking status for formats using LockDir. |
306 |
repository.lock_read() |
307 |
try: |
|
308 |
show_repository_info(repository, verbose) |
|
309 |
finally: |
|
310 |
repository.unlock() |
|
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
311 |
return
|
312 |
except NoRepositoryPresent: |
|
313 |
pass
|
|
314 |
||
1694.2.6
by Martin Pool
[merge] bzr.dev |
315 |
# Return silently, cmd_info already returned NotBranchError if no bzrdir
|
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
316 |
# could be opened.
|
317 |
||
318 |
||
319 |
def show_tree_info(working, verbose): |
|
320 |
"""Output to stdout the 'info' for working."""
|
|
321 |
branch = working.branch |
|
322 |
repository = branch.repository |
|
323 |
control = working.bzrdir |
|
324 |
||
325 |
_show_location_info(repository, branch, working) |
|
1694.2.6
by Martin Pool
[merge] bzr.dev |
326 |
_show_related_info(branch) |
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
327 |
_show_format_info(control, repository, branch, working) |
1694.2.6
by Martin Pool
[merge] bzr.dev |
328 |
_show_locking_info(repository, branch, working) |
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
329 |
_show_missing_revisions_branch(branch) |
330 |
_show_missing_revisions_working(working) |
|
331 |
_show_working_stats(working) |
|
332 |
_show_branch_stats(branch, verbose) |
|
333 |
_show_repository_stats(repository) |
|
334 |
||
335 |
||
336 |
def show_branch_info(branch, verbose): |
|
337 |
"""Output to stdout the 'info' for branch."""
|
|
338 |
repository = branch.repository |
|
339 |
control = branch.bzrdir |
|
340 |
||
341 |
_show_location_info(repository, branch) |
|
1694.2.6
by Martin Pool
[merge] bzr.dev |
342 |
_show_related_info(branch) |
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
343 |
_show_format_info(control, repository, branch) |
1694.2.6
by Martin Pool
[merge] bzr.dev |
344 |
_show_locking_info(repository, branch) |
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
345 |
_show_missing_revisions_branch(branch) |
346 |
_show_branch_stats(branch, verbose) |
|
347 |
_show_repository_stats(repository) |
|
348 |
||
349 |
||
350 |
def show_repository_info(repository, verbose): |
|
1694.2.6
by Martin Pool
[merge] bzr.dev |
351 |
"""Output to stdout the 'info' for repository."""
|
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
352 |
control = repository.bzrdir |
353 |
||
354 |
_show_location_info(repository) |
|
355 |
_show_format_info(control, repository) |
|
1694.2.6
by Martin Pool
[merge] bzr.dev |
356 |
_show_locking_info(repository) |
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
357 |
_show_repository_info(repository) |
358 |
_show_repository_stats(repository) |