~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Aaron Bentley
  • Date: 2007-12-22 02:01:03 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20071222020103-ggjszok7n974e1l2
Update branches, multi-pull to new APIs, create trees

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Aaron Bentley <aaron@aaronbentley.com>
 
1
# Copyright (C) 2005, 2006, 2007 Aaron Bentley <aaron.bentley@utoronto.ca>
2
2
# Copyright (C) 2005, 2006 Canonical Limited.
3
3
# Copyright (C) 2006 Michael Ellerman.
4
4
#
30
30
 
31
31
from version import version_info, __version__
32
32
from command import BzrToolsCommand
33
 
from errors import CommandError
 
33
from errors import CommandError, NoPyBaz
34
34
from patchsource import BzrPatchSource
35
35
import sys
36
36
import os.path
441
441
                            help="Create a lightweight checkout."), 'revision',
442
442
                     Option('files-from', type=unicode,
443
443
                            help='Accelerate checkout using files from this'
444
 
                                 ' tree.'),
445
 
                     Option('hardlink',
446
 
                            help='Hard-link files from source/files-from tree'
447
 
                            ' where posible.')]
 
444
                                 ' tree.')]
448
445
    takes_args = ["source", "target?"]
449
446
    def run(self, source, target=None, lightweight=False, revision=None,
450
 
            files_from=None, hardlink=False):
 
447
            files_from=None):
451
448
        from cbranch import cbranch
452
449
        return cbranch(source, target, lightweight=lightweight,
453
 
                       revision=revision, files_from=files_from,
454
 
                       hardlink=hardlink)
 
450
                       revision=revision, files_from=files_from)
455
451
 
456
452
 
457
453
class cmd_branches(BzrToolsCommand):
547
543
        colordiff(check_style, *args, **kwargs)
548
544
 
549
545
 
 
546
class cmd_baz_import(BzrToolsCommand):
 
547
    """Import an Arch or Baz archive into a bzr repository.
 
548
 
 
549
    This command should be used on local archives (or mirrors) only.  It is
 
550
    quite slow on remote archives.
 
551
 
 
552
    reuse_history allows you to specify any previous imports you
 
553
    have done of different archives, which this archive has branches
 
554
    tagged from. This will dramatically reduce the time to convert
 
555
    the archive as it will not have to convert the history already
 
556
    converted in that other branch.
 
557
 
 
558
    If you specify prefixes, only branches whose names start with that prefix
 
559
    will be imported.  Skipped branches will be listed, so you can import any
 
560
    branches you missed by accident.  Here's an example of doing a partial
 
561
    import from thelove@canonical.com:
 
562
    bzr baz-import thelove thelove@canonical.com --prefixes dists:talloc-except
 
563
 
 
564
    WARNING: Encoding should not be specified unless necessary, because if you
 
565
    specify an encoding, your converted branch will not interoperate with
 
566
    independently-converted branches, unless the other branches were converted
 
567
    with exactly the same encoding.  Any encoding recognized by Python may
 
568
    be specified.  Aliases are not detected, so 'utf_8', 'U8', 'UTF' and 'utf8'
 
569
    are incompatible.
 
570
    """
 
571
    takes_args = ['to_root_dir', 'from_archive', 'reuse_history*']
 
572
    takes_options = ['verbose', Option('prefixes', type=str,
 
573
                     help="Prefixes of branches to import, colon-separated."),
 
574
                     Option('encoding', type=str,
 
575
                     help='Force encoding to specified value.  See WARNING.')]
 
576
 
 
577
    def run(self, to_root_dir, from_archive, encoding=None, verbose=False,
 
578
            reuse_history_list=[], prefixes=None):
 
579
        from errors import NoPyBaz
 
580
        try:
 
581
            import baz_import
 
582
            baz_import.baz_import(to_root_dir, from_archive, encoding,
 
583
                                  verbose, reuse_history_list, prefixes)
 
584
        except NoPyBaz:
 
585
            print "This command is disabled.  Please install PyBaz."
 
586
 
 
587
 
 
588
class cmd_baz_import_branch(BzrToolsCommand):
 
589
    """Import an Arch or Baz branch into a bzr branch.
 
590
 
 
591
    WARNING: Encoding should not be specified unless necessary, because if you
 
592
    specify an encoding, your converted branch will not interoperate with
 
593
    independently-converted branches, unless the other branches were converted
 
594
    with exactly the same encoding.  Any encoding recognized by Python may
 
595
    be specified.  Aliases are not detected, so 'utf_8', 'U8', 'UTF' and 'utf8'
 
596
    are incompatible.
 
597
    """
 
598
    takes_args = ['to_location', 'from_branch?', 'reuse_history*']
 
599
    takes_options = ['verbose', 
 
600
                     Option('max-count', type=int, 
 
601
                     help='Maximim revisions to import at once.'),
 
602
                     Option('encoding', type=str,
 
603
                     help='Force encoding to specified value.  See WARNING.')]
 
604
 
 
605
    def run(self, to_location, from_branch=None, fast=False, max_count=None,
 
606
            encoding=None, verbose=False, dry_run=False,
 
607
            reuse_history_list=[]):
 
608
        from errors import NoPyBaz
 
609
        try:
 
610
            import baz_import
 
611
            baz_import.baz_import_branch(to_location, from_branch, fast,
 
612
                                         max_count, verbose, encoding, dry_run,
 
613
                                         reuse_history_list)
 
614
        except NoPyBaz:
 
615
            print "This command is disabled.  Please install PyBaz."
 
616
 
 
617
 
550
618
class cmd_rspush(BzrToolsCommand):
551
619
    """Upload this branch to another location using rsync.
552
620
 
569
637
                      working_tree=not no_tree)
570
638
 
571
639
 
572
 
class cmd_link_tree(BzrToolsCommand):
573
 
    """Hardlink matching files to another tree.
574
 
 
575
 
    Only files with identical content and execute bit will be linked.
576
 
    """
577
 
    takes_args = ['location']
578
 
 
579
 
    def run(self, location):
580
 
        from bzrlib import workingtree
581
 
        from bzrlib.plugins.bzrtools.link_tree import link_tree
582
 
        target_tree = workingtree.WorkingTree.open_containing(".")[0]
583
 
        source_tree = workingtree.WorkingTree.open(location)
584
 
        target_tree.lock_write()
585
 
        try:
586
 
            source_tree.lock_read()
587
 
            try:
588
 
                link_tree(target_tree, source_tree)
589
 
            finally:
590
 
                source_tree.unlock()
591
 
        finally:
592
 
            target_tree.unlock()
593
 
 
594
 
from heads import cmd_heads
595
640
commands = [
 
641
            cmd_baz_import,
 
642
            cmd_baz_import_branch,
596
643
            cmd_branches,
 
644
            cmd_trees,
597
645
            cmd_branch_history,
598
646
            cmd_cbranch,
599
647
            cmd_cdiff,
600
648
            cmd_clean_tree,
601
649
            cmd_fetch_ghosts,
602
650
            cmd_graph_ancestry,
603
 
            cmd_heads,
604
651
            cmd_import,
605
 
            cmd_link_tree,
606
652
            cmd_multi_pull,
607
653
            cmd_patch,
608
654
            cmd_rspush,
609
655
            cmd_shelf,
610
656
            cmd_shell,
611
657
            cmd_shelve,
612
 
            cmd_trees,
613
658
            cmd_unshelve,
614
659
            cmd_zap,
615
660
            ]
627
672
    from unittest import TestSuite
628
673
    import bzrtools
629
674
    import tests.clean_tree
630
 
    import tests.test_dotgraph
631
675
    import tests.is_clean
632
 
    import tests.test_cbranch
633
 
    import tests.test_link_tree
634
 
    import tests.test_patch
635
676
    import tests.test_rspush
636
677
    import tests.upstream_import
637
678
    import zap
640
681
    result = TestSuite()
641
682
    result.addTest(DocTestSuite(bzrtools, optionflags=ELLIPSIS))
642
683
    result.addTest(tests.clean_tree.test_suite())
 
684
    try:
 
685
        import baz_import
 
686
        result.addTest(DocTestSuite(baz_import))
 
687
    except NoPyBaz:
 
688
        pass
643
689
    result.addTest(tests.test_suite())
644
690
    result.addTest(TestLoader().loadTestsFromModule(tests.shelf_tests))
645
691
    result.addTest(tests.blackbox.test_suite())
646
692
    result.addTest(tests.upstream_import.test_suite())
647
693
    result.addTest(zap.test_suite())
648
 
    result.addTest(TestLoader().loadTestsFromModule(tests.test_dotgraph))
649
694
    result.addTest(TestLoader().loadTestsFromModule(tests.is_clean))
650
 
    result.addTest(TestLoader().loadTestsFromModule(tests.test_link_tree))
651
 
    result.addTest(TestLoader().loadTestsFromModule(tests.test_patch))
652
695
    result.addTest(TestLoader().loadTestsFromModule(tests.test_rspush))
653
 
    result.addTest(TestLoader().loadTestsFromModule(tests.test_cbranch))
654
696
    return result