/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: 2020-05-06 02:13:25 UTC
  • mfrom: (7490.7.21 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200506021325-awbmmqu1zyorz7sj
Merge 3.1 branch.

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