/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: Jelmer Vernooij
  • Date: 2011-01-19 18:40:15 UTC
  • mfrom: (5622 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5624.
  • Revision ID: jelmer@samba.org-20110119184015-ahycpz0yduideif0
merge bzr.dev.

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:
2053
2052
    @display_command
2054
2053
    def run(self, null=False, directory=u'.'):
2055
2054
        tree = WorkingTree.open_containing(directory)[0]
 
2055
        self.add_cleanup(tree.lock_read().unlock)
2056
2056
        td = tree.changes_from(tree.basis_tree())
 
2057
        self.cleanup_now()
2057
2058
        for path, id, kind, text_modified, meta_modified in td.modified:
2058
2059
            if null:
2059
2060
                self.outf.write(path + '\0')
3329
3330
 
3330
3331
 
3331
3332
class cmd_upgrade(Command):
3332
 
    __doc__ = """Upgrade branch storage to current format.
3333
 
 
3334
 
    The check command or bzr developers may sometimes advise you to run
3335
 
    this command. When the default format has changed you may also be warned
3336
 
    during other operations to upgrade.
 
3333
    __doc__ = """Upgrade a repository, branch or working tree to a newer format.
 
3334
 
 
3335
    When the default format has changed after a major new release of
 
3336
    Bazaar, you may be informed during certain operations that you
 
3337
    should upgrade. Upgrading to a newer format may improve performance
 
3338
    or make new features available. It may however limit interoperability
 
3339
    with older repositories or with older versions of Bazaar.
 
3340
 
 
3341
    If you wish to upgrade to a particular format rather than the
 
3342
    current default, that can be specified using the --format option.
 
3343
    As a consequence, you can use the upgrade command this way to
 
3344
    "downgrade" to an earlier format, though some conversions are
 
3345
    a one way process (e.g. changing from the 1.x default to the
 
3346
    2.x default) so downgrading is not always possible.
 
3347
 
 
3348
    A backup.bzr.~#~ directory is created at the start of the conversion
 
3349
    process (where # is a number). By default, this is left there on
 
3350
    completion. If the conversion fails, delete the new .bzr directory
 
3351
    and rename this one back in its place. Use the --clean option to ask
 
3352
    for the backup.bzr directory to be removed on successful conversion.
 
3353
    Alternatively, you can delete it by hand if everything looks good
 
3354
    afterwards.
 
3355
 
 
3356
    If the location given is a shared repository, dependent branches
 
3357
    are also converted provided the repository converts successfully.
 
3358
    If the conversion of a branch fails, remaining branches are still
 
3359
    tried.
 
3360
 
 
3361
    For more information on upgrades, see the Bazaar Upgrade Guide,
 
3362
    http://doc.bazaar.canonical.com/latest/en/upgrade-guide/.
3337
3363
    """
3338
3364
 
3339
 
    _see_also = ['check']
 
3365
    _see_also = ['check', 'reconcile', 'formats']
3340
3366
    takes_args = ['url?']
3341
3367
    takes_options = [
3342
 
                    RegistryOption('format',
3343
 
                        help='Upgrade to a specific format.  See "bzr help'
3344
 
                             ' formats" for details.',
3345
 
                        lazy_registry=('bzrlib.bzrdir', 'format_registry'),
3346
 
                        converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
3347
 
                        value_switches=True, title='Branch format'),
3348
 
                    ]
 
3368
        RegistryOption('format',
 
3369
            help='Upgrade to a specific format.  See "bzr help'
 
3370
                 ' formats" for details.',
 
3371
            lazy_registry=('bzrlib.bzrdir', 'format_registry'),
 
3372
            converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
 
3373
            value_switches=True, title='Branch format'),
 
3374
        Option('clean',
 
3375
            help='Remove the backup.bzr directory if successful.'),
 
3376
        Option('dry-run',
 
3377
            help="Show what would be done, but don't actually do anything."),
 
3378
    ]
3349
3379
 
3350
 
    def run(self, url='.', format=None):
 
3380
    def run(self, url='.', format=None, clean=False, dry_run=False):
3351
3381
        from bzrlib.upgrade import upgrade
3352
 
        upgrade(url, format)
 
3382
        exceptions = upgrade(url, format, clean_up=clean, dry_run=dry_run)
 
3383
        if exceptions:
 
3384
            if len(exceptions) == 1:
 
3385
                # Compatibility with historical behavior
 
3386
                raise exceptions[0]
 
3387
            else:
 
3388
                return 3
3353
3389
 
3354
3390
 
3355
3391
class cmd_whoami(Command):
3391
3427
                self.outf.write(c.username() + '\n')
3392
3428
            return
3393
3429
 
 
3430
        if email:
 
3431
            raise errors.BzrCommandError("--email can only be used to display existing "
 
3432
                                         "identity")
 
3433
 
3394
3434
        # display a warning if an email address isn't included in the given name.
3395
3435
        try:
3396
3436
            _mod_config.extract_email_address(name)
5448
5488
    takes_options = [
5449
5489
        custom_help('directory',
5450
5490
            help='Branch whose tags should be displayed.'),
5451
 
        RegistryOption.from_kwargs('sort',
 
5491
        RegistryOption('sort',
5452
5492
            'Sort tags by different criteria.', title='Sorting',
5453
 
            natural='Sort numeric substrings as numbers:'
5454
 
                    ' suitable for version numbers. (default)',
5455
 
            alpha='Sort tags lexicographically.',
5456
 
            time='Sort tags chronologically.',
 
5493
            lazy_registry=('bzrlib.tag', 'tag_sort_methods')
5457
5494
            ),
5458
5495
        'show-ids',
5459
5496
        'revision',
5460
5497
    ]
5461
5498
 
5462
5499
    @display_command
5463
 
    def run(self,
5464
 
            directory='.',
5465
 
            sort='natural',
5466
 
            show_ids=False,
5467
 
            revision=None,
5468
 
            ):
 
5500
    def run(self, directory='.', sort=None, show_ids=False, revision=None):
 
5501
        from bzrlib.tag import tag_sort_methods
5469
5502
        branch, relpath = Branch.open_containing(directory)
5470
5503
 
5471
5504
        tags = branch.tags.get_tag_dict().items()
5480
5513
            # only show revisions between revid1 and revid2 (inclusive)
5481
5514
            tags = [(tag, revid) for tag, revid in tags if
5482
5515
                graph.is_between(revid, revid1, revid2)]
5483
 
        if sort == 'natural':
5484
 
            def natural_sort_key(tag):
5485
 
                return [f(s) for f,s in 
5486
 
                        zip(itertools.cycle((unicode.lower,int)),
5487
 
                                            re.split('([0-9]+)', tag[0]))]
5488
 
            tags.sort(key=natural_sort_key)
5489
 
        elif sort == 'alpha':
5490
 
            tags.sort()
5491
 
        elif sort == 'time':
5492
 
            timestamps = {}
5493
 
            for tag, revid in tags:
5494
 
                try:
5495
 
                    revobj = branch.repository.get_revision(revid)
5496
 
                except errors.NoSuchRevision:
5497
 
                    timestamp = sys.maxint # place them at the end
5498
 
                else:
5499
 
                    timestamp = revobj.timestamp
5500
 
                timestamps[revid] = timestamp
5501
 
            tags.sort(key=lambda x: timestamps[x[1]])
 
5516
        if sort is None:
 
5517
            sort = tag_sort_methods.get()
 
5518
        sort(branch, tags)
5502
5519
        if not show_ids:
5503
5520
            # [ (tag, revid), ... ] -> [ (tag, dotted_revno), ... ]
5504
5521
            for index, (tag, revid) in enumerate(tags):