1
# Copyright (C) 2005, 2006 by Canonical Ltd
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
11
# GNU General Public License for more details.
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
import bzrlib.diff as diff
23
27
from bzrlib.errors import (NoWorkingTree, NotBranchError,
24
28
NoRepositoryPresent, NotLocalUrl)
25
29
from bzrlib.missing import find_unmerged
26
import bzrlib.osutils as osutils
27
from bzrlib.symbol_versioning import *
30
from bzrlib.symbol_versioning import (deprecated_function,
30
34
def plural(n, base='', pl=None):
39
def _repo_relpath(repo_path, path):
43
def _repo_rel_url(repo_url, inner_url):
40
44
"""Return path with common prefix of repository path removed.
42
46
If path is not part of the repository, the original path is returned.
43
47
If path is equal to the repository, the current directory marker '.' is
49
Otherwise, a relative path is returned, with trailing '/' stripped.
46
path = osutils.normalizepath(path)
47
repo_path = osutils.normalizepath(repo_path)
51
inner_url = urlutils.normalize_url(inner_url)
52
repo_url = urlutils.normalize_url(repo_url)
53
if inner_url == repo_url:
50
if osutils.is_inside(repo_path, path):
51
return osutils.relpath(repo_path, path)
55
result = urlutils.relative_url(repo_url, inner_url)
56
if result != inner_url:
57
result = result.rstrip('/')
55
61
def _show_location_info(repository, branch=None, working=None):
61
67
branch_path = branch.bzrdir.root_transport.base
62
68
if working_path != branch_path:
63
69
# lightweight checkout
64
print ' light checkout root: %s' % working_path
70
print ' light checkout root: %s' % working_path
65
71
if repository.is_shared():
66
72
# lightweight checkout of branch in shared repository
67
print ' shared repository: %s' % repository_path
68
print ' repository branch: %s' % (
69
_repo_relpath(repository_path, branch_path))
73
print ' shared repository: %s' % repository_path
74
print ' repository branch: %s' % (
75
_repo_rel_url(repository_path, branch_path))
71
77
# lightweight checkout of standalone branch
72
print ' checkout of branch: %s' % branch_path
78
print ' checkout of branch: %s' % branch_path
73
79
elif repository.is_shared():
74
80
# branch with tree inside shared repository
75
81
print ' shared repository: %s' % repository_path
76
82
print ' repository checkout: %s' % (
77
_repo_relpath(repository_path, branch_path))
83
_repo_rel_url(repository_path, branch_path))
78
84
elif branch.get_bound_location():
80
86
print ' checkout root: %s' % working_path
88
94
# branch is part of shared repository
89
95
print ' shared repository: %s' % repository_path
90
96
print ' repository branch: %s' % (
91
_repo_relpath(repository_path, branch_path))
97
_repo_rel_url(repository_path, branch_path))
93
99
# standalone branch
94
100
print ' branch root: %s' % branch_path
170
176
branch = working.branch
171
177
basis = working.basis_tree()
172
178
work_inv = working.inventory
173
delta = diff.compare_trees(basis, working, want_unchanged=True)
174
history = branch.revision_history()
175
tree_last_id = working.last_revision()
179
branch_revno, branch_last_revision = branch.last_revision_info()
181
tree_last_id = working.get_parent_ids()[0]
177
if len(history) and tree_last_id != history[-1]:
185
if branch_revno and tree_last_id != branch_last_revision:
178
186
tree_last_revno = branch.revision_id_to_revno(tree_last_id)
179
missing_count = len(history) - tree_last_revno
187
missing_count = branch_revno - tree_last_revno
181
189
print 'Working tree is out of date: missing %d revision%s.' % (
182
190
missing_count, plural(missing_count))
186
194
"""Show statistics about a working tree."""
187
195
basis = working.basis_tree()
188
196
work_inv = working.inventory
189
delta = diff.compare_trees(basis, working, want_unchanged=True)
197
delta = working.changes_from(basis, want_unchanged=True)
192
200
print 'In the working tree:'
217
226
def _show_branch_stats(branch, verbose):
218
227
"""Show statistics about a branch."""
219
repository = branch.repository
220
history = branch.revision_history()
228
revno, head = branch.last_revision_info()
223
230
print 'Branch history:'
225
231
print ' %8d revision%s' % (revno, plural(revno))
232
stats = branch.repository.gather_stats(head, committers=verbose)
229
committers[repository.get_revision(rev).committer] = True
230
print ' %8d committer%s' % (len(committers), plural(len(committers)))
232
firstrev = repository.get_revision(history[0])
233
age = int((time.time() - firstrev.timestamp) / 3600 / 24)
234
committers = stats['committers']
235
print ' %8d committer%s' % (committers, plural(committers))
237
timestamp, timezone = stats['firstrev']
238
age = int((time.time() - timestamp) / 3600 / 24)
234
239
print ' %8d day%s old' % (age, plural(age))
235
print ' first revision: %s' % osutils.format_date(firstrev.timestamp,
238
lastrev = repository.get_revision(history[-1])
239
print ' latest revision: %s' % osutils.format_date(lastrev.timestamp,
243
# print 'Text store:'
244
# c, t = branch.text_store.total_size()
245
# print ' %8d file texts' % c
246
# print ' %8d KiB' % (t/1024)
249
# print 'Inventory store:'
250
# c, t = branch.inventory_store.total_size()
251
# print ' %8d inventories' % c
252
# print ' %8d KiB' % (t/1024)
240
print ' first revision: %s' % osutils.format_date(timestamp,
242
timestamp, timezone = stats['latestrev']
243
print ' latest revision: %s' % osutils.format_date(timestamp,
255
248
def _show_repository_info(repository):
259
252
print 'Create working tree for new branches inside the repository.'
262
def _show_repository_stats(repository):
255
def _show_repository_stats(stats):
263
256
"""Show statistics about a repository."""
264
if repository.bzrdir.root_transport.listable():
257
if 'revisions' in stats or 'size' in stats:
266
print 'Revision store:'
267
c, t = repository._revision_store.total_size(repository.get_transaction())
268
print ' %8d revision%s' % (c, plural(c))
269
print ' %8d KiB' % (t/1024)
260
if 'revisions' in stats:
261
revisions = stats['revisions']
262
print ' %8d revision%s' % (revisions, plural(revisions))
264
print ' %8d KiB' % (stats['size']/1024)
272
267
@deprecated_function(zero_eight)
278
273
def show_bzrdir_info(a_bzrdir, verbose=False):
279
274
"""Output to stdout the 'info' for a_bzrdir."""
281
working = a_bzrdir.open_workingtree()
276
working = a_bzrdir.open_workingtree(
277
recommend_upgrade=False)
282
278
working.lock_read()
284
280
show_tree_info(working, verbose)
327
323
_show_missing_revisions_branch(branch)
328
324
_show_missing_revisions_working(working)
329
325
_show_working_stats(working)
330
_show_branch_stats(branch, verbose)
331
_show_repository_stats(repository)
326
stats = _show_branch_stats(branch, verbose)
327
_show_repository_stats(stats)
334
330
def show_branch_info(branch, verbose):
341
337
_show_format_info(control, repository, branch)
342
338
_show_locking_info(repository, branch)
343
339
_show_missing_revisions_branch(branch)
344
_show_branch_stats(branch, verbose)
345
_show_repository_stats(repository)
340
stats = _show_branch_stats(branch, verbose)
341
_show_repository_stats(stats)
348
344
def show_repository_info(repository, verbose):
353
349
_show_format_info(control, repository)
354
350
_show_locking_info(repository)
355
351
_show_repository_info(repository)
356
_show_repository_stats(repository)
352
stats = repository.gather_stats()
353
_show_repository_stats(stats)