/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 breezy/info.py

  • Committer: Jelmer Vernooij
  • Date: 2018-02-18 21:42:57 UTC
  • mto: This revision was merged to the branch mainline in revision 6859.
  • Revision ID: jelmer@jelmer.uk-20180218214257-jpevutp1wa30tz3v
Update TODO to reference Breezy, not Bazaar.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from __future__ import absolute_import
 
18
 
17
19
__all__ = ['show_bzrdir_info']
18
20
 
19
 
from io import StringIO
20
21
import time
21
22
import sys
22
23
 
32
33
    bzrdir,
33
34
    )
34
35
from .errors import (NoWorkingTree, NotBranchError,
35
 
                     NoRepositoryPresent, NotLocalUrl)
 
36
                           NoRepositoryPresent, NotLocalUrl)
36
37
from .missing import find_unmerged
37
 
 
38
 
 
39
 
def plural(n, base=u'', pl=None):
 
38
from .sixish import (
 
39
    BytesIO,
 
40
    )
 
41
 
 
42
 
 
43
def plural(n, base='', pl=None):
40
44
    if n == 1:
41
45
        return base
42
46
    elif pl is not None:
43
47
        return pl
44
48
    else:
45
 
        return u's'
 
49
        return 's'
46
50
 
47
51
 
48
52
class LocationList(object):
77
81
 
78
82
    def get_lines(self):
79
83
        max_len = max(len(l) for l, u in self.locs)
80
 
        return ["  %*s: %s\n" % (max_len, l, u) for l, u in self.locs]
 
84
        return ["  %*s: %s\n" % (max_len, l, u) for l, u in self.locs ]
81
85
 
82
86
 
83
87
def gather_location_info(repository=None, branch=None, working=None,
84
 
                         control=None):
 
88
        control=None):
85
89
    locs = {}
86
90
    if branch is not None:
87
91
        branch_path = branch.user_url
106
110
            else:
107
111
                locs['checkout root'] = branch_path
108
112
        if working_path != master_path:
109
 
            (master_path_base, params) = urlutils.split_segment_parameters(
110
 
                master_path)
111
 
            if working_path == master_path_base:
112
 
                locs['checkout of co-located branch'] = params['branch']
113
 
            elif 'branch' in params:
114
 
                locs['checkout of branch'] = "%s, branch %s" % (
115
 
                    master_path_base, params['branch'])
116
 
            else:
117
 
                locs['checkout of branch'] = master_path
 
113
            locs['checkout of branch'] = master_path
118
114
        elif repository.is_shared():
119
115
            locs['repository branch'] = branch_path
120
116
        elif branch_path is not None:
144
140
        locs['shared repository'] = repository.user_url
145
141
    order = ['control directory', 'light checkout root',
146
142
             'repository checkout root', 'checkout root',
147
 
             'checkout of branch', 'checkout of co-located branch',
148
 
             'shared repository', 'repository', 'repository branch',
149
 
             'branch root', 'bound to branch']
 
143
             'checkout of branch', 'shared repository',
 
144
             'repository', 'repository branch', 'branch root',
 
145
             'bound to branch']
150
146
    return [(n, locs[n]) for n in order if n in locs]
151
147
 
152
148
 
168
164
    try:
169
165
        locs.add_url('stacked on', branch.get_stacked_on_url())
170
166
    except (_mod_branch.UnstackableBranchFormat, errors.UnstackableRepositoryFormat,
171
 
            errors.NotStacked):
 
167
        errors.NotStacked):
172
168
        pass
173
169
    return locs
174
170
 
197
193
    outfile.write('Format:\n')
198
194
    if control:
199
195
        outfile.write('       control: %s\n' %
200
 
                      control._format.get_format_description())
 
196
            control._format.get_format_description())
201
197
    if working:
202
198
        outfile.write('  working tree: %s\n' %
203
 
                      working._format.get_format_description())
 
199
            working._format.get_format_description())
204
200
    if branch:
205
201
        outfile.write('        branch: %s\n' %
206
 
                      branch._format.get_format_description())
 
202
            branch._format.get_format_description())
207
203
    if repository:
208
204
        outfile.write('    repository: %s\n' %
209
 
                      repository._format.get_format_description())
 
205
            repository._format.get_format_description())
210
206
 
211
207
 
212
208
def _show_locking_info(repository=None, branch=None, working=None,
213
 
                       outfile=None):
 
209
        outfile=None):
214
210
    """Show locking status of working, branch and repository."""
215
211
    if (repository and repository.get_physical_lock_status() or
216
212
        (branch and branch.get_physical_lock_status()) or
217
 
            (working and working.get_physical_lock_status())):
 
213
        (working and working.get_physical_lock_status())):
218
214
        outfile.write('\n')
219
215
        outfile.write('Lock status:\n')
220
216
        if working:
246
242
        if remote_extra:
247
243
            outfile.write('\n')
248
244
            outfile.write(('Branch is out of date: missing %d '
249
 
                           'revision%s.\n') % (len(remote_extra),
250
 
                                               plural(len(remote_extra))))
 
245
                'revision%s.\n') % (len(remote_extra),
 
246
                plural(len(remote_extra))))
251
247
 
252
248
 
253
249
def _show_missing_revisions_working(working, outfile):
254
250
    """Show missing revisions in working tree."""
255
251
    branch = working.branch
 
252
    basis = working.basis_tree()
256
253
    try:
257
254
        branch_revno, branch_last_revision = branch.last_revision_info()
258
255
    except errors.UnsupportedOperation:
267
264
        missing_count = branch_revno - tree_last_revno
268
265
        outfile.write('\n')
269
266
        outfile.write(('Working tree is out of date: missing %d '
270
 
                       'revision%s.\n') % (missing_count, plural(missing_count)))
 
267
            'revision%s.\n') % (missing_count, plural(missing_count)))
271
268
 
272
269
 
273
270
def _show_working_stats(working, outfile):
282
279
    outfile.write('  %8d added\n' % len(delta.added))
283
280
    outfile.write('  %8d removed\n' % len(delta.removed))
284
281
    outfile.write('  %8d renamed\n' % len(delta.renamed))
285
 
    outfile.write('  %8d copied\n' % len(delta.copied))
286
282
 
287
283
    ignore_cnt = unknown_cnt = 0
288
284
    for path in working.extras():
294
290
    outfile.write('  %8d ignored\n' % ignore_cnt)
295
291
 
296
292
    dir_cnt = 0
 
293
    root_id = working.get_root_id()
297
294
    for path, entry in working.iter_entries_by_dir():
298
 
        if entry.kind == 'directory' and path != '':
 
295
        if entry.kind == 'directory' and entry.file_id != root_id:
299
296
            dir_cnt += 1
300
297
    outfile.write('  %8d versioned %s\n' % (dir_cnt,
301
 
                                            plural(dir_cnt, 'subdirectory', 'subdirectories')))
 
298
        plural(dir_cnt, 'subdirectory', 'subdirectories')))
302
299
 
303
300
 
304
301
def _show_branch_stats(branch, verbose, outfile):
314
311
    if verbose:
315
312
        committers = stats['committers']
316
313
        outfile.write('  %8d committer%s\n' % (committers,
317
 
                                               plural(committers)))
 
314
            plural(committers)))
318
315
    if revno:
319
316
        timestamp, timezone = stats['firstrev']
320
317
        age = int((time.time() - timestamp) / 3600 / 24)
321
318
        outfile.write('  %8d day%s old\n' % (age, plural(age)))
322
319
        outfile.write('   first revision: %s\n' %
323
 
                      osutils.format_date(timestamp, timezone))
 
320
            osutils.format_date(timestamp, timezone))
324
321
        timestamp, timezone = stats['latestrev']
325
322
        outfile.write('  latest revision: %s\n' %
326
 
                      osutils.format_date(timestamp, timezone))
 
323
            osutils.format_date(timestamp, timezone))
327
324
    return stats
328
325
 
329
326
 
332
329
    if repository.make_working_trees():
333
330
        outfile.write('\n')
334
331
        outfile.write('Create working tree for new branches inside '
335
 
                      'the repository.\n')
 
332
            'the repository.\n')
336
333
 
337
334
 
338
335
def _show_repository_stats(repository, stats, outfile):
339
336
    """Show statistics about a repository."""
340
 
    f = StringIO()
 
337
    f = BytesIO()
341
338
    if 'revisions' in stats:
342
339
        revisions = stats['revisions']
343
340
        f.write('  %8d revision%s\n' % (revisions, plural(revisions)))
344
341
    if 'size' in stats:
345
 
        f.write('  %8d KiB\n' % (stats['size'] / 1024))
 
342
        f.write('  %8d KiB\n' % (stats['size']/1024))
346
343
    for hook in hooks['repository']:
347
344
        hook(repository, stats, f)
348
345
    if f.getvalue() != "":
390
387
 
391
388
 
392
389
def show_component_info(control, repository, branch=None, working=None,
393
 
                        verbose=1, outfile=None):
 
390
    verbose=1, outfile=None):
394
391
    """Write info about all bzrdir components to stdout"""
395
392
    if outfile is None:
396
393
        outfile = sys.stdout
403
400
    outfile.write("%s (format: %s)\n" % (layout, format))
404
401
    _show_location_info(
405
402
        gather_location_info(control=control, repository=repository,
406
 
                             branch=branch, working=working),
 
403
            branch=branch, working=working),
407
404
        outfile)
408
405
    if branch is not None:
409
406
        _show_related_info(branch, outfile)
455
452
        extra = []
456
453
        if repository.make_working_trees():
457
454
            extra.append('trees')
458
 
        if len(control.branch_names()) > 0:
 
455
        if len(control.get_branches()) > 0:
459
456
            extra.append('colocated branches')
460
457
        if extra:
461
458
            phrase += ' with ' + " and ".join(extra)
472
469
        if branch is None and tree is not None:
473
470
            phrase = "branchless tree"
474
471
        else:
475
 
            if (tree is not None and tree.controldir.control_url !=
476
 
                    branch.controldir.control_url):
 
472
            if (tree is not None and tree.user_url !=
 
473
                branch.user_url):
477
474
                independence = ''
478
475
                phrase = "Lightweight checkout"
479
476
            elif branch.get_bound_location() is not None:
496
493
 
497
494
    If no matching candidate is found, "unnamed" is returned.
498
495
    """
499
 
    candidates = []
 
496
    candidates  = []
500
497
    if (branch is not None and tree is not None and
501
 
            branch.user_url != tree.user_url):
 
498
        branch.user_url != tree.user_url):
502
499
        branch = None
503
500
        repository = None
504
501
    non_aliases = set(controldir.format_registry.keys())
507
504
        format = controldir.format_registry.make_controldir(key)
508
505
        if isinstance(format, bzrdir.BzrDirMetaFormat1):
509
506
            if (tree and format.workingtree_format !=
510
 
                    tree._format):
 
507
                tree._format):
511
508
                continue
512
509
            if (branch and format.get_branch_format() !=
513
 
                    branch._format):
 
510
                branch._format):
514
511
                continue
515
512
            if (repository and format.repository_format !=
516
 
                    repository._format):
 
513
                repository._format):
517
514
                continue
518
515
        if format.__class__ is not control._format.__class__:
519
516
            continue
522
519
        return 'unnamed'
523
520
    candidates.sort()
524
521
    new_candidates = [c for c in candidates if not
525
 
                      controldir.format_registry.get_info(c).hidden]
 
522
        controldir.format_registry.get_info(c).hidden]
526
523
    if len(new_candidates) > 0:
527
524
        # If there are any non-hidden formats that match, only return those to
528
525
        # avoid listing hidden formats except when only a hidden format will
536
533
 
537
534
    def __init__(self):
538
535
        super(InfoHooks, self).__init__("breezy.info", "hooks")
539
 
        self.add_hook(
540
 
            'repository',
 
536
        self.add_hook('repository',
541
537
            "Invoked when displaying the statistics for a repository. "
542
538
            "repository is called with a statistics dictionary as returned "
543
539
            "by the repository and a file-like object to write to.", (1, 15))