~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to command_classes.py

  • Committer: Aaron Bentley
  • Date: 2008-11-03 18:37:43 UTC
  • Revision ID: aaron@aaronbentley.com-20081103183743-tvsatmk9v3a108o0
More release updates

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Aaron Bentley <aaron.bentley@utoronto.ca>
 
1
# Copyright (C) 2005, 2006, 2007 Aaron Bentley <aaron@aaronbentley.com>
2
2
# Copyright (C) 2005, 2006 Canonical Limited.
3
3
# Copyright (C) 2006 Michael Ellerman.
4
4
#
16
16
#    along with this program; if not, write to the Free Software
17
17
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
 
19
 
"""\
20
 
Various useful plugins for working with bzr.
21
 
"""
22
 
 
23
19
import bzrlib
24
20
 
25
21
from bzrlib.lazy_import import lazy_import
28
24
import shelf
29
25
""")
30
26
 
31
 
from version import version_info, __version__
32
27
from command import BzrToolsCommand
33
 
from errors import CommandError, NoPyBaz
 
28
from errors import CommandError
34
29
from patchsource import BzrPatchSource
35
30
import sys
36
31
import os.path
44
39
import bzrlib.ignores
45
40
from bzrlib.trace import note
46
41
from bzrlib.option import Option
47
 
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__),
48
 
                                                 "external")))
49
42
 
50
 
import show_paths
51
43
from command import BzrToolsCommand
52
44
 
53
45
bzrlib.ignores.add_runtime_ignores(['./.shelf'])
74
66
                     Option('unknown',
75
67
                            help='Delete files unknown to bzr (default).'),
76
68
                     Option('dry-run', help='Show files to delete instead of'
77
 
                            ' deleting them.')]
78
 
    def run(self, unknown=False, ignored=False, detritus=False, dry_run=False):
 
69
                            ' deleting them.'),
 
70
                     Option('force', help='Do not prompt before deleting.')]
 
71
    def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
 
72
            force=False):
79
73
        from clean_tree import clean_tree
80
74
        if not (unknown or ignored or detritus):
81
75
            unknown = True
 
76
        if dry_run:
 
77
            force = True
82
78
        clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus, 
83
 
                   dry_run=dry_run)
 
79
                   dry_run=dry_run, no_prompt=force)
84
80
 
85
81
 
86
82
class cmd_graph_ancestry(BzrToolsCommand):
178
174
        return patch(wt, filename, strip, silent)
179
175
 
180
176
 
181
 
class cmd_shelve(BzrToolsCommand):
 
177
class cmd_shelve1(BzrToolsCommand):
182
178
    """Temporarily set aside some changes from the current tree.
183
179
 
184
180
    Shelve allows you to temporarily put changes you've made "on the shelf",
185
181
    ie. out of the way, until a later time when you can bring them back from
186
 
    the shelf with the 'unshelve' command.
 
182
    the shelf with the 'unshelve1' command.
187
183
 
188
184
    Shelve is intended to help separate several sets of text changes that have
189
185
    been inappropriately mingled.  If you just want to get rid of all changes
190
186
    (text and otherwise) and you don't need to restore them later, use revert.
191
 
    If you want to shelve all text changes at once, use shelve --all.
 
187
    If you want to shelve all text changes at once, use shelve1 --all.
192
188
 
193
 
    By default shelve asks you what you want to shelve, press '?' at the
194
 
    prompt to get help. To shelve everything run shelve --all.
 
189
    By default shelve1 asks you what you want to shelve, press '?' at the
 
190
    prompt to get help. To shelve everything run shelve1 --all.
195
191
 
196
192
    If filenames are specified, only the changes to those files will be
197
193
    shelved, other files will be left untouched.
199
195
    If a revision is specified, changes since that revision will be shelved.
200
196
 
201
197
    You can put multiple items on the shelf. Normally each time you run
202
 
    unshelve the most recently shelved changes will be reinstated. However,
 
198
    unshelve1 the most recently shelved changes will be reinstated. However,
203
199
    you can also unshelve changes in a different order by explicitly
204
 
    specifiying which changes to unshelve. This works best when the changes
 
200
    specifiying which changes to unshelve1. This works best when the changes
205
201
    don't depend on each other.
206
202
 
207
203
    While you have patches on the shelf you can view and manipulate them with
208
204
    the 'shelf' command. Run 'bzr shelf -h' for more info.
209
205
    """
210
206
 
 
207
    aliases = ['shelve']
211
208
    takes_args = ['file*']
212
209
    takes_options = [Option('message',
213
210
            help='A message to associate with the shelved changes.',
274
271
 
275
272
 
276
273
class cmd_shelf(BzrToolsCommand):
277
 
    """Perform various operations on your shelved patches. See also shelve."""
 
274
    """Perform various operations on your shelved patches. See also shelve1."""
278
275
    takes_args = ['subcommand', 'args*']
279
276
 
280
277
    subcommands = [cmd_shelf_list, cmd_shelf_delete, cmd_shelf_switch,
339
336
        return text
340
337
 
341
338
 
342
 
class cmd_unshelve(BzrToolsCommand):
 
339
class cmd_unshelve1(BzrToolsCommand):
343
340
    """Restore shelved changes.
344
341
 
345
342
    By default the most recently shelved changes are restored. However if you
346
343
    specify a patch by name those changes will be restored instead.
347
344
 
348
 
    See 'shelve' for more information.
 
345
    See 'shelve1' for more information.
349
346
    """
 
347
    aliases = ['unshelve']
350
348
    takes_options = [
351
349
            Option('all', help='Unshelve all changes without prompting.'),
352
350
            Option('force', help='Force unshelving even if errors occur.'),
438
436
    deprecated.
439
437
    """
440
438
    takes_options = [Option("lightweight",
441
 
                            help="Create a lightweight checkout."), 'revision']
 
439
                            help="Create a lightweight checkout."), 'revision',
 
440
                     Option('files-from', type=unicode,
 
441
                            help='Accelerate checkout using files from this'
 
442
                                 ' tree.'),
 
443
                     Option('hardlink',
 
444
                            help='Hard-link files from source/files-from tree'
 
445
                            ' where posible.')]
442
446
    takes_args = ["source", "target?"]
443
 
    def run(self, source, target=None, lightweight=False, revision=None):
 
447
    def run(self, source, target=None, lightweight=False, revision=None,
 
448
            files_from=None, hardlink=False):
444
449
        from cbranch import cbranch
445
450
        return cbranch(source, target, lightweight=lightweight,
446
 
                       revision=revision)
 
451
                       revision=revision, files_from=files_from,
 
452
                       hardlink=hardlink)
447
453
 
448
454
 
449
455
class cmd_branches(BzrToolsCommand):
453
459
        from branches import branches
454
460
        return branches(location)
455
461
 
 
462
class cmd_trees(BzrToolsCommand):
 
463
    """Scan a location for trees"""
 
464
    takes_args = ['location?']
 
465
    def run(self, location='.'):
 
466
        from bzrlib.workingtree import WorkingTree
 
467
        from bzrlib.transport import get_transport
 
468
        t = get_transport(location)
 
469
        for tree in WorkingTree.find_trees(location):
 
470
            self.outf.write('%s\n' % t.relpath(
 
471
                tree.bzrdir.root_transport.base))
456
472
 
457
473
class cmd_multi_pull(BzrToolsCommand):
458
474
    """Pull all the branches under a location, e.g. a repository.
495
511
                print e
496
512
 
497
513
 
 
514
 
498
515
class cmd_import(BzrToolsCommand):
499
516
    """Import sources from a directory, tarball or zip file
500
517
 
528
545
        colordiff(check_style, *args, **kwargs)
529
546
 
530
547
 
531
 
class cmd_baz_import(BzrToolsCommand):
532
 
    """Import an Arch or Baz archive into a bzr repository.
533
 
 
534
 
    This command should be used on local archives (or mirrors) only.  It is
535
 
    quite slow on remote archives.
536
 
 
537
 
    reuse_history allows you to specify any previous imports you
538
 
    have done of different archives, which this archive has branches
539
 
    tagged from. This will dramatically reduce the time to convert
540
 
    the archive as it will not have to convert the history already
541
 
    converted in that other branch.
542
 
 
543
 
    If you specify prefixes, only branches whose names start with that prefix
544
 
    will be imported.  Skipped branches will be listed, so you can import any
545
 
    branches you missed by accident.  Here's an example of doing a partial
546
 
    import from thelove@canonical.com:
547
 
    bzr baz-import thelove thelove@canonical.com --prefixes dists:talloc-except
548
 
 
549
 
    WARNING: Encoding should not be specified unless necessary, because if you
550
 
    specify an encoding, your converted branch will not interoperate with
551
 
    independently-converted branches, unless the other branches were converted
552
 
    with exactly the same encoding.  Any encoding recognized by Python may
553
 
    be specified.  Aliases are not detected, so 'utf_8', 'U8', 'UTF' and 'utf8'
554
 
    are incompatible.
555
 
    """
556
 
    takes_args = ['to_root_dir', 'from_archive', 'reuse_history*']
557
 
    takes_options = ['verbose', Option('prefixes', type=str,
558
 
                     help="Prefixes of branches to import, colon-separated."),
559
 
                     Option('encoding', type=str,
560
 
                     help='Force encoding to specified value.  See WARNING.')]
561
 
 
562
 
    def run(self, to_root_dir, from_archive, encoding=None, verbose=False,
563
 
            reuse_history_list=[], prefixes=None):
564
 
        from errors import NoPyBaz
565
 
        try:
566
 
            import baz_import
567
 
            baz_import.baz_import(to_root_dir, from_archive, encoding,
568
 
                                  verbose, reuse_history_list, prefixes)
569
 
        except NoPyBaz:
570
 
            print "This command is disabled.  Please install PyBaz."
571
 
 
572
 
 
573
 
class cmd_baz_import_branch(BzrToolsCommand):
574
 
    """Import an Arch or Baz branch into a bzr branch.
575
 
 
576
 
    WARNING: Encoding should not be specified unless necessary, because if you
577
 
    specify an encoding, your converted branch will not interoperate with
578
 
    independently-converted branches, unless the other branches were converted
579
 
    with exactly the same encoding.  Any encoding recognized by Python may
580
 
    be specified.  Aliases are not detected, so 'utf_8', 'U8', 'UTF' and 'utf8'
581
 
    are incompatible.
582
 
    """
583
 
    takes_args = ['to_location', 'from_branch?', 'reuse_history*']
584
 
    takes_options = ['verbose', 
585
 
                     Option('max-count', type=int, 
586
 
                     help='Maximim revisions to import at once.'),
587
 
                     Option('encoding', type=str,
588
 
                     help='Force encoding to specified value.  See WARNING.')]
589
 
 
590
 
    def run(self, to_location, from_branch=None, fast=False, max_count=None,
591
 
            encoding=None, verbose=False, dry_run=False,
592
 
            reuse_history_list=[]):
593
 
        from errors import NoPyBaz
594
 
        try:
595
 
            import baz_import
596
 
            baz_import.baz_import_branch(to_location, from_branch, fast,
597
 
                                         max_count, verbose, encoding, dry_run,
598
 
                                         reuse_history_list)
599
 
        except NoPyBaz:
600
 
            print "This command is disabled.  Please install PyBaz."
601
 
 
602
 
 
603
548
class cmd_rspush(BzrToolsCommand):
604
549
    """Upload this branch to another location using rsync.
605
550
 
622
567
                      working_tree=not no_tree)
623
568
 
624
569
 
 
570
class cmd_link_tree(BzrToolsCommand):
 
571
    """Hardlink matching files to another tree.
 
572
 
 
573
    Only files with identical content and execute bit will be linked.
 
574
    """
 
575
    takes_args = ['location']
 
576
 
 
577
    def run(self, location):
 
578
        from bzrlib import workingtree
 
579
        from bzrlib.plugins.bzrtools.link_tree import link_tree
 
580
        target_tree = workingtree.WorkingTree.open_containing(".")[0]
 
581
        source_tree = workingtree.WorkingTree.open(location)
 
582
        target_tree.lock_write()
 
583
        try:
 
584
            source_tree.lock_read()
 
585
            try:
 
586
                link_tree(target_tree, source_tree)
 
587
            finally:
 
588
                source_tree.unlock()
 
589
        finally:
 
590
            target_tree.unlock()
 
591
 
 
592
from heads import cmd_heads
625
593
commands = [
626
 
            cmd_baz_import,
627
 
            cmd_baz_import_branch,
628
594
            cmd_branches,
629
595
            cmd_branch_history,
630
596
            cmd_cbranch,
632
598
            cmd_clean_tree,
633
599
            cmd_fetch_ghosts,
634
600
            cmd_graph_ancestry,
 
601
            cmd_heads,
635
602
            cmd_import,
 
603
            cmd_link_tree,
636
604
            cmd_multi_pull,
637
605
            cmd_patch,
638
606
            cmd_rspush,
639
607
            cmd_shelf,
640
608
            cmd_shell,
641
 
            cmd_shelve,
642
 
            cmd_unshelve,
 
609
            cmd_shelve1,
 
610
            cmd_trees,
 
611
            cmd_unshelve1,
643
612
            cmd_zap,
644
613
            ]
645
614
 
646
 
 
647
 
if hasattr(bzrlib.commands, 'register_command'):
648
 
    for command in commands:
649
 
        bzrlib.commands.register_command(command)
650
 
 
651
 
 
652
 
def test_suite():
653
 
    from bzrlib.tests.TestUtil import TestLoader
654
 
    import tests
655
 
    from doctest import DocTestSuite, ELLIPSIS
656
 
    from unittest import TestSuite
657
 
    import bzrtools
658
 
    import tests.clean_tree
659
 
    import tests.is_clean
660
 
    import tests.test_rspush
661
 
    import tests.upstream_import
662
 
    import zap
663
 
    import tests.blackbox
664
 
    import tests.shelf_tests
665
 
    result = TestSuite()
666
 
    result.addTest(DocTestSuite(bzrtools, optionflags=ELLIPSIS))
667
 
    result.addTest(tests.clean_tree.test_suite())
668
 
    try:
669
 
        import baz_import
670
 
        result.addTest(DocTestSuite(baz_import))
671
 
    except NoPyBaz:
672
 
        pass
673
 
    result.addTest(tests.test_suite())
674
 
    result.addTest(TestLoader().loadTestsFromModule(tests.shelf_tests))
675
 
    result.addTest(tests.blackbox.test_suite())
676
 
    result.addTest(tests.upstream_import.test_suite())
677
 
    result.addTest(zap.test_suite())
678
 
    result.addTest(TestLoader().loadTestsFromModule(tests.is_clean))
679
 
    result.addTest(TestLoader().loadTestsFromModule(tests.test_rspush))
680
 
    return result