~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Michael Ellerman
  • Date: 2005-11-29 01:41:52 UTC
  • mto: (0.3.1 shelf-dev) (325.1.2 bzrtools)
  • mto: This revision was merged to the branch mainline in revision 334.
  • Revision ID: michael@ellerman.id.au-20051129014152-f5ede8888bcebc48
HunkSelector was broken if you did a "done" followed by "status/invert" etc.
Fixup to make pychecker happy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
 
"""\
3
 
Various useful plugins for working with bzr.
4
 
"""
 
2
"""Shelf - temporarily set aside changes, then bring them back."""
 
3
 
5
4
import bzrlib.commands
6
 
import push
7
 
import annotate
8
 
from shelf import Shelf
9
 
import sys
10
 
import os.path
11
 
from bzrlib.option import Option
12
5
import bzrlib.branch
13
6
from bzrlib.errors import BzrCommandError
14
 
sys.path.append(os.path.dirname(__file__))
15
 
from reweave_inventory import cmd_fix
16
 
 
17
 
Option.OPTIONS['ignored'] = Option('ignored',
18
 
        help='delete all ignored files.')
19
 
Option.OPTIONS['detritus'] = Option('detritus',
20
 
        help='delete conflict files merge backups, and failed selftest dirs.' +
21
 
              '(*.THIS, *.BASE, *.OTHER, *~, *.tmp')
22
 
Option.OPTIONS['dry-run'] = Option('dry-run',
23
 
        help='show files to delete instead of deleting them.')
24
 
 
25
 
class cmd_clean_tree(bzrlib.commands.Command):
26
 
    """Remove unwanted files from working tree.
27
 
    Normally, ignored files are left alone.
28
 
    """
29
 
    takes_options = ['ignored', 'detritus', 'dry-run']
30
 
    def run(self, ignored=False, detritus=False, dry_run=False):
31
 
        from clean_tree import clean_tree
32
 
        clean_tree('.', ignored=ignored, detritus=detritus, dry_run=dry_run)
33
 
 
34
 
Option.OPTIONS['merge-branch'] = Option('merge-branch',type=str)
35
 
 
36
 
class cmd_graph_ancestry(bzrlib.commands.Command):
37
 
    """Produce ancestry graphs using dot.
38
 
    
39
 
    Output format is detected according to file extension.  Some of the more
40
 
    common output formats are html, png, gif, svg, ps.  An extension of '.dot'
41
 
    will cause a dot graph file to be produced.  HTML output has mouseovers
42
 
    that show the commit message.
43
 
 
44
 
    Branches are labeled r?, where ? is the revno.  If they have no revno,
45
 
    with the last 5 characters of their revision identifier are used instead.
46
 
 
47
 
    The value starting with d is "(maximum) distance from the null revision".
48
 
    
49
 
    If --merge-branch is specified, the two branches are compared and a merge
50
 
    base is selected.
51
 
    
52
 
    Legend:
53
 
    white    normal revision
54
 
    yellow   THIS  history
55
 
    red      OTHER history
56
 
    orange   COMMON history
57
 
    blue     COMMON non-history ancestor
58
 
    green    Merge base (COMMON ancestor farthest from the null revision)
59
 
    dotted   Ghost revision (missing from branch storage)
60
 
 
61
 
    Ancestry is usually collapsed by skipping revisions with a single parent
62
 
    and descendant.  The number of skipped revisions is shown on the arrow.
63
 
    This feature can be disabled with --no-collapse.
64
 
 
65
 
    By default, revisions are ordered by distance from root, but they can be
66
 
    clustered instead using --cluster.
67
 
 
68
 
    If available, rsvg is used to antialias PNG and JPEG output, but this can
69
 
    be disabled with --no-antialias.
70
 
    """
71
 
    takes_args = ['branch', 'file']
72
 
    takes_options = [Option('no-collapse', help="Do not skip simple nodes"), 
73
 
                     Option('no-antialias',
74
 
                     help="Do not use rsvg to produce antialiased output"), 
75
 
                     Option('merge-branch', type=str, 
76
 
                     help="Use this branch to calcuate a merge base"), 
77
 
                     Option('cluster', help="Use clustered output.")]
78
 
    def run(self, branch, file, no_collapse=False, no_antialias=False,
79
 
        merge_branch=None, cluster=False):
80
 
        import graph
81
 
        if cluster:
82
 
            ranking = "cluster"
83
 
        else:
84
 
            ranking = "forced"
85
 
        graph.write_ancestry_file(branch, file, not no_collapse, 
86
 
                                  not no_antialias, merge_branch, ranking)
87
 
 
88
 
class cmd_fetch_ghosts(bzrlib.commands.Command):
89
 
    """Attempt to retrieve ghosts from another branch.
90
 
    If the other branch is not supplied, the last-pulled branch is used.
91
 
    """
92
 
    aliases = ['fetch-missing']
93
 
    takes_args = ['branch?']
94
 
    takes_options = [Option('no-fix')]
95
 
    def run(self, branch=None, no_fix=False):
96
 
        from fetch_ghosts import fetch_ghosts
97
 
        fetch_ghosts(branch, no_fix)
98
 
 
99
 
strip_help="""Strip the smallest prefix containing num leading slashes  from \
100
 
each file name found in the patch file."""
101
 
Option.OPTIONS['strip'] = Option('strip', type=int, help=strip_help)
102
 
class cmd_patch(bzrlib.commands.Command):
103
 
    """Apply a named patch to the current tree.
104
 
    """
105
 
    takes_args = ['filename?']
106
 
    takes_options = ['strip']
107
 
    def run(self, filename=None, strip=0):
108
 
        from patch import patch
109
 
        from bzrlib.branch import Branch
110
 
        b = Branch.open_containing('.')[0]
111
 
        return patch(b, filename, strip)
112
 
 
 
7
from bzrlib.option import Option
 
8
from shelf import Shelf
113
9
 
114
10
class cmd_shelve(bzrlib.commands.Command):
115
 
    """Temporarily remove some text changes from the current tree.
116
 
    Use 'unshelve' to restore these changes.
117
 
 
118
 
    Shelve is intended to help separate several sets of text changes that have
119
 
    been inappropriately mingled.  If you just want to get rid of all changes
120
 
    (text and otherwise) and you don't need to restore them later, use revert.
121
 
    If you want to shelve all text changes at once, use shelve --all.
122
 
 
123
 
    If filenames are specified, only changes to those files will be shelved.
124
 
    If a revision is specified, all changes since that revision will may be
125
 
    shelved.
 
11
    """Temporarily set aside some changes to the current working tree.
 
12
 
 
13
    Shelve allows you to temporarily put changes you've made "on the shelf",
 
14
    ie. out of the way, until a later time when you can bring them back from
 
15
    the shelf with the 'unshelve' command.
 
16
 
 
17
    You can put multiple items on the shelf, each time you run unshelve the
 
18
    most recently shelved changes will be reinstated.
 
19
 
 
20
    If filenames are specified, only the changes to those files will be
 
21
    shelved, other files will be left untouched.
 
22
 
 
23
    If a revision is specified, changes since that revision will be shelved.
 
24
 
 
25
    If you specifiy "--pick" you'll be prompted for each hunk of the diff as
 
26
    to whether you want to shelve it or not. Press "?" at the prompt for help.
126
27
    """
127
28
    takes_args = ['file*']
128
 
    takes_options = [Option('all', 
129
 
                            help='Shelve all changes without prompting'), 
130
 
                     'message', 'revision']
131
 
    def run(self, all=False, file_list=None, message=None, revision=None):
 
29
    takes_options = [Option('pick'), 'message', 'revision']
 
30
    def run(self, pick=False, file_list=None, message=None, revision=None):
132
31
        if file_list is not None and len(file_list) > 0:
133
32
            branchdir = file_list[0]
134
33
        else:
142
41
                                  "parameter.")
143
42
 
144
43
        s = Shelf(branchdir)
145
 
        return s.shelve(all, message, revision, file_list)
146
 
 
 
44
        return s.shelve(pick, message, revision, file_list)
147
45
 
148
46
class cmd_unshelve(bzrlib.commands.Command):
149
 
    """Restore previously-shelved changes to the current tree.
150
 
    See also 'shelve'.
 
47
    """Reinstate the most recently shelved changes.
 
48
    See 'shelve' for more information.
151
49
    """
152
 
    def run(self):
 
50
    takes_options = [Option('pick')]
 
51
    def run(self, pick=False):
153
52
        s = Shelf('.')
154
 
        return s.unshelve()
155
 
 
156
 
class cmd_shell(bzrlib.commands.Command):
157
 
    """Begin an interactive shell tailored for bzr.
158
 
    Bzr commands can be used without typing bzr first, and will be run natively
159
 
    when possible.  Tab completion is tailored for bzr.  The shell prompt shows
160
 
    the branch nick, revno, and path.
161
 
 
162
 
    If it encounters any moderately complicated shell command, it will punt to
163
 
    the system shell.
164
 
 
165
 
    Example:
166
 
    $ bzr shell
167
 
    bzr bzrtools:287/> status
168
 
    modified:
169
 
      __init__.py
170
 
    bzr bzrtools:287/> status --[TAB][TAB]
171
 
    --all        --help       --revision   --show-ids
172
 
    bzr bzrtools:287/> status --
173
 
    """
174
 
    def run(self):
175
 
        import shell
176
 
        return shell.run_shell()
177
 
 
178
 
class cmd_branch_history(bzrlib.commands.Command):
179
 
    """\
180
 
    Display the revision history with reference to lines of development.
181
 
 
182
 
    Each different committer or branch nick is considered a different line of
183
 
    development.  Committers are treated as the same if they have the same
184
 
    name, or if they have the same email address.
185
 
    """
186
 
    takes_args = ["branch?"]
187
 
    def run(self, branch=None):
188
 
        from branchhistory import branch_history 
189
 
        return branch_history(branch)
190
 
 
191
 
commands = [cmd_shelve, cmd_unshelve, cmd_clean_tree, cmd_graph_ancestry,
192
 
            cmd_fetch_ghosts, cmd_patch, cmd_shell, cmd_fix, cmd_branch_history]
193
 
 
194
 
command_decorators = []
195
 
 
196
 
import bzrlib.builtins
197
 
if not hasattr(bzrlib.builtins, "cmd_annotate"):
198
 
    commands.append(annotate.cmd_annotate)
199
 
if not hasattr(bzrlib.builtins, "cmd_push"):
200
 
    commands.append(push.cmd_push)
201
 
else:
202
 
    command_decorators.append(push.cmd_push)
203
 
 
204
 
from errors import NoPyBaz
205
 
try:
206
 
    import baz_import
207
 
    commands.append(baz_import.cmd_baz_import)
208
 
 
209
 
except NoPyBaz:
210
 
    class cmd_baz_import(bzrlib.commands.Command):
211
 
        """Disabled. (Requires PyBaz)"""
212
 
        takes_args = ['to_root_dir?', 'from_archive?']
213
 
        takes_options = ['verbose']
214
 
        def run(self, to_root_dir=None, from_archive=None, verbose=False):
215
 
            print "This command is disabled.  Please install PyBaz."
216
 
    commands.append(cmd_baz_import)
217
 
 
218
 
 
219
 
if hasattr(bzrlib.commands, 'register_command'):
220
 
    for command in commands:
221
 
        bzrlib.commands.register_command(command)
222
 
    for command in command_decorators:
223
 
        command._original_command = bzrlib.commands.register_command(
224
 
            command, True)
225
 
 
 
53
        return s.unshelve(pick)
 
54
 
 
55
bzrlib.commands.register_command(cmd_shelve)
 
56
bzrlib.commands.register_command(cmd_unshelve)
226
57
 
227
58
def test_suite():
228
 
    from doctest import DocTestSuite
229
 
    from unittest import TestSuite, TestLoader
230
 
    import clean_tree
231
 
    import blackbox
232
 
    import shelf_tests
233
 
    result = TestSuite()
234
 
    result.addTest(DocTestSuite(bzrtools))
235
 
    result.addTest(clean_tree.test_suite())
236
 
    result.addTest(TestLoader().loadTestsFromModule(shelf_tests))
237
 
    result.addTest(blackbox.test_suite())
238
 
    return result
 
59
    from bzrlib.tests.TestUtil import TestLoader
 
60
    import tests
 
61
    return TestLoader().loadTestsFromModule(tests)