/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: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

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
 
21
from cStringIO import StringIO
20
22
import time
21
23
import sys
22
24
 
23
 
from . import (
24
 
    branch as _mod_branch,
 
25
from bzrlib import (
 
26
    bzrdir,
25
27
    controldir,
26
28
    errors,
27
29
    hooks as _mod_hooks,
28
30
    osutils,
29
31
    urlutils,
30
32
    )
31
 
from .bzr import (
32
 
    bzrdir,
33
 
    )
34
 
from .errors import (NoWorkingTree, NotBranchError,
35
 
                     NoRepositoryPresent, NotLocalUrl)
36
 
from .missing import find_unmerged
37
 
 
38
 
 
39
 
def plural(n, base=u'', pl=None):
 
33
from bzrlib.errors import (NoWorkingTree, NotBranchError,
 
34
                           NoRepositoryPresent, NotLocalUrl)
 
35
from bzrlib.missing import find_unmerged
 
36
 
 
37
 
 
38
def plural(n, base='', pl=None):
40
39
    if n == 1:
41
40
        return base
42
41
    elif pl is not None:
43
42
        return pl
44
43
    else:
45
 
        return u's'
 
44
        return 's'
46
45
 
47
46
 
48
47
class LocationList(object):
57
56
            return
58
57
        try:
59
58
            path = urlutils.local_path_from_url(url)
60
 
        except urlutils.InvalidURL:
 
59
        except errors.InvalidURL:
61
60
            self.locs.append((label, url))
62
61
        else:
63
62
            self.add_path(label, path)
77
76
 
78
77
    def get_lines(self):
79
78
        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]
 
79
        return ["  %*s: %s\n" % (max_len, l, u) for l, u in self.locs ]
81
80
 
82
81
 
83
82
def gather_location_info(repository=None, branch=None, working=None,
84
 
                         control=None):
 
83
        control=None):
85
84
    locs = {}
86
85
    if branch is not None:
87
86
        branch_path = branch.user_url
106
105
            else:
107
106
                locs['checkout root'] = branch_path
108
107
        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
 
108
            locs['checkout of branch'] = master_path
118
109
        elif repository.is_shared():
119
110
            locs['repository branch'] = branch_path
120
111
        elif branch_path is not None:
144
135
        locs['shared repository'] = repository.user_url
145
136
    order = ['control directory', 'light checkout root',
146
137
             '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']
 
138
             'checkout of branch', 'shared repository',
 
139
             'repository', 'repository branch', 'branch root',
 
140
             'bound to branch']
150
141
    return [(n, locs[n]) for n in order if n in locs]
151
142
 
152
143
 
167
158
    locs.add_url('submit branch', branch.get_submit_branch())
168
159
    try:
169
160
        locs.add_url('stacked on', branch.get_stacked_on_url())
170
 
    except (_mod_branch.UnstackableBranchFormat, errors.UnstackableRepositoryFormat,
171
 
            errors.NotStacked):
 
161
    except (errors.UnstackableBranchFormat, errors.UnstackableRepositoryFormat,
 
162
        errors.NotStacked):
172
163
        pass
173
164
    return locs
174
165
 
197
188
    outfile.write('Format:\n')
198
189
    if control:
199
190
        outfile.write('       control: %s\n' %
200
 
                      control._format.get_format_description())
 
191
            control._format.get_format_description())
201
192
    if working:
202
193
        outfile.write('  working tree: %s\n' %
203
 
                      working._format.get_format_description())
 
194
            working._format.get_format_description())
204
195
    if branch:
205
196
        outfile.write('        branch: %s\n' %
206
 
                      branch._format.get_format_description())
 
197
            branch._format.get_format_description())
207
198
    if repository:
208
199
        outfile.write('    repository: %s\n' %
209
 
                      repository._format.get_format_description())
 
200
            repository._format.get_format_description())
210
201
 
211
202
 
212
203
def _show_locking_info(repository=None, branch=None, working=None,
213
 
                       outfile=None):
 
204
        outfile=None):
214
205
    """Show locking status of working, branch and repository."""
215
206
    if (repository and repository.get_physical_lock_status() or
216
207
        (branch and branch.get_physical_lock_status()) or
217
 
            (working and working.get_physical_lock_status())):
 
208
        (working and working.get_physical_lock_status())):
218
209
        outfile.write('\n')
219
210
        outfile.write('Lock status:\n')
220
211
        if working:
246
237
        if remote_extra:
247
238
            outfile.write('\n')
248
239
            outfile.write(('Branch is out of date: missing %d '
249
 
                           'revision%s.\n') % (len(remote_extra),
250
 
                                               plural(len(remote_extra))))
 
240
                'revision%s.\n') % (len(remote_extra),
 
241
                plural(len(remote_extra))))
251
242
 
252
243
 
253
244
def _show_missing_revisions_working(working, outfile):
254
245
    """Show missing revisions in working tree."""
255
246
    branch = working.branch
 
247
    basis = working.basis_tree()
256
248
    try:
257
249
        branch_revno, branch_last_revision = branch.last_revision_info()
258
250
    except errors.UnsupportedOperation:
267
259
        missing_count = branch_revno - tree_last_revno
268
260
        outfile.write('\n')
269
261
        outfile.write(('Working tree is out of date: missing %d '
270
 
                       'revision%s.\n') % (missing_count, plural(missing_count)))
 
262
            'revision%s.\n') % (missing_count, plural(missing_count)))
271
263
 
272
264
 
273
265
def _show_working_stats(working, outfile):
282
274
    outfile.write('  %8d added\n' % len(delta.added))
283
275
    outfile.write('  %8d removed\n' % len(delta.removed))
284
276
    outfile.write('  %8d renamed\n' % len(delta.renamed))
285
 
    outfile.write('  %8d copied\n' % len(delta.copied))
286
277
 
287
278
    ignore_cnt = unknown_cnt = 0
288
279
    for path in working.extras():
294
285
    outfile.write('  %8d ignored\n' % ignore_cnt)
295
286
 
296
287
    dir_cnt = 0
 
288
    root_id = working.get_root_id()
297
289
    for path, entry in working.iter_entries_by_dir():
298
 
        if entry.kind == 'directory' and path != '':
 
290
        if entry.kind == 'directory' and entry.file_id != root_id:
299
291
            dir_cnt += 1
300
292
    outfile.write('  %8d versioned %s\n' % (dir_cnt,
301
 
                                            plural(dir_cnt, 'subdirectory', 'subdirectories')))
 
293
        plural(dir_cnt, 'subdirectory', 'subdirectories')))
302
294
 
303
295
 
304
296
def _show_branch_stats(branch, verbose, outfile):
314
306
    if verbose:
315
307
        committers = stats['committers']
316
308
        outfile.write('  %8d committer%s\n' % (committers,
317
 
                                               plural(committers)))
 
309
            plural(committers)))
318
310
    if revno:
319
311
        timestamp, timezone = stats['firstrev']
320
312
        age = int((time.time() - timestamp) / 3600 / 24)
321
313
        outfile.write('  %8d day%s old\n' % (age, plural(age)))
322
314
        outfile.write('   first revision: %s\n' %
323
 
                      osutils.format_date(timestamp, timezone))
 
315
            osutils.format_date(timestamp, timezone))
324
316
        timestamp, timezone = stats['latestrev']
325
317
        outfile.write('  latest revision: %s\n' %
326
 
                      osutils.format_date(timestamp, timezone))
 
318
            osutils.format_date(timestamp, timezone))
327
319
    return stats
328
320
 
329
321
 
332
324
    if repository.make_working_trees():
333
325
        outfile.write('\n')
334
326
        outfile.write('Create working tree for new branches inside '
335
 
                      'the repository.\n')
 
327
            'the repository.\n')
336
328
 
337
329
 
338
330
def _show_repository_stats(repository, stats, outfile):
342
334
        revisions = stats['revisions']
343
335
        f.write('  %8d revision%s\n' % (revisions, plural(revisions)))
344
336
    if 'size' in stats:
345
 
        f.write('  %8d KiB\n' % (stats['size'] / 1024))
 
337
        f.write('  %8d KiB\n' % (stats['size']/1024))
346
338
    for hook in hooks['repository']:
347
339
        hook(repository, stats, f)
348
340
    if f.getvalue() != "":
351
343
        outfile.write(f.getvalue())
352
344
 
353
345
 
354
 
def show_bzrdir_info(a_controldir, verbose=False, outfile=None):
355
 
    """Output to stdout the 'info' for a_controldir."""
 
346
def show_bzrdir_info(a_bzrdir, verbose=False, outfile=None):
 
347
    """Output to stdout the 'info' for a_bzrdir."""
356
348
    if outfile is None:
357
349
        outfile = sys.stdout
358
350
    try:
359
 
        tree = a_controldir.open_workingtree(
 
351
        tree = a_bzrdir.open_workingtree(
360
352
            recommend_upgrade=False)
361
353
    except (NoWorkingTree, NotLocalUrl, NotBranchError):
362
354
        tree = None
363
355
        try:
364
 
            branch = a_controldir.open_branch(name="")
 
356
            branch = a_bzrdir.open_branch(name="")
365
357
        except NotBranchError:
366
358
            branch = None
367
359
            try:
368
 
                repository = a_controldir.open_repository()
 
360
                repository = a_bzrdir.open_repository()
369
361
            except NoRepositoryPresent:
370
362
                lockable = None
371
363
                repository = None
382
374
    if lockable is not None:
383
375
        lockable.lock_read()
384
376
    try:
385
 
        show_component_info(a_controldir, repository, branch, tree, verbose,
 
377
        show_component_info(a_bzrdir, repository, branch, tree, verbose,
386
378
                            outfile)
387
379
    finally:
388
380
        if lockable is not None:
390
382
 
391
383
 
392
384
def show_component_info(control, repository, branch=None, working=None,
393
 
                        verbose=1, outfile=None):
 
385
    verbose=1, outfile=None):
394
386
    """Write info about all bzrdir components to stdout"""
395
387
    if outfile is None:
396
388
        outfile = sys.stdout
403
395
    outfile.write("%s (format: %s)\n" % (layout, format))
404
396
    _show_location_info(
405
397
        gather_location_info(control=control, repository=repository,
406
 
                             branch=branch, working=working),
 
398
            branch=branch, working=working),
407
399
        outfile)
408
400
    if branch is not None:
409
401
        _show_related_info(branch, outfile)
455
447
        extra = []
456
448
        if repository.make_working_trees():
457
449
            extra.append('trees')
458
 
        if len(control.branch_names()) > 0:
 
450
        if len(control.get_branches()) > 0:
459
451
            extra.append('colocated branches')
460
452
        if extra:
461
453
            phrase += ' with ' + " and ".join(extra)
472
464
        if branch is None and tree is not None:
473
465
            phrase = "branchless tree"
474
466
        else:
475
 
            if (tree is not None and tree.controldir.control_url !=
476
 
                    branch.controldir.control_url):
 
467
            if (tree is not None and tree.user_url !=
 
468
                branch.user_url):
477
469
                independence = ''
478
470
                phrase = "Lightweight checkout"
479
471
            elif branch.get_bound_location() is not None:
496
488
 
497
489
    If no matching candidate is found, "unnamed" is returned.
498
490
    """
499
 
    candidates = []
 
491
    candidates  = []
500
492
    if (branch is not None and tree is not None and
501
 
            branch.user_url != tree.user_url):
 
493
        branch.user_url != tree.user_url):
502
494
        branch = None
503
495
        repository = None
504
496
    non_aliases = set(controldir.format_registry.keys())
505
497
    non_aliases.difference_update(controldir.format_registry.aliases())
506
498
    for key in non_aliases:
507
 
        format = controldir.format_registry.make_controldir(key)
 
499
        format = controldir.format_registry.make_bzrdir(key)
508
500
        if isinstance(format, bzrdir.BzrDirMetaFormat1):
509
501
            if (tree and format.workingtree_format !=
510
 
                    tree._format):
 
502
                tree._format):
511
503
                continue
512
504
            if (branch and format.get_branch_format() !=
513
 
                    branch._format):
 
505
                branch._format):
514
506
                continue
515
507
            if (repository and format.repository_format !=
516
 
                    repository._format):
 
508
                repository._format):
517
509
                continue
518
510
        if format.__class__ is not control._format.__class__:
519
511
            continue
522
514
        return 'unnamed'
523
515
    candidates.sort()
524
516
    new_candidates = [c for c in candidates if not
525
 
                      controldir.format_registry.get_info(c).hidden]
 
517
        controldir.format_registry.get_info(c).hidden]
526
518
    if len(new_candidates) > 0:
527
519
        # If there are any non-hidden formats that match, only return those to
528
520
        # avoid listing hidden formats except when only a hidden format will
535
527
    """Hooks for the info command."""
536
528
 
537
529
    def __init__(self):
538
 
        super(InfoHooks, self).__init__("breezy.info", "hooks")
539
 
        self.add_hook(
540
 
            'repository',
 
530
        super(InfoHooks, self).__init__("bzrlib.info", "hooks")
 
531
        self.add_hook('repository',
541
532
            "Invoked when displaying the statistics for a repository. "
542
533
            "repository is called with a statistics dictionary as returned "
543
534
            "by the repository and a file-like object to write to.", (1, 15))