~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Martin Pool
  • Date: 2005-08-25 09:17:19 UTC
  • Revision ID: mbp@sourcefrog.net-20050825091719-b2d7be7bf56bb35a
- fix a few errors in new merge code

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
# would help with validation and shell completion.
28
28
 
29
29
 
30
 
# TODO: Help messages for options.
31
 
 
32
 
# TODO: Define arguments by objects, rather than just using names.
33
 
# Those objects can specify the expected type of the argument, which
34
 
# would help with validation and shell completion.
35
 
 
36
 
 
37
30
import sys
38
31
import os
39
32
 
58
51
        k_unsquished = k
59
52
    if not plugin_cmds.has_key(k_unsquished):
60
53
        plugin_cmds[k_unsquished] = cmd
61
 
        mutter('registered plugin command %s', k_unsquished)      
62
54
    else:
63
55
        log_error('Two plugins defined the same command: %r' % k)
64
56
        log_error('Not loading the one in %r' % sys.modules[cmd.__module__])
200
192
 
201
193
    # first look up this command under the specified name
202
194
    cmds = _get_cmd_dict(plugins_override=plugins_override)
203
 
    mutter("all commands: %r", cmds.keys())
204
195
    try:
205
196
        return cmd, cmds[cmd]
206
197
    except KeyError:
476
467
    takes_options = ['verbose', 'no-recurse']
477
468
    
478
469
    def run(self, file_list, verbose=False, no_recurse=False):
479
 
        from bzrlib.add import smart_add, _PrintAddCallback
480
 
        recurse = not no_recurse
481
 
        smart_add(file_list, verbose, not no_recurse,
482
 
                  callback=_PrintAddCallback)
 
470
        from bzrlib.add import smart_add
 
471
        smart_add(file_list, verbose, not no_recurse)
483
472
 
484
473
 
485
474
 
497
486
            os.mkdir(d)
498
487
            if not b:
499
488
                b = find_branch(d)
500
 
            b.add([d])
501
 
            print 'added', d
 
489
            b.add([d], verbose=True)
502
490
 
503
491
 
504
492
class cmd_relpath(Command):
593
581
        
594
582
        if os.path.isdir(names_list[-1]):
595
583
            # move into existing directory
596
 
            for pair in b.move(rel_names[:-1], rel_names[-1]):
597
 
                print "%s => %s" % pair
 
584
            b.move(rel_names[:-1], rel_names[-1])
598
585
        else:
599
586
            if len(names_list) != 2:
600
587
                raise BzrCommandError('to mv multiple files the destination '
601
588
                                      'must be a versioned directory')
602
 
            for pair in b.move(rel_names[0], rel_names[1]):
603
 
                print "%s => %s" % pair
 
589
            b.move(rel_names[0], rel_names[1])
604
590
            
605
591
    
606
592
 
626
612
        import tempfile
627
613
        from shutil import rmtree
628
614
        import errno
629
 
        from bzrlib.branch import pull_loc
630
615
        
631
616
        br_to = find_branch('.')
632
617
        stored_loc = None
679
664
    aliases = ['get', 'clone']
680
665
 
681
666
    def run(self, from_location, to_location=None, revision=None):
682
 
        from bzrlib.branch import copy_branch, find_cached_branch
683
 
        import tempfile
684
667
        import errno
 
668
        from bzrlib.merge import merge
 
669
        from bzrlib.branch import DivergedBranches, \
 
670
             find_cached_branch, Branch
685
671
        from shutil import rmtree
 
672
        from meta_store import CachedStore
 
673
        import tempfile
686
674
        cache_root = tempfile.mkdtemp()
 
675
 
 
676
        if revision is None:
 
677
            revision = [None]
 
678
        elif len(revision) > 1:
 
679
            raise BzrCommandError('bzr branch --revision takes exactly 1 revision value')
 
680
 
687
681
        try:
688
 
            if revision is None:
689
 
                revision = [None]
690
 
            elif len(revision) > 1:
691
 
                raise BzrCommandError(
692
 
                    'bzr branch --revision takes exactly 1 revision value')
693
682
            try:
694
683
                br_from = find_cached_branch(from_location, cache_root)
695
684
            except OSError, e:
698
687
                                          ' exist.' % to_location)
699
688
                else:
700
689
                    raise
 
690
 
701
691
            if to_location is None:
702
692
                to_location = os.path.basename(from_location.rstrip("/\\"))
 
693
 
703
694
            try:
704
695
                os.mkdir(to_location)
705
696
            except OSError, e:
711
702
                                          to_location)
712
703
                else:
713
704
                    raise
714
 
            try:
715
 
                copy_branch(br_from, to_location, revision[0])
716
 
            except bzrlib.errors.NoSuchRevision:
717
 
                rmtree(to_location)
718
 
                msg = "The branch %s has no revision %d." % (from_location, revision[0])
719
 
                raise BzrCommandError(msg)
 
705
            br_to = Branch(to_location, init=True)
 
706
 
 
707
            br_to.set_root_id(br_from.get_root_id())
 
708
 
 
709
            if revision:
 
710
                if revision[0] is None:
 
711
                    revno = br_from.revno()
 
712
                else:
 
713
                    revno, rev_id = br_from.get_revision_info(revision[0])
 
714
                try:
 
715
                    br_to.update_revisions(br_from, stop_revision=revno)
 
716
                except bzrlib.errors.NoSuchRevision:
 
717
                    rmtree(to_location)
 
718
                    msg = "The branch %s has no revision %d." % (from_location,
 
719
                                                                 revno)
 
720
                    raise BzrCommandError(msg)
 
721
 
 
722
            merge((to_location, -1), (to_location, 0), this_dir=to_location,
 
723
                  check_clean=False, ignore_zero=True)
 
724
            from_location = pull_loc(br_from)
 
725
            br_to.controlfile("x-pull", "wb").write(from_location + "\n")
720
726
        finally:
721
727
            rmtree(cache_root)
722
728
 
723
729
 
 
730
def pull_loc(branch):
 
731
    # TODO: Should perhaps just make attribute be 'base' in
 
732
    # RemoteBranch and Branch?
 
733
    if hasattr(branch, "baseurl"):
 
734
        return branch.baseurl
 
735
    else:
 
736
        return branch.base
 
737
 
 
738
 
 
739
 
724
740
class cmd_renames(Command):
725
741
    """Show list of renamed files.
726
742
 
1357
1373
class cmd_upgrade(Command):
1358
1374
    """Upgrade branch storage to current format.
1359
1375
 
1360
 
    The check command or bzr developers may sometimes advise you to run
1361
 
    this command.
 
1376
    This should normally be used only after the check command tells
 
1377
    you to run it.
1362
1378
    """
1363
1379
    takes_args = ['dir?']
1364
1380
 
1387
1403
class cmd_selftest(Command):
1388
1404
    """Run internal test suite"""
1389
1405
    hidden = True
1390
 
    takes_options = ['verbose', 'pattern']
1391
 
    def run(self, verbose=False, pattern=".*"):
 
1406
    takes_options = ['verbose']
 
1407
    def run(self, verbose=False):
1392
1408
        import bzrlib.ui
1393
1409
        from bzrlib.selftest import selftest
 
1410
 
1394
1411
        # we don't want progress meters from the tests to go to the
1395
1412
        # real output; and we don't want log messages cluttering up
1396
1413
        # the real logs.
 
1414
 
1397
1415
        save_ui = bzrlib.ui.ui_factory
1398
1416
        bzrlib.trace.info('running tests...')
 
1417
        bzrlib.trace.disable_default_logging()
1399
1418
        try:
1400
1419
            bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
1401
 
            result = selftest(verbose=verbose, pattern=pattern)
 
1420
            result = selftest(verbose=verbose)
1402
1421
            if result:
1403
1422
                bzrlib.trace.info('tests passed')
1404
1423
            else:
1405
1424
                bzrlib.trace.info('tests failed')
1406
1425
            return int(not result)
1407
1426
        finally:
 
1427
            bzrlib.trace.enable_default_logging()
1408
1428
            bzrlib.ui.ui_factory = save_ui
1409
1429
 
1410
1430
 
1527
1547
            merge_type = ApplyMerge3
1528
1548
 
1529
1549
        if revision is None or len(revision) < 1:
1530
 
            base = [None, None]
 
1550
            base = (None, None)
1531
1551
            other = (branch, -1)
1532
1552
        else:
1533
1553
            if len(revision) == 1:
1557
1577
 
1558
1578
    def run(self, revision=None, no_backup=False, file_list=None):
1559
1579
        from bzrlib.merge import merge
1560
 
        from bzrlib.branch import Branch
1561
1580
        if file_list is not None:
1562
1581
            if len(file_list) == 0:
1563
1582
                raise BzrCommandError("No files specified")
1570
1589
              ignore_zero=True,
1571
1590
              backup_files=not no_backup,
1572
1591
              file_list=file_list)
1573
 
        if not file_list:
1574
 
            Branch('.').set_pending_merges([])
1575
1592
 
1576
1593
 
1577
1594
class cmd_assert_fail(Command):
1652
1669
        from inspect import getdoc
1653
1670
        from pprint import pprint
1654
1671
        for plugin in bzrlib.plugin.all_plugins:
1655
 
            if hasattr(plugin, '__path__'):
1656
 
                print plugin.__path__[0]
1657
 
            else:
1658
 
                print `plugin`
 
1672
            print plugin.__path__[0]
1659
1673
            d = getdoc(plugin)
1660
1674
            if d:
1661
1675
                print '\t', d.split('\n')[0]
1691
1705
    'root':                   str,
1692
1706
    'no-backup':              None,
1693
1707
    'merge-type':             get_merge_type,
1694
 
    'pattern':                str,
1695
1708
    }
1696
1709
 
1697
1710
SHORT_OPTIONS = {
1960
1973
 
1961
1974
def main(argv):
1962
1975
    import bzrlib.ui
 
1976
    
1963
1977
    bzrlib.trace.log_startup(argv)
 
1978
 
1964
1979
    bzrlib.ui.ui_factory = bzrlib.ui.TextUIFactory()
1965
1980
 
1966
1981
    try: