~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/info.py

Update test support, and remove deprecated functions pullable_revisions and get_intervening_revisions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
from bzrlib.errors import (NoWorkingTree, NotBranchError,
26
26
                           NoRepositoryPresent, NotLocalUrl)
27
27
from bzrlib.missing import find_unmerged
28
 
from bzrlib.osutils import format_date
 
28
import bzrlib.osutils as osutils
29
29
from bzrlib.symbol_versioning import *
30
30
 
31
31
 
32
 
def _countiter(it):
33
 
    # surely there's a builtin for this?
34
 
    i = 0
35
 
    for j in it:
36
 
        i += 1
37
 
    return i        
38
 
 
39
 
 
40
32
def plural(n, base='', pl=None):
41
33
    if n == 1:
42
34
        return base
46
38
        return 's'
47
39
 
48
40
 
49
 
def _show_location_info(repository=None, branch=None, working=None):
 
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):
50
58
    """Show known locations for working, branch and repository."""
 
59
    repository_path = repository.bzrdir.root_transport.base
51
60
    print 'Location:'
52
 
    if working and branch and working.bzrdir != branch.bzrdir:
53
 
        # Lightweight checkout
54
 
        print '       checkout root: %s' % (
55
 
            working.bzrdir.root_transport.base)
56
 
        print '  checkout of branch: %s' % (
57
 
            branch.bzrdir.root_transport.base)
 
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
58
87
    elif branch:
59
 
        # Standalone or bound branch (normal checkout)
60
 
        print '         branch root: %s' % (
61
 
            branch.bzrdir.root_transport.base)
62
 
        if branch.get_bound_location():
63
 
            print '     bound to branch: %s' % branch.get_bound_location()
64
 
 
65
 
    if repository and (not branch or repository.bzrdir != branch.bzrdir):
66
 
        if repository.is_shared():
67
 
            print '   shared repository: %s' % (
68
 
                repository.bzrdir.root_transport.base)
69
 
        else:
70
 
            print '          repository: %s' % (
71
 
                repository.bzrdir.root_transport.base)
72
 
 
73
 
    if branch:
 
88
        # branch is part of shared repository
 
89
        assert repository.is_shared()
 
90
        branch_path = branch.bzrdir.root_transport.base
 
91
        print '  shared repository: %s' % repository_path
 
92
        print '  repository branch: %s' % (
 
93
            _repo_relpath(repository_path, branch_path))
 
94
    else:
 
95
        # shared repository
 
96
        assert repository.is_shared()
 
97
        print '  shared repository: %s' % repository_path
 
98
 
 
99
 
 
100
def _show_related_info(branch):
 
101
    """Show parent and push location of branch."""
 
102
    if branch.get_parent() or branch.get_push_location():
 
103
        print
 
104
        print 'Related branches:'
74
105
        if branch.get_parent():
75
 
            print '       parent branch: %s' % branch.get_parent()
 
106
            if branch.get_push_location():
 
107
                print '      parent branch: %s' % branch.get_parent()
 
108
            else:
 
109
                print '  parent branch: %s' % branch.get_parent()
76
110
        if branch.get_push_location():
77
 
            print '      push to branch: %s' % branch.get_push_location()
 
111
            print '  publish to branch: %s' % branch.get_push_location()
78
112
 
79
113
 
80
114
def _show_format_info(control=None, repository=None, branch=None, working=None):
91
125
        print '    repository: %s' % repository._format.get_format_description()
92
126
 
93
127
 
 
128
def _show_locking_info(repository, branch=None, working=None):
 
129
    """Show locking status of working, branch and repository."""
 
130
    if (repository.get_physical_lock_status() or
 
131
        (branch and branch.get_physical_lock_status()) or
 
132
        (working and working.get_physical_lock_status())):
 
133
        print
 
134
        print 'Lock status:'
 
135
        if working:
 
136
            if working.get_physical_lock_status():
 
137
                status = 'locked'
 
138
            else:
 
139
                status = 'unlocked'
 
140
            print '  working tree: %s' % status
 
141
        if branch:
 
142
            if branch.get_physical_lock_status():
 
143
                status = 'locked'
 
144
            else:
 
145
                status = 'unlocked'
 
146
            print '        branch: %s' % status
 
147
        if repository:
 
148
            if repository.get_physical_lock_status():
 
149
                status = 'locked'
 
150
            else:
 
151
                status = 'unlocked'
 
152
            print '    repository: %s' % status
 
153
 
 
154
 
94
155
def _show_missing_revisions_branch(branch):
95
156
    """Show missing master revisions in branch."""
96
157
    # Try with inaccessible branch ?
170
231
        firstrev = repository.get_revision(history[0])
171
232
        age = int((time.time() - firstrev.timestamp) / 3600 / 24)
172
233
        print '  %8d day%s old' % (age, plural(age))
173
 
        print '   first revision: %s' % format_date(firstrev.timestamp,
174
 
                                                    firstrev.timezone)
 
234
        print '   first revision: %s' % osutils.format_date(firstrev.timestamp,
 
235
                                                            firstrev.timezone)
175
236
 
176
237
        lastrev = repository.get_revision(history[-1])
177
 
        print '  latest revision: %s' % format_date(lastrev.timestamp,
178
 
                                                    lastrev.timezone)
 
238
        print '  latest revision: %s' % osutils.format_date(lastrev.timestamp,
 
239
                                                            lastrev.timezone)
179
240
 
180
241
#     print
181
242
#     print 'Text store:'
248
309
    except NoRepositoryPresent:
249
310
        pass
250
311
 
251
 
    # Return silently, cmd_info returns NotBranchError if no bzrdir
 
312
    # Return silently, cmd_info already returned NotBranchError if no bzrdir
252
313
    # could be opened.
253
314
 
254
315
 
259
320
    control = working.bzrdir
260
321
 
261
322
    _show_location_info(repository, branch, working)
 
323
    _show_related_info(branch)
262
324
    _show_format_info(control, repository, branch, working)
 
325
    _show_locking_info(repository, branch, working)
263
326
    _show_missing_revisions_branch(branch)
264
327
    _show_missing_revisions_working(working)
265
328
    _show_working_stats(working)
273
336
    control = branch.bzrdir
274
337
 
275
338
    _show_location_info(repository, branch)
 
339
    _show_related_info(branch)
276
340
    _show_format_info(control, repository, branch)
 
341
    _show_locking_info(repository, branch)
277
342
    _show_missing_revisions_branch(branch)
278
343
    _show_branch_stats(branch, verbose)
279
344
    _show_repository_stats(repository)
280
345
 
281
346
 
282
347
def show_repository_info(repository, verbose):
283
 
    """Output to stdout the 'info' for branch."""
 
348
    """Output to stdout the 'info' for repository."""
284
349
    control = repository.bzrdir
285
350
 
286
351
    _show_location_info(repository)
287
352
    _show_format_info(control, repository)
 
353
    _show_locking_info(repository)
288
354
    _show_repository_info(repository)
289
355
    _show_repository_stats(repository)