/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/builtins.py

  • Committer: Andrew Bennetts
  • Date: 2011-02-07 04:14:29 UTC
  • mfrom: (5535.4.26 fetch-all-tags-309682)
  • mto: This revision was merged to the branch mainline in revision 5648.
  • Revision ID: andrew.bennetts@canonical.com-20110207041429-3kc1blj34rvvxod9
Merge fetch-all-tags-309682.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
21
21
from bzrlib.lazy_import import lazy_import
22
22
lazy_import(globals(), """
23
23
import cStringIO
24
 
import itertools
25
 
import re
26
24
import sys
27
25
import time
28
26
 
330
328
        if revision_id is None and revision is None:
331
329
            raise errors.BzrCommandError('You must supply either'
332
330
                                         ' --revision or a revision_id')
333
 
        b = WorkingTree.open_containing(directory)[0].branch
 
331
 
 
332
        b = bzrdir.BzrDir.open_containing_tree_or_branch(directory)[1]
334
333
 
335
334
        revisions = b.repository.revisions
336
335
        if revisions is None:
483
482
            d.destroy_workingtree()
484
483
 
485
484
 
 
485
class cmd_repair_workingtree(Command):
 
486
    __doc__ = """Reset the working tree state file.
 
487
 
 
488
    This is not meant to be used normally, but more as a way to recover from
 
489
    filesystem corruption, etc. This rebuilds the working inventory back to a
 
490
    'known good' state. Any new modifications (adding a file, renaming, etc)
 
491
    will be lost, though modified files will still be detected as such.
 
492
 
 
493
    Most users will want something more like "bzr revert" or "bzr update"
 
494
    unless the state file has become corrupted.
 
495
 
 
496
    By default this attempts to recover the current state by looking at the
 
497
    headers of the state file. If the state file is too corrupted to even do
 
498
    that, you can supply --revision to force the state of the tree.
 
499
    """
 
500
 
 
501
    takes_options = ['revision', 'directory',
 
502
        Option('force',
 
503
               help='Reset the tree even if it doesn\'t appear to be'
 
504
                    ' corrupted.'),
 
505
    ]
 
506
    hidden = True
 
507
 
 
508
    def run(self, revision=None, directory='.', force=False):
 
509
        tree, _ = WorkingTree.open_containing(directory)
 
510
        self.add_cleanup(tree.lock_tree_write().unlock)
 
511
        if not force:
 
512
            try:
 
513
                tree.check_state()
 
514
            except errors.BzrError:
 
515
                pass # There seems to be a real error here, so we'll reset
 
516
            else:
 
517
                # Refuse
 
518
                raise errors.BzrCommandError(
 
519
                    'The tree does not appear to be corrupt. You probably'
 
520
                    ' want "bzr revert" instead. Use "--force" if you are'
 
521
                    ' sure you want to reset the working tree.')
 
522
        if revision is None:
 
523
            revision_ids = None
 
524
        else:
 
525
            revision_ids = [r.as_revision_id(tree.branch) for r in revision]
 
526
        try:
 
527
            tree.reset_state(revision_ids)
 
528
        except errors.BzrError, e:
 
529
            if revision_ids is None:
 
530
                extra = (', the header appears corrupt, try passing -r -1'
 
531
                         ' to set the state to the last commit')
 
532
            else:
 
533
                extra = ''
 
534
            raise errors.BzrCommandError('failed to reset the tree state'
 
535
                                         + extra)
 
536
 
 
537
 
486
538
class cmd_revno(Command):
487
539
    __doc__ = """Show current revision number.
488
540
 
1017
1069
            log.show_branch_change(
1018
1070
                branch_to, self.outf, result.old_revno,
1019
1071
                result.old_revid)
 
1072
        if getattr(result, 'tag_conflicts', None):
 
1073
            return 1
 
1074
        else:
 
1075
            return 0
1020
1076
 
1021
1077
 
1022
1078
class cmd_push(Command):
1963
2019
            type=unicode,
1964
2020
            ),
1965
2021
        RegistryOption('format',
 
2022
            short_name='F',
1966
2023
            help='Diff format to use.',
1967
2024
            lazy_registry=('bzrlib.diff', 'format_registry'),
1968
 
            value_switches=False, title='Diff format'),
 
2025
            title='Diff format'),
1969
2026
        ]
1970
2027
    aliases = ['di', 'dif']
1971
2028
    encoding_type = 'exact'
2052
2109
    @display_command
2053
2110
    def run(self, null=False, directory=u'.'):
2054
2111
        tree = WorkingTree.open_containing(directory)[0]
 
2112
        self.add_cleanup(tree.lock_read().unlock)
2055
2113
        td = tree.changes_from(tree.basis_tree())
 
2114
        self.cleanup_now()
2056
2115
        for path, id, kind, text_modified, meta_modified in td.modified:
2057
2116
            if null:
2058
2117
                self.outf.write(path + '\0')
3328
3387
 
3329
3388
 
3330
3389
class cmd_upgrade(Command):
3331
 
    __doc__ = """Upgrade branch storage to current format.
3332
 
 
3333
 
    The check command or bzr developers may sometimes advise you to run
3334
 
    this command. When the default format has changed you may also be warned
3335
 
    during other operations to upgrade.
 
3390
    __doc__ = """Upgrade a repository, branch or working tree to a newer format.
 
3391
 
 
3392
    When the default format has changed after a major new release of
 
3393
    Bazaar, you may be informed during certain operations that you
 
3394
    should upgrade. Upgrading to a newer format may improve performance
 
3395
    or make new features available. It may however limit interoperability
 
3396
    with older repositories or with older versions of Bazaar.
 
3397
 
 
3398
    If you wish to upgrade to a particular format rather than the
 
3399
    current default, that can be specified using the --format option.
 
3400
    As a consequence, you can use the upgrade command this way to
 
3401
    "downgrade" to an earlier format, though some conversions are
 
3402
    a one way process (e.g. changing from the 1.x default to the
 
3403
    2.x default) so downgrading is not always possible.
 
3404
 
 
3405
    A backup.bzr.~#~ directory is created at the start of the conversion
 
3406
    process (where # is a number). By default, this is left there on
 
3407
    completion. If the conversion fails, delete the new .bzr directory
 
3408
    and rename this one back in its place. Use the --clean option to ask
 
3409
    for the backup.bzr directory to be removed on successful conversion.
 
3410
    Alternatively, you can delete it by hand if everything looks good
 
3411
    afterwards.
 
3412
 
 
3413
    If the location given is a shared repository, dependent branches
 
3414
    are also converted provided the repository converts successfully.
 
3415
    If the conversion of a branch fails, remaining branches are still
 
3416
    tried.
 
3417
 
 
3418
    For more information on upgrades, see the Bazaar Upgrade Guide,
 
3419
    http://doc.bazaar.canonical.com/latest/en/upgrade-guide/.
3336
3420
    """
3337
3421
 
3338
 
    _see_also = ['check']
 
3422
    _see_also = ['check', 'reconcile', 'formats']
3339
3423
    takes_args = ['url?']
3340
3424
    takes_options = [
3341
 
                    RegistryOption('format',
3342
 
                        help='Upgrade to a specific format.  See "bzr help'
3343
 
                             ' formats" for details.',
3344
 
                        lazy_registry=('bzrlib.bzrdir', 'format_registry'),
3345
 
                        converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
3346
 
                        value_switches=True, title='Branch format'),
3347
 
                    ]
 
3425
        RegistryOption('format',
 
3426
            help='Upgrade to a specific format.  See "bzr help'
 
3427
                 ' formats" for details.',
 
3428
            lazy_registry=('bzrlib.bzrdir', 'format_registry'),
 
3429
            converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
 
3430
            value_switches=True, title='Branch format'),
 
3431
        Option('clean',
 
3432
            help='Remove the backup.bzr directory if successful.'),
 
3433
        Option('dry-run',
 
3434
            help="Show what would be done, but don't actually do anything."),
 
3435
    ]
3348
3436
 
3349
 
    def run(self, url='.', format=None):
 
3437
    def run(self, url='.', format=None, clean=False, dry_run=False):
3350
3438
        from bzrlib.upgrade import upgrade
3351
 
        upgrade(url, format)
 
3439
        exceptions = upgrade(url, format, clean_up=clean, dry_run=dry_run)
 
3440
        if exceptions:
 
3441
            if len(exceptions) == 1:
 
3442
                # Compatibility with historical behavior
 
3443
                raise exceptions[0]
 
3444
            else:
 
3445
                return 3
3352
3446
 
3353
3447
 
3354
3448
class cmd_whoami(Command):
3390
3484
                self.outf.write(c.username() + '\n')
3391
3485
            return
3392
3486
 
 
3487
        if email:
 
3488
            raise errors.BzrCommandError("--email can only be used to display existing "
 
3489
                                         "identity")
 
3490
 
3393
3491
        # display a warning if an email address isn't included in the given name.
3394
3492
        try:
3395
3493
            _mod_config.extract_email_address(name)
4546
4644
 
4547
4645
    @display_command
4548
4646
    def run(self, verbose=False):
4549
 
        import bzrlib.plugin
4550
 
        from inspect import getdoc
4551
 
        result = []
4552
 
        for name, plugin in bzrlib.plugin.plugins().items():
4553
 
            version = plugin.__version__
4554
 
            if version == 'unknown':
4555
 
                version = ''
4556
 
            name_ver = '%s %s' % (name, version)
4557
 
            d = getdoc(plugin.module)
4558
 
            if d:
4559
 
                doc = d.split('\n')[0]
4560
 
            else:
4561
 
                doc = '(no description)'
4562
 
            result.append((name_ver, doc, plugin.path()))
4563
 
        for name_ver, doc, path in sorted(result):
4564
 
            self.outf.write("%s\n" % name_ver)
4565
 
            self.outf.write("   %s\n" % doc)
4566
 
            if verbose:
4567
 
                self.outf.write("   %s\n" % path)
4568
 
            self.outf.write("\n")
 
4647
        from bzrlib import plugin
 
4648
        self.outf.writelines(
 
4649
            plugin.describe_plugins(show_paths=verbose))
4569
4650
 
4570
4651
 
4571
4652
class cmd_testament(Command):
5447
5528
    takes_options = [
5448
5529
        custom_help('directory',
5449
5530
            help='Branch whose tags should be displayed.'),
5450
 
        RegistryOption.from_kwargs('sort',
 
5531
        RegistryOption('sort',
5451
5532
            'Sort tags by different criteria.', title='Sorting',
5452
 
            natural='Sort numeric substrings as numbers:'
5453
 
                    ' suitable for version numbers. (default)',
5454
 
            alpha='Sort tags lexicographically.',
5455
 
            time='Sort tags chronologically.',
 
5533
            lazy_registry=('bzrlib.tag', 'tag_sort_methods')
5456
5534
            ),
5457
5535
        'show-ids',
5458
5536
        'revision',
5459
5537
    ]
5460
5538
 
5461
5539
    @display_command
5462
 
    def run(self,
5463
 
            directory='.',
5464
 
            sort='natural',
5465
 
            show_ids=False,
5466
 
            revision=None,
5467
 
            ):
 
5540
    def run(self, directory='.', sort=None, show_ids=False, revision=None):
 
5541
        from bzrlib.tag import tag_sort_methods
5468
5542
        branch, relpath = Branch.open_containing(directory)
5469
5543
 
5470
5544
        tags = branch.tags.get_tag_dict().items()
5479
5553
            # only show revisions between revid1 and revid2 (inclusive)
5480
5554
            tags = [(tag, revid) for tag, revid in tags if
5481
5555
                graph.is_between(revid, revid1, revid2)]
5482
 
        if sort == 'natural':
5483
 
            def natural_sort_key(tag):
5484
 
                return [f(s) for f,s in 
5485
 
                        zip(itertools.cycle((unicode.lower,int)),
5486
 
                                            re.split('([0-9]+)', tag[0]))]
5487
 
            tags.sort(key=natural_sort_key)
5488
 
        elif sort == 'alpha':
5489
 
            tags.sort()
5490
 
        elif sort == 'time':
5491
 
            timestamps = {}
5492
 
            for tag, revid in tags:
5493
 
                try:
5494
 
                    revobj = branch.repository.get_revision(revid)
5495
 
                except errors.NoSuchRevision:
5496
 
                    timestamp = sys.maxint # place them at the end
5497
 
                else:
5498
 
                    timestamp = revobj.timestamp
5499
 
                timestamps[revid] = timestamp
5500
 
            tags.sort(key=lambda x: timestamps[x[1]])
 
5556
        if sort is None:
 
5557
            sort = tag_sort_methods.get()
 
5558
        sort(branch, tags)
5501
5559
        if not show_ids:
5502
5560
            # [ (tag, revid), ... ] -> [ (tag, dotted_revno), ... ]
5503
5561
            for index, (tag, revid) in enumerate(tags):