~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to command_classes.py

  • Committer: Jelmer Vernooij
  • Date: 2011-08-29 17:00:45 UTC
  • mto: This revision was merged to the branch mainline in revision 778.
  • Revision ID: jelmer@samba.org-20110829170045-j1yns6q2e6jb236i
Remove unused imports and fix two imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2005, 2006, 2007 Aaron Bentley <aaron@aaronbentley.com>
2
 
# Copyright (C) 2005, 2006 Canonical Limited.
 
2
# Copyright (C) 2005, 2006, 2011 Canonical Limited.
3
3
# Copyright (C) 2006 Michael Ellerman.
4
4
#
5
5
#    This program is free software; you can redistribute it and/or modify
27
27
from command import BzrToolsCommand
28
28
from errors import CommandError
29
29
from patchsource import BzrPatchSource
30
 
import sys
31
 
import os.path
32
30
 
33
 
import bzrlib.builtins
34
31
import bzrlib.commands
35
32
from bzrlib.branch import Branch
36
 
from bzrlib.bzrdir import BzrDir
37
33
from bzrlib.commands import get_cmd_object
38
34
from bzrlib.errors import BzrCommandError
39
 
import bzrlib.ignores
40
 
from bzrlib.trace import note
41
35
from bzrlib.option import Option, RegistryOption
42
36
 
43
 
from command import BzrToolsCommand
44
 
 
45
37
 
46
38
class cmd_graph_ancestry(BzrToolsCommand):
47
39
    """Produce ancestry graphs using dot.
48
 
    
 
40
 
49
41
    Output format is detected according to file extension.  Some of the more
50
42
    common output formats are html, png, gif, svg, ps.  An extension of '.dot'
51
43
    will cause a dot graph file to be produced.  HTML output has mouseovers
117
109
    takes_options = [Option('no-fix', help="Skip additional synchonization.")]
118
110
    def run(self, branch=None, no_fix=False):
119
111
        from fetch_ghosts import fetch_ghosts
120
 
        fetch_ghosts(branch, no_fix)
 
112
        fetch_ghosts(branch, do_reconcile=not no_fix)
121
113
 
122
114
strip_help="""Strip the smallest prefix containing num leading slashes  from \
123
115
each file name found in the patch file."""
127
119
    """Apply a named patch to the current tree.
128
120
    """
129
121
    takes_args = ['filename?']
130
 
    takes_options = [Option('strip', type=int, help=strip_help),
 
122
    takes_options = [Option('strip', type=int, short_name='p',
 
123
                            help=strip_help),
131
124
                     Option('silent', help='Suppress chatter.')]
132
125
    def run(self, filename=None, strip=None, silent=False):
133
126
        from patch import patch
338
331
    --all        --help       --revision   --show-ids
339
332
    bzr bzrtools:287/> status --
340
333
    """
341
 
    def run(self):
 
334
    takes_options = [
 
335
        Option('directory',
 
336
            help='Branch in which to start the shell, '
 
337
                 'rather than the one containing the working directory.',
 
338
            short_name='d',
 
339
            type=unicode,
 
340
            ),
 
341
        ]
 
342
    def run(self, directory=None):
342
343
        import shell
343
 
        return shell.run_shell()
 
344
        return shell.run_shell(directory)
344
345
 
345
346
 
346
347
class cmd_branch_history(BzrToolsCommand):
367
368
 
368
369
    If --branch is specified, the branch will be deleted too, but only if the
369
370
    the branch has no new commits (relative to its parent).
 
371
 
 
372
    If bzr-pipeline is also installed, the --store option will store changes
 
373
    in the branch before deleting the tree.  To restore the changes, do::
 
374
 
 
375
      bzr checkout --lightweight $BRANCH $CHECKOUT
 
376
      bzr switch-pipe -d $CHECKOUT `bzr nick -d $CHECKOUT`
370
377
    """
371
378
    takes_options = [Option("branch", help="Remove associated branch from"
372
379
                                           " repository."),
373
 
                     Option('force', help='Delete tree even if contents are'
374
 
                     ' modified.')]
 
380
                     RegistryOption('change_policy',
 
381
                                    'How to handle changed files',
 
382
                                    lazy_registry =
 
383
                                    ('bzrlib.plugins.bzrtools.zap',
 
384
                                        'change_policy_registry'),
 
385
                                    value_switches=True,
 
386
                                    enum_switch=False)]
375
387
    takes_args = ["checkout"]
376
 
    def run(self, checkout, branch=False, force=False):
377
 
        from zap import zap
378
 
        return zap(checkout, remove_branch=branch, allow_modified=force)
 
388
    def run(self, checkout, branch=False, change_policy=None):
 
389
        from zap import (
 
390
            change_policy_registry,
 
391
            StoreChanges,
 
392
            zap,
 
393
        )
 
394
        if change_policy is None:
 
395
            change_policy = change_policy_registry.get()
 
396
        if change_policy is StoreChanges:
 
397
            try:
 
398
                import bzrlib.plugins.pipeline
 
399
            except ImportError:
 
400
                raise BzrCommandError('--store requires bzr-pipeline.')
 
401
        return zap(checkout, remove_branch=branch, policy=change_policy)
379
402
 
380
403
 
381
404
class cmd_cbranch(BzrToolsCommand):
514
537
        colordiff(color, check_style, *args, **kwargs)
515
538
 
516
539
 
 
540
class cmd_conflict_diff(BzrToolsCommand):
 
541
 
 
542
    """Compare a conflicted file against BASE."""
 
543
 
 
544
    encoding_type = 'exact'
 
545
    takes_args = ['file*']
 
546
    takes_options = [
 
547
        RegistryOption.from_kwargs('direction', 'Direction of comparison.',
 
548
            value_switches=True, enum_switch=False,
 
549
            other='Compare OTHER against common base.',
 
550
            this='Compare THIS against common base.')]
 
551
 
 
552
    def run(self, file_list, direction='other'):
 
553
        from bzrlib.plugins.bzrtools.colordiff import DiffWriter
 
554
        from conflict_diff import ConflictDiffer
 
555
        dw = DiffWriter(self.outf, check_style=False, color='auto')
 
556
        ConflictDiffer().run(dw, file_list, direction)
 
557
 
 
558
 
517
559
class cmd_rspush(BzrToolsCommand):
518
560
    """Upload this branch to another location using rsync.
519
561
 
557
599
                source_tree.unlock()
558
600
        finally:
559
601
            target_tree.unlock()
 
602
 
 
603
 
 
604
class cmd_create_mirror(BzrToolsCommand):
 
605
    """Create a mirror of another branch.
 
606
 
 
607
    This is similar to `bzr branch`, but copies more settings, including the
 
608
    submit branch and nickname.
 
609
 
 
610
    It sets the public branch and parent of the target to the source location.
 
611
    """
 
612
 
 
613
    takes_args = ['source', 'target']
 
614
 
 
615
    def run(self, source, target):
 
616
        source_branch = Branch.open(source)
 
617
        from bzrlib.plugins.bzrtools.mirror import create_mirror
 
618
        create_mirror(source_branch, target, [])