/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-06-14 17:59:16 UTC
  • mto: This revision was merged to the branch mainline in revision 7065.
  • Revision ID: jelmer@jelmer.uk-20180614175916-a2e2xh5k533guq1x
Move breezy.plugins.git to breezy.git.

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