~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: John Arbash Meinel
  • Date: 2010-08-10 20:03:44 UTC
  • mto: This revision was merged to the branch mainline in revision 5376.
  • Revision ID: john@arbash-meinel.com-20100810200344-6muerwvkafqu7w47
Rework things a bit so the logic can be shared.

It turns out that some of the peak memory is actually during the inventory
to string to bundle translations. So re-use the refcount logic there.
This actually does show a decrease in peak memory.
Specifically 'cd bzr.dev; bzr send ../2.2' drops from 221MB peak to 156MB.

We don't speed anything up (16.5s both ways), but peak memory is quite
a bit better.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
    bzrdir,
33
33
    directory_service,
34
34
    delta,
35
 
    config as _mod_config,
 
35
    config,
36
36
    errors,
37
37
    globbing,
38
38
    hooks,
1354
1354
    If you want to discard your local changes, you can just do a
1355
1355
    'bzr revert' instead of 'bzr commit' after the update.
1356
1356
 
1357
 
    If you want to restore a file that has been removed locally, use
1358
 
    'bzr revert' instead of 'bzr update'.
1359
 
 
1360
1357
    If the tree's branch is bound to a master branch, it will also update
1361
1358
    the branch from the master.
1362
1359
    """
1480
1477
class cmd_remove(Command):
1481
1478
    __doc__ = """Remove files or directories.
1482
1479
 
1483
 
    This makes Bazaar stop tracking changes to the specified files. Bazaar will
1484
 
    delete them if they can easily be recovered using revert otherwise they
1485
 
    will be backed up (adding an extention of the form .~#~). If no options or
1486
 
    parameters are given Bazaar will scan for files that are being tracked by
1487
 
    Bazaar but missing in your tree and stop tracking them for you.
 
1480
    This makes bzr stop tracking changes to the specified files. bzr will delete
 
1481
    them if they can easily be recovered using revert. If no options or
 
1482
    parameters are given bzr will scan for files that are being tracked by bzr
 
1483
    but missing in your tree and stop tracking them for you.
1488
1484
    """
1489
1485
    takes_args = ['file*']
1490
1486
    takes_options = ['verbose',
1492
1488
        RegistryOption.from_kwargs('file-deletion-strategy',
1493
1489
            'The file deletion mode to be used.',
1494
1490
            title='Deletion Strategy', value_switches=True, enum_switch=False,
1495
 
            safe='Backup changed files (default).',
 
1491
            safe='Only delete files if they can be'
 
1492
                 ' safely recovered (default).',
1496
1493
            keep='Delete from bzr but leave the working copy.',
1497
1494
            force='Delete all the specified files, even if they can not be '
1498
1495
                'recovered and even if they are non-empty directories.')]
1595
1592
 
1596
1593
    _see_also = ['check']
1597
1594
    takes_args = ['branch?']
1598
 
    takes_options = [
1599
 
        Option('canonicalize-chks',
1600
 
               help='Make sure CHKs are in canonical form (repairs '
1601
 
                    'bug 522637).',
1602
 
               hidden=True),
1603
 
        ]
1604
1595
 
1605
 
    def run(self, branch=".", canonicalize_chks=False):
 
1596
    def run(self, branch="."):
1606
1597
        from bzrlib.reconcile import reconcile
1607
1598
        dir = bzrdir.BzrDir.open(branch)
1608
 
        reconcile(dir, canonicalize_chks=canonicalize_chks)
 
1599
        reconcile(dir)
1609
1600
 
1610
1601
 
1611
1602
class cmd_revision_history(Command):
1887
1878
        Same as 'bzr diff' but prefix paths with old/ and new/::
1888
1879
 
1889
1880
            bzr diff --prefix old/:new/
1890
 
            
1891
 
        Show the differences using a custom diff program with options::
1892
 
        
1893
 
            bzr diff --using /usr/bin/diff --diff-options -wu
1894
1881
    """
1895
1882
    _see_also = ['status']
1896
1883
    takes_args = ['file*']
1897
1884
    takes_options = [
1898
1885
        Option('diff-options', type=str,
1899
 
               help='Pass these options to the external diff program.'),
 
1886
               help='Pass these options to the diff program.'),
1900
1887
        Option('prefix', type=str,
1901
1888
               short_name='p',
1902
1889
               help='Set prefixes added to old and new filenames, as '
1943
1930
                '--prefix expects two values separated by a colon'
1944
1931
                ' (eg "old/:new/")')
1945
1932
 
 
1933
        if using is not None and diff_options is not None:
 
1934
            raise errors.BzrCommandError(
 
1935
            '--diff-options and --using are mutually exclusive.')
 
1936
 
1946
1937
        if revision and len(revision) > 2:
1947
1938
            raise errors.BzrCommandError('bzr diff --revision takes exactly'
1948
1939
                                         ' one or two revision specifiers')
3325
3316
                try:
3326
3317
                    c = Branch.open_containing(u'.')[0].get_config()
3327
3318
                except errors.NotBranchError:
3328
 
                    c = _mod_config.GlobalConfig()
 
3319
                    c = config.GlobalConfig()
3329
3320
            else:
3330
3321
                c = Branch.open(directory).get_config()
3331
3322
            if email:
3336
3327
 
3337
3328
        # display a warning if an email address isn't included in the given name.
3338
3329
        try:
3339
 
            _mod_config.extract_email_address(name)
 
3330
            config.extract_email_address(name)
3340
3331
        except errors.NoEmailInUsername, e:
3341
3332
            warning('"%s" does not seem to contain an email address.  '
3342
3333
                    'This is allowed, but not recommended.', name)
3348
3339
            else:
3349
3340
                c = Branch.open(directory).get_config()
3350
3341
        else:
3351
 
            c = _mod_config.GlobalConfig()
 
3342
            c = config.GlobalConfig()
3352
3343
        c.set_user_option('email', name)
3353
3344
 
3354
3345
 
3421
3412
                'bzr alias --remove expects an alias to remove.')
3422
3413
        # If alias is not found, print something like:
3423
3414
        # unalias: foo: not found
3424
 
        c = _mod_config.GlobalConfig()
 
3415
        c = config.GlobalConfig()
3425
3416
        c.unset_alias(alias_name)
3426
3417
 
3427
3418
    @display_command
3428
3419
    def print_aliases(self):
3429
3420
        """Print out the defined aliases in a similar format to bash."""
3430
 
        aliases = _mod_config.GlobalConfig().get_aliases()
 
3421
        aliases = config.GlobalConfig().get_aliases()
3431
3422
        for key, value in sorted(aliases.iteritems()):
3432
3423
            self.outf.write('bzr alias %s="%s"\n' % (key, value))
3433
3424
 
3443
3434
 
3444
3435
    def set_alias(self, alias_name, alias_command):
3445
3436
        """Save the alias in the global config."""
3446
 
        c = _mod_config.GlobalConfig()
 
3437
        c = config.GlobalConfig()
3447
3438
        c.set_alias(alias_name, alias_command)
3448
3439
 
3449
3440
 
3484
3475
    If you set BZR_TEST_PDB=1 when running selftest, failing tests will drop
3485
3476
    into a pdb postmortem session.
3486
3477
 
3487
 
    The --coverage=DIRNAME global option produces a report with covered code
3488
 
    indicated.
3489
 
 
3490
3478
    :Examples:
3491
3479
        Run only tests relating to 'ignore'::
3492
3480
 
3576
3564
            randomize=None, exclude=None, strict=False,
3577
3565
            load_list=None, debugflag=None, starting_with=None, subunit=False,
3578
3566
            parallel=None, lsprof_tests=False):
3579
 
        from bzrlib import tests
 
3567
        from bzrlib.tests import selftest
 
3568
 
 
3569
        # Make deprecation warnings visible, unless -Werror is set
 
3570
        symbol_versioning.activate_deprecation_warnings(override=False)
3580
3571
 
3581
3572
        if testspecs_list is not None:
3582
3573
            pattern = '|'.join(testspecs_list)
3623
3614
                          "starting_with": starting_with
3624
3615
                          }
3625
3616
        selftest_kwargs.update(self.additional_selftest_args)
3626
 
 
3627
 
        # Make deprecation warnings visible, unless -Werror is set
3628
 
        cleanup = symbol_versioning.activate_deprecation_warnings(
3629
 
            override=False)
3630
 
        try:
3631
 
            result = tests.selftest(**selftest_kwargs)
3632
 
        finally:
3633
 
            cleanup()
 
3617
        result = selftest(**selftest_kwargs)
3634
3618
        return int(not result)
3635
3619
 
3636
3620
 
4804
4788
            self.outf.write('The above revision(s) will be removed.\n')
4805
4789
 
4806
4790
        if not force:
4807
 
            if not ui.ui_factory.confirm_action(
4808
 
                    'Uncommit these revisions',
4809
 
                    'bzrlib.builtins.uncommit',
4810
 
                    {}):
4811
 
                self.outf.write('Canceled\n')
 
4791
            if not ui.ui_factory.get_boolean('Are you sure'):
 
4792
                self.outf.write('Canceled')
4812
4793
                return 0
4813
4794
 
4814
4795
        mutter('Uncommitting from {%s} to {%s}',
4820
4801
 
4821
4802
 
4822
4803
class cmd_break_lock(Command):
4823
 
    __doc__ = """Break a dead lock.
4824
 
 
4825
 
    This command breaks a lock on a repository, branch, working directory or
4826
 
    config file.
 
4804
    __doc__ = """Break a dead lock on a repository, branch or working directory.
4827
4805
 
4828
4806
    CAUTION: Locks should only be broken when you are sure that the process
4829
4807
    holding the lock has been stopped.
4834
4812
    :Examples:
4835
4813
        bzr break-lock
4836
4814
        bzr break-lock bzr+ssh://example.com/bzr/foo
4837
 
        bzr break-lock --conf ~/.bazaar
4838
4815
    """
4839
 
 
4840
4816
    takes_args = ['location?']
4841
 
    takes_options = [
4842
 
        Option('config',
4843
 
               help='LOCATION is the directory where the config lock is.'),
4844
 
        ]
4845
4817
 
4846
 
    def run(self, location=None, config=False):
 
4818
    def run(self, location=None, show=False):
4847
4819
        if location is None:
4848
4820
            location = u'.'
4849
 
        if config:
4850
 
            conf = _mod_config.LockableConfig(file_name=location)
4851
 
            conf.break_lock()
4852
 
        else:
4853
 
            control, relpath = bzrdir.BzrDir.open_containing(location)
4854
 
            try:
4855
 
                control.break_lock()
4856
 
            except NotImplementedError:
4857
 
                pass
 
4821
        control, relpath = bzrdir.BzrDir.open_containing(location)
 
4822
        try:
 
4823
            control.break_lock()
 
4824
        except NotImplementedError:
 
4825
            pass
4858
4826
 
4859
4827
 
4860
4828
class cmd_wait_until_signalled(Command):
4945
4913
    not part of it.  (Such trees can be produced by "bzr split", but also by
4946
4914
    running "bzr branch" with the target inside a tree.)
4947
4915
 
4948
 
    The result is a combined tree, with the subtree no longer an independent
 
4916
    The result is a combined tree, with the subtree no longer an independant
4949
4917
    part.  This is marked as a merge of the subtree into the containing tree,
4950
4918
    and all history is preserved.
4951
4919
    """