/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/info.py

  • Committer: John Arbash Meinel
  • Date: 2006-09-13 02:09:37 UTC
  • mto: This revision was merged to the branch mainline in revision 2004.
  • Revision ID: john@arbash-meinel.com-20060913020937-2df2f49f9a28ec43
Update HACKING and docstrings

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 by Canonical Ltd
2
2
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.
7
 
#
 
7
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.
12
 
#
 
12
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
19
19
import time
20
20
 
21
21
 
22
 
from bzrlib import (
23
 
    diff,
24
 
    osutils,
25
 
    urlutils,
26
 
    )
 
22
import bzrlib.diff as diff
27
23
from bzrlib.errors import (NoWorkingTree, NotBranchError,
28
24
                           NoRepositoryPresent, NotLocalUrl)
29
25
from bzrlib.missing import find_unmerged
30
 
from bzrlib.symbol_versioning import (deprecated_function,
 
26
import bzrlib.osutils as osutils
 
27
from bzrlib.symbol_versioning import (deprecated_function, 
31
28
        zero_eight)
32
29
 
33
30
 
40
37
        return 's'
41
38
 
42
39
 
43
 
def _repo_rel_url(repo_url, inner_url):
 
40
def _repo_relpath(repo_path, path):
44
41
    """Return path with common prefix of repository path removed.
45
42
 
46
43
    If path is not part of the repository, the original path is returned.
47
44
    If path is equal to the repository, the current directory marker '.' is
48
45
    returned.
49
 
    Otherwise, a relative path is returned, with trailing '/' stripped.
50
46
    """
51
 
    inner_url = urlutils.normalize_url(inner_url)
52
 
    repo_url = urlutils.normalize_url(repo_url)
53
 
    if inner_url == repo_url:
 
47
    path = osutils.normalizepath(path)
 
48
    repo_path = osutils.normalizepath(repo_path)
 
49
    if path == repo_path:
54
50
        return '.'
55
 
    result = urlutils.relative_url(repo_url, inner_url)
56
 
    if result != inner_url:
57
 
        result = result.rstrip('/')
58
 
    return result
 
51
    if osutils.is_inside(repo_path, path):
 
52
        return osutils.relpath(repo_path, path)
 
53
    return path
59
54
 
60
55
 
61
56
def _show_location_info(repository, branch=None, working=None):
72
67
                # lightweight checkout of branch in shared repository
73
68
                print '   shared repository: %s' % repository_path
74
69
                print '   repository branch: %s' % (
75
 
                    _repo_rel_url(repository_path, branch_path))
 
70
                    _repo_relpath(repository_path, branch_path))
76
71
            else:
77
72
                # lightweight checkout of standalone branch
78
73
                print '  checkout of branch: %s' % branch_path
80
75
            # branch with tree inside shared repository
81
76
            print '    shared repository: %s' % repository_path
82
77
            print '  repository checkout: %s' % (
83
 
                _repo_rel_url(repository_path, branch_path))
 
78
                _repo_relpath(repository_path, branch_path))
84
79
        elif branch.get_bound_location():
85
80
            # normal checkout
86
81
            print '       checkout root: %s' % working_path
94
89
            # branch is part of shared repository
95
90
            print '  shared repository: %s' % repository_path
96
91
            print '  repository branch: %s' % (
97
 
                _repo_rel_url(repository_path, branch_path))
 
92
                _repo_relpath(repository_path, branch_path))
98
93
        else:
99
94
            # standalone branch
100
95
            print '  branch root: %s' % branch_path
176
171
    branch = working.branch
177
172
    basis = working.basis_tree()
178
173
    work_inv = working.inventory
179
 
    branch_revno, branch_last_revision = branch.last_revision_info()
 
174
    delta = working.changes_from(basis, want_unchanged=True)
 
175
    history = branch.revision_history()
180
176
    try:
181
177
        tree_last_id = working.get_parent_ids()[0]
182
178
    except IndexError:
183
179
        tree_last_id = None
184
180
 
185
 
    if branch_revno and tree_last_id != branch_last_revision:
 
181
    if len(history) and tree_last_id != history[-1]:
186
182
        tree_last_revno = branch.revision_id_to_revno(tree_last_id)
187
 
        missing_count = branch_revno - tree_last_revno
 
183
        missing_count = len(history) - tree_last_revno
188
184
        print
189
185
        print 'Working tree is out of date: missing %d revision%s.' % (
190
186
            missing_count, plural(missing_count))
214
210
    print '  %8d ignored' % ignore_cnt
215
211
 
216
212
    dir_cnt = 0
217
 
    for file_id in work_inv:
218
 
        if (work_inv.get_file_kind(file_id) == 'directory' and 
219
 
            not work_inv.is_root(file_id)):
220
 
            dir_cnt += 1
 
213
    entries = work_inv.iter_entries()
 
214
    entries.next()
 
215
    dir_cnt = sum(1 for path, ie in entries if ie.kind == 'directory')
221
216
    print '  %8d versioned %s' \
222
217
          % (dir_cnt,
223
218
             plural(dir_cnt, 'subdirectory', 'subdirectories'))
225
220
 
226
221
def _show_branch_stats(branch, verbose):
227
222
    """Show statistics about a branch."""
228
 
    revno, head = branch.last_revision_info()
 
223
    repository = branch.repository
 
224
    history = branch.revision_history()
 
225
 
229
226
    print
230
227
    print 'Branch history:'
 
228
    revno = len(history)
231
229
    print '  %8d revision%s' % (revno, plural(revno))
232
 
    stats = branch.repository.gather_stats(head, committers=verbose)
233
230
    if verbose:
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)
 
231
        committers = {}
 
232
        for rev in history:
 
233
            committers[repository.get_revision(rev).committer] = True
 
234
        print '  %8d committer%s' % (len(committers), plural(len(committers)))
 
235
    if revno > 0:
 
236
        firstrev = repository.get_revision(history[0])
 
237
        age = int((time.time() - firstrev.timestamp) / 3600 / 24)
239
238
        print '  %8d day%s old' % (age, plural(age))
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
 
239
        print '   first revision: %s' % osutils.format_date(firstrev.timestamp,
 
240
                                                            firstrev.timezone)
 
241
 
 
242
        lastrev = repository.get_revision(history[-1])
 
243
        print '  latest revision: %s' % osutils.format_date(lastrev.timestamp,
 
244
                                                            lastrev.timezone)
 
245
 
 
246
#     print
 
247
#     print 'Text store:'
 
248
#     c, t = branch.text_store.total_size()
 
249
#     print '  %8d file texts' % c
 
250
#     print '  %8d KiB' % (t/1024)
 
251
 
 
252
#     print
 
253
#     print 'Inventory store:'
 
254
#     c, t = branch.inventory_store.total_size()
 
255
#     print '  %8d inventories' % c
 
256
#     print '  %8d KiB' % (t/1024)
246
257
 
247
258
 
248
259
def _show_repository_info(repository):
252
263
        print 'Create working tree for new branches inside the repository.'
253
264
 
254
265
 
255
 
def _show_repository_stats(stats):
 
266
def _show_repository_stats(repository):
256
267
    """Show statistics about a repository."""
257
 
    if 'revisions' in stats or 'size' in stats:
 
268
    if repository.bzrdir.root_transport.listable():
258
269
        print
259
 
        print 'Repository:'
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)
 
270
        print 'Revision store:'
 
271
        c, t = repository._revision_store.total_size(repository.get_transaction())
 
272
        print '  %8d revision%s' % (c, plural(c))
 
273
        print '  %8d KiB' % (t/1024)
265
274
 
266
275
 
267
276
@deprecated_function(zero_eight)
273
282
def show_bzrdir_info(a_bzrdir, verbose=False):
274
283
    """Output to stdout the 'info' for a_bzrdir."""
275
284
    try:
276
 
        working = a_bzrdir.open_workingtree(
277
 
            recommend_upgrade=False)
 
285
        working = a_bzrdir.open_workingtree()
278
286
        working.lock_read()
279
287
        try:
280
288
            show_tree_info(working, verbose)
323
331
    _show_missing_revisions_branch(branch)
324
332
    _show_missing_revisions_working(working)
325
333
    _show_working_stats(working)
326
 
    stats = _show_branch_stats(branch, verbose)
327
 
    _show_repository_stats(stats)
 
334
    _show_branch_stats(branch, verbose)
 
335
    _show_repository_stats(repository)
328
336
 
329
337
 
330
338
def show_branch_info(branch, verbose):
337
345
    _show_format_info(control, repository, branch)
338
346
    _show_locking_info(repository, branch)
339
347
    _show_missing_revisions_branch(branch)
340
 
    stats = _show_branch_stats(branch, verbose)
341
 
    _show_repository_stats(stats)
 
348
    _show_branch_stats(branch, verbose)
 
349
    _show_repository_stats(repository)
342
350
 
343
351
 
344
352
def show_repository_info(repository, verbose):
349
357
    _show_format_info(control, repository)
350
358
    _show_locking_info(repository)
351
359
    _show_repository_info(repository)
352
 
    stats = repository.gather_stats()
353
 
    _show_repository_stats(stats)
 
360
    _show_repository_stats(repository)