~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/info.py

  • Committer: Aaron Bentley
  • Date: 2007-03-07 23:15:10 UTC
  • mto: (1551.19.24 Aaron's mergeable stuff)
  • mto: This revision was merged to the branch mainline in revision 2325.
  • Revision ID: abentley@panoramicfeedback.com-20070307231510-jae63zsli83db3eb
Make ChangeReporter private

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005 by Martin Pool
2
 
# Copyright (C) 2005 by Canonical Ltd
3
 
 
4
 
 
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
 
2
5
3
# This program is free software; you can redistribute it and/or modify
6
4
# it under the terms of the GNU General Public License as published by
7
5
# the Free Software Foundation; either version 2 of the License, or
8
6
# (at your option) any later version.
9
 
 
 
7
#
10
8
# This program is distributed in the hope that it will be useful,
11
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
11
# GNU General Public License for more details.
14
 
 
 
12
#
15
13
# You should have received a copy of the GNU General Public License
16
14
# along with this program; if not, write to the Free Software
17
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
19
import time
22
20
 
23
21
 
24
 
import bzrlib.diff as diff
 
22
from bzrlib import (
 
23
    diff,
 
24
    osutils,
 
25
    urlutils,
 
26
    )
25
27
from bzrlib.errors import (NoWorkingTree, NotBranchError,
26
28
                           NoRepositoryPresent, NotLocalUrl)
27
29
from bzrlib.missing import find_unmerged
28
 
import bzrlib.osutils as osutils
29
 
from bzrlib.symbol_versioning import *
 
30
from bzrlib.symbol_versioning import (deprecated_function,
 
31
        zero_eight)
30
32
 
31
33
 
32
34
def plural(n, base='', pl=None):
33
35
    if n == 1:
34
36
        return base
35
 
    elif pl != None:
 
37
    elif pl is not None:
36
38
        return pl
37
39
    else:
38
40
        return 's'
39
41
 
40
42
 
41
 
def _repo_relpath(repo_path, path):
 
43
def _repo_rel_url(repo_url, inner_url):
42
44
    """Return path with common prefix of repository path removed.
43
45
 
44
46
    If path is not part of the repository, the original path is returned.
45
47
    If path is equal to the repository, the current directory marker '.' is
46
48
    returned.
 
49
    Otherwise, a relative path is returned, with trailing '/' stripped.
47
50
    """
48
 
    path = osutils.normalizepath(path)
49
 
    repo_path = osutils.normalizepath(repo_path)
50
 
    if path == repo_path:
 
51
    inner_url = urlutils.normalize_url(inner_url)
 
52
    repo_url = urlutils.normalize_url(repo_url)
 
53
    if inner_url == repo_url:
51
54
        return '.'
52
 
    if osutils.is_inside(repo_path, path):
53
 
        return osutils.relpath(repo_path, path)
54
 
    return path
 
55
    result = urlutils.relative_url(repo_url, inner_url)
 
56
    if result != inner_url:
 
57
        result = result.rstrip('/')
 
58
    return result
55
59
 
56
60
 
57
61
def _show_location_info(repository, branch=None, working=None):
63
67
        branch_path = branch.bzrdir.root_transport.base
64
68
        if working_path != branch_path:
65
69
            # lightweight checkout
66
 
            print '  light checkout root: %s' % working_path
 
70
            print ' light checkout root: %s' % working_path
67
71
            if repository.is_shared():
68
72
                # 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))
 
73
                print '   shared repository: %s' % repository_path
 
74
                print '   repository branch: %s' % (
 
75
                    _repo_rel_url(repository_path, branch_path))
72
76
            else:
73
77
                # lightweight checkout of standalone branch
74
 
                print '   checkout of branch: %s' % branch_path
 
78
                print '  checkout of branch: %s' % branch_path
75
79
        elif repository.is_shared():
76
80
            # branch with tree inside shared repository
77
81
            print '    shared repository: %s' % repository_path
78
82
            print '  repository checkout: %s' % (
79
 
                _repo_relpath(repository_path, branch_path))
 
83
                _repo_rel_url(repository_path, branch_path))
80
84
        elif branch.get_bound_location():
81
85
            # normal checkout
82
86
            print '       checkout root: %s' % working_path
90
94
            # branch is part of shared repository
91
95
            print '  shared repository: %s' % repository_path
92
96
            print '  repository branch: %s' % (
93
 
                _repo_relpath(repository_path, branch_path))
 
97
                _repo_rel_url(repository_path, branch_path))
94
98
        else:
95
99
            # standalone branch
96
100
            print '  branch root: %s' % branch_path
172
176
    branch = working.branch
173
177
    basis = working.basis_tree()
174
178
    work_inv = working.inventory
175
 
    delta = diff.compare_trees(basis, working, want_unchanged=True)
176
 
    history = branch.revision_history()
177
 
    tree_last_id = working.last_revision()
 
179
    branch_revno, branch_last_revision = branch.last_revision_info()
 
180
    try:
 
181
        tree_last_id = working.get_parent_ids()[0]
 
182
    except IndexError:
 
183
        tree_last_id = None
178
184
 
179
 
    if len(history) and tree_last_id != history[-1]:
 
185
    if branch_revno and tree_last_id != branch_last_revision:
180
186
        tree_last_revno = branch.revision_id_to_revno(tree_last_id)
181
 
        missing_count = len(history) - tree_last_revno
 
187
        missing_count = branch_revno - tree_last_revno
182
188
        print
183
189
        print 'Working tree is out of date: missing %d revision%s.' % (
184
190
            missing_count, plural(missing_count))
188
194
    """Show statistics about a working tree."""
189
195
    basis = working.basis_tree()
190
196
    work_inv = working.inventory
191
 
    delta = diff.compare_trees(basis, working, want_unchanged=True)
 
197
    delta = working.changes_from(basis, want_unchanged=True)
192
198
 
193
199
    print
194
200
    print 'In the working tree:'
209
215
 
210
216
    dir_cnt = 0
211
217
    for file_id in work_inv:
212
 
        if work_inv.get_file_kind(file_id) == 'directory':
 
218
        if (work_inv.get_file_kind(file_id) == 'directory' and 
 
219
            not work_inv.is_root(file_id)):
213
220
            dir_cnt += 1
214
221
    print '  %8d versioned %s' \
215
222
          % (dir_cnt,
218
225
 
219
226
def _show_branch_stats(branch, verbose):
220
227
    """Show statistics about a branch."""
221
 
    repository = branch.repository
222
 
    history = branch.revision_history()
223
 
 
 
228
    revno, head = branch.last_revision_info()
224
229
    print
225
230
    print 'Branch history:'
226
 
    revno = len(history)
227
231
    print '  %8d revision%s' % (revno, plural(revno))
 
232
    stats = branch.repository.gather_stats(head, committers=verbose)
228
233
    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)))
233
 
    if revno > 0:
234
 
        firstrev = repository.get_revision(history[0])
235
 
        age = int((time.time() - firstrev.timestamp) / 3600 / 24)
 
234
        committers = stats['committers']
 
235
        print '  %8d committer%s' % (committers, plural(committers))
 
236
    if revno:
 
237
        timestamp, timezone = stats['firstrev']
 
238
        age = int((time.time() - timestamp) / 3600 / 24)
236
239
        print '  %8d day%s old' % (age, plural(age))
237
 
        print '   first revision: %s' % osutils.format_date(firstrev.timestamp,
238
 
                                                            firstrev.timezone)
239
 
 
240
 
        lastrev = repository.get_revision(history[-1])
241
 
        print '  latest revision: %s' % osutils.format_date(lastrev.timestamp,
242
 
                                                            lastrev.timezone)
243
 
 
244
 
#     print
245
 
#     print 'Text store:'
246
 
#     c, t = branch.text_store.total_size()
247
 
#     print '  %8d file texts' % c
248
 
#     print '  %8d KiB' % (t/1024)
249
 
 
250
 
#     print
251
 
#     print 'Inventory store:'
252
 
#     c, t = branch.inventory_store.total_size()
253
 
#     print '  %8d inventories' % c
254
 
#     print '  %8d KiB' % (t/1024)
 
240
        print '   first revision: %s' % osutils.format_date(timestamp,
 
241
            timezone)
 
242
        timestamp, timezone = stats['latestrev']
 
243
        print '  latest revision: %s' % osutils.format_date(timestamp,
 
244
            timezone)
 
245
    return stats
255
246
 
256
247
 
257
248
def _show_repository_info(repository):
261
252
        print 'Create working tree for new branches inside the repository.'
262
253
 
263
254
 
264
 
def _show_repository_stats(repository):
 
255
def _show_repository_stats(stats):
265
256
    """Show statistics about a repository."""
266
 
    if repository.bzrdir.root_transport.listable():
 
257
    if 'revisions' in stats or 'size' in stats:
267
258
        print
268
259
        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)
 
260
    if 'revisions' in stats:
 
261
        revisions = stats['revisions']
 
262
        print '  %8d revision%s' % (revisions, plural(revisions))
 
263
    if 'size' in stats:
 
264
        print '  %8d KiB' % (stats['size']/1024)
272
265
 
273
266
 
274
267
@deprecated_function(zero_eight)
329
322
    _show_missing_revisions_branch(branch)
330
323
    _show_missing_revisions_working(working)
331
324
    _show_working_stats(working)
332
 
    _show_branch_stats(branch, verbose)
333
 
    _show_repository_stats(repository)
 
325
    stats = _show_branch_stats(branch, verbose)
 
326
    _show_repository_stats(stats)
334
327
 
335
328
 
336
329
def show_branch_info(branch, verbose):
343
336
    _show_format_info(control, repository, branch)
344
337
    _show_locking_info(repository, branch)
345
338
    _show_missing_revisions_branch(branch)
346
 
    _show_branch_stats(branch, verbose)
347
 
    _show_repository_stats(repository)
 
339
    stats = _show_branch_stats(branch, verbose)
 
340
    _show_repository_stats(stats)
348
341
 
349
342
 
350
343
def show_repository_info(repository, verbose):
355
348
    _show_format_info(control, repository)
356
349
    _show_locking_info(repository)
357
350
    _show_repository_info(repository)
358
 
    _show_repository_stats(repository)
 
351
    stats = repository.gather_stats()
 
352
    _show_repository_stats(stats)