~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Aaron Bentley
  • Date: 2006-03-22 22:18:19 UTC
  • Revision ID: abentley@panoramicfeedback.com-20060322221819-0e627e73d1232926
Added zap command

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
"""
5
5
import bzrlib.commands
6
6
import push
7
 
import annotate
 
7
from errors import CommandError
 
8
from patchsource import BzrPatchSource
8
9
from shelf import Shelf
9
10
import sys
10
11
import os.path
11
12
from bzrlib.option import Option
12
13
import bzrlib.branch
13
14
from bzrlib.errors import BzrCommandError
14
 
sys.path.append(os.path.dirname(__file__))
15
 
from reweave_inventory import cmd_fix
 
15
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), 
 
16
                                                 "external")))
 
17
from bzrlib import DEFAULT_IGNORE
 
18
 
 
19
 
 
20
DEFAULT_IGNORE.append('./.shelf')
 
21
DEFAULT_IGNORE.append('./.bzr-shelf*')
 
22
 
16
23
 
17
24
Option.OPTIONS['ignored'] = Option('ignored',
18
25
        help='delete all ignored files.')
23
30
        help='show files to delete instead of deleting them.')
24
31
 
25
32
class cmd_clean_tree(bzrlib.commands.Command):
26
 
    """Remove unwanted files from working tree.
 
33
    """Remove unwanted files from working tree.  <BZRTOOLS>
27
34
    Normally, ignored files are left alone.
28
35
    """
29
36
    takes_options = ['ignored', 'detritus', 'dry-run']
31
38
        from clean_tree import clean_tree
32
39
        clean_tree('.', ignored=ignored, detritus=detritus, dry_run=dry_run)
33
40
 
34
 
Option.OPTIONS['no-collapse'] = Option('no-collapse')
35
 
Option.OPTIONS['no-antialias'] = Option('no-antialias')
36
 
Option.OPTIONS['cluster'] = Option('cluster')
37
41
Option.OPTIONS['merge-branch'] = Option('merge-branch',type=str)
38
42
 
39
43
class cmd_graph_ancestry(bzrlib.commands.Command):
40
 
    """Produce ancestry graphs using dot.
 
44
    """Produce ancestry graphs using dot.  <BZRTOOLS>
41
45
    
42
46
    Output format is detected according to file extension.  Some of the more
43
 
    common output formats are png, gif, svg, ps.  An extension of '.dot' will
44
 
    cause a dot graph file to be produced.
 
47
    common output formats are html, png, gif, svg, ps.  An extension of '.dot'
 
48
    will cause a dot graph file to be produced.  HTML output has mouseovers
 
49
    that show the commit message.
45
50
 
46
51
    Branches are labeled r?, where ? is the revno.  If they have no revno,
47
52
    with the last 5 characters of their revision identifier are used instead.
 
53
 
 
54
    The value starting with d is "(maximum) distance from the null revision".
48
55
    
49
56
    If --merge-branch is specified, the two branches are compared and a merge
50
57
    base is selected.
55
62
    red      OTHER history
56
63
    orange   COMMON history
57
64
    blue     COMMON non-history ancestor
58
 
    dotted   Missing from branch storage
 
65
    green    Merge base (COMMON ancestor farthest from the null revision)
 
66
    dotted   Ghost revision (missing from branch storage)
59
67
 
60
 
    Ancestry is usually collapsed by removing revisions with a single parent
 
68
    Ancestry is usually collapsed by skipping revisions with a single parent
61
69
    and descendant.  The number of skipped revisions is shown on the arrow.
62
70
    This feature can be disabled with --no-collapse.
63
71
 
68
76
    be disabled with --no-antialias.
69
77
    """
70
78
    takes_args = ['branch', 'file']
71
 
    takes_options = ['no-collapse', 'no-antialias', 'merge-branch', 'cluster']
 
79
    takes_options = [Option('no-collapse', help="Do not skip simple nodes"), 
 
80
                     Option('no-antialias',
 
81
                     help="Do not use rsvg to produce antialiased output"), 
 
82
                     Option('merge-branch', type=str, 
 
83
                     help="Use this branch to calcuate a merge base"), 
 
84
                     Option('cluster', help="Use clustered output.")]
72
85
    def run(self, branch, file, no_collapse=False, no_antialias=False,
73
86
        merge_branch=None, cluster=False):
74
87
        import graph
80
93
                                  not no_antialias, merge_branch, ranking)
81
94
 
82
95
class cmd_fetch_ghosts(bzrlib.commands.Command):
83
 
    """Attempt to retrieve ghosts from another branch.
 
96
    """Attempt to retrieve ghosts from another branch.  <BZRTOOLS>
84
97
    If the other branch is not supplied, the last-pulled branch is used.
85
98
    """
86
99
    aliases = ['fetch-missing']
93
106
strip_help="""Strip the smallest prefix containing num leading slashes  from \
94
107
each file name found in the patch file."""
95
108
Option.OPTIONS['strip'] = Option('strip', type=int, help=strip_help)
 
109
Option.OPTIONS['bzrdiff'] = Option('bzrdiff',type=None,
 
110
                                help="""Handle extra bzr tags""")
96
111
class cmd_patch(bzrlib.commands.Command):
97
 
    """Apply a named patch to the current tree.
 
112
    """Apply a named patch to the current tree.  <BZRTOOLS>
98
113
    """
99
114
    takes_args = ['filename?']
100
 
    takes_options = ['strip']
101
 
    def run(self, filename=None, strip=0):
 
115
    takes_options = ['strip','bzrdiff']
 
116
    def run(self, filename=None, strip=-1, bzrdiff=0):
102
117
        from patch import patch
103
 
        from bzrlib.branch import Branch
104
 
        b = Branch.open_containing('.')[0]
105
 
        return patch(b, filename, strip)
 
118
        from bzrlib.workingtree import WorkingTree
 
119
        wt = WorkingTree.open_containing('.')[0]
 
120
        if strip == -1:
 
121
            if bzrdiff: strip = 0
 
122
            else:       strip = 1
106
123
 
 
124
        return patch(wt, filename, strip, legacy= not bzrdiff)
107
125
 
108
126
class cmd_shelve(bzrlib.commands.Command):
109
 
    """Temporarily remove some changes from the current tree.
110
 
    Use 'unshelve' to restore these changes.
111
 
 
112
 
    If filenames are specified, only changes to those files will be unshelved.
113
 
    If a revision is specified, all changes since that revision will may be
114
 
    unshelved.
 
127
    """Temporarily set aside some changes from the current tree.  <BZRTOOLS>
 
128
 
 
129
    Shelve allows you to temporarily put changes you've made "on the shelf",
 
130
    ie. out of the way, until a later time when you can bring them back from
 
131
    the shelf with the 'unshelve' command.
 
132
 
 
133
    Shelve is intended to help separate several sets of text changes that have
 
134
    been inappropriately mingled.  If you just want to get rid of all changes
 
135
    (text and otherwise) and you don't need to restore them later, use revert.
 
136
    If you want to shelve all text changes at once, use shelve --all.
 
137
 
 
138
    By default shelve asks you what you want to shelve, press '?' at the
 
139
    prompt to get help. To shelve everything run shelve --all.
 
140
 
 
141
    You can put multiple items on the shelf, each time you run unshelve the
 
142
    most recently shelved changes will be reinstated.
 
143
 
 
144
    If filenames are specified, only the changes to those files will be
 
145
    shelved, other files will be left untouched.
 
146
 
 
147
    If a revision is specified, changes since that revision will be shelved.
115
148
    """
 
149
 
116
150
    takes_args = ['file*']
117
 
    takes_options = ['all', 'message', 'revision']
 
151
    takes_options = ['message', 'revision',
 
152
            Option('all', help='Shelve all changes without prompting')]
 
153
 
118
154
    def run(self, all=False, file_list=None, message=None, revision=None):
119
 
        if file_list is not None and len(file_list) > 0:
120
 
            branchdir = file_list[0]
121
 
        else:
122
 
            branchdir = '.'
123
 
 
124
155
        if revision is not None and revision:
125
156
            if len(revision) == 1:
126
157
                revision = revision[0]
127
158
            else:
128
 
                raise BzrCommandError("shelve only accepts a single revision "
 
159
                raise CommandError("shelve only accepts a single revision "
129
160
                                  "parameter.")
130
161
 
131
 
        s = Shelf(branchdir)
132
 
        return s.shelve(all, message, revision, file_list)
 
162
        source = BzrPatchSource(revision, file_list)
 
163
        s = Shelf(source.base)
 
164
        s.shelve(source, all, message)
 
165
        return 0
 
166
 
 
167
class cmd_shelf(bzrlib.commands.Command):
 
168
    """Perform various operations on your shelved patches. See also shelve.
 
169
 
 
170
    Subcommands:
 
171
        list   (ls)           List the patches on the current shelf.
 
172
        delete (del) <patch>  Delete a patch from the current shelf.
 
173
        switch       <shelf>  Switch to the named shelf, create it if necessary.
 
174
        show         <patch>  Show the contents of the specified patch.
 
175
        upgrade               Upgrade old format shelves.
 
176
    """
 
177
    takes_args = ['subcommand', 'args*']
 
178
 
 
179
    def run(self, subcommand, args_list):
 
180
        import sys
 
181
 
 
182
        source = BzrPatchSource()
 
183
        s = Shelf(source.base)
 
184
 
 
185
        if subcommand == 'ls' or subcommand == 'list':
 
186
            self.__check_no_args(args_list, "shelf list takes no arguments!")
 
187
            s.list()
 
188
        elif subcommand == 'delete' or subcommand == 'del':
 
189
            self.__check_one_arg(args_list, "shelf delete takes one argument!")
 
190
            s.delete(args_list[0])
 
191
        elif subcommand == 'switch':
 
192
            self.__check_one_arg(args_list, "shelf switch takes one argument!")
 
193
            s = Shelf(source.base, args_list[0])
 
194
            s.make_default()
 
195
        elif subcommand == 'show':
 
196
            self.__check_one_arg(args_list, "shelf show takes one argument!")
 
197
            s.display(args_list[0])
 
198
        elif subcommand == 'upgrade':
 
199
            self.__check_no_args(args_list, "shelf upgrade takes no arguments!")
 
200
            s.upgrade()
 
201
        else:
 
202
            print subcommand, args_list
 
203
            print >>sys.stderr, "Unknown shelf subcommand '%s'" % subcommand
 
204
 
 
205
    def __check_one_arg(self, args, msg):
 
206
        if args is None or len(args) != 1:
 
207
            raise CommandError(msg)
 
208
 
 
209
    def __check_no_args(self, args, msg):
 
210
        if args is not None:
 
211
            raise CommandError(msg)
133
212
 
134
213
 
135
214
class cmd_unshelve(bzrlib.commands.Command):
136
 
    """Restore previously-shelved changes to the current tree.
137
 
    See also 'shelve'.
 
215
    """Restore the most recently shelved changes to current tree.  <BZRTOOLS>
 
216
    See 'shelve' for more information.
138
217
    """
139
 
    def run(self):
140
 
        s = Shelf('.')
141
 
        return s.unshelve()
 
218
    takes_options = [
 
219
            Option('all', help='Unshelve all changes without prompting'),
 
220
            Option('force', help='Force unshelving even if errors occur'),
 
221
    ]
 
222
    def run(self, all=False, force=False):
 
223
        source = BzrPatchSource()
 
224
        s = Shelf(source.base)
 
225
        s.unshelve(source, all, force)
 
226
        return 0
 
227
 
142
228
 
143
229
class cmd_shell(bzrlib.commands.Command):
 
230
    """Begin an interactive shell tailored for bzr.  <BZRTOOLS>
 
231
    Bzr commands can be used without typing bzr first, and will be run natively
 
232
    when possible.  Tab completion is tailored for bzr.  The shell prompt shows
 
233
    the branch nick, revno, and path.
 
234
 
 
235
    If it encounters any moderately complicated shell command, it will punt to
 
236
    the system shell.
 
237
 
 
238
    Example:
 
239
    $ bzr shell
 
240
    bzr bzrtools:287/> status
 
241
    modified:
 
242
      __init__.py
 
243
    bzr bzrtools:287/> status --[TAB][TAB]
 
244
    --all        --help       --revision   --show-ids
 
245
    bzr bzrtools:287/> status --
 
246
    """
144
247
    def run(self):
145
248
        import shell
146
249
        return shell.run_shell()
147
250
 
148
 
commands = [cmd_shelve, cmd_unshelve, cmd_clean_tree, cmd_graph_ancestry,
149
 
            cmd_fetch_ghosts, cmd_patch, cmd_shell, cmd_fix]
 
251
class cmd_branch_history(bzrlib.commands.Command):
 
252
    """\
 
253
    Display the development history of a branch  <BZRTOOLS>.
 
254
 
 
255
    Each different committer or branch nick is considered a different line of
 
256
    development.  Committers are treated as the same if they have the same
 
257
    name, or if they have the same email address.
 
258
    """
 
259
    takes_args = ["branch?"]
 
260
    def run(self, branch=None):
 
261
        from branchhistory import branch_history 
 
262
        return branch_history(branch)
 
263
 
 
264
 
 
265
class cmd_zap(bzrlib.commands.Command):
 
266
    """\
 
267
    Remove a checkout, if it can be done safely. <BZRTOOLS>
 
268
 
 
269
    This command will remove a checkout without losing data.  That means
 
270
    it only removes checkouts, 
 
271
    """
 
272
    takes_args = ["checkout"]
 
273
    def run(self, checkout):
 
274
        from zap import zap
 
275
        return zap(checkout)
 
276
 
 
277
 
 
278
commands = [cmd_shelve, cmd_unshelve, cmd_shelf, cmd_clean_tree,
 
279
            cmd_graph_ancestry, cmd_fetch_ghosts, cmd_patch, cmd_shell,
 
280
            cmd_branch_history, cmd_zap]
 
281
 
150
282
 
151
283
command_decorators = []
152
284
 
 
285
 
153
286
import bzrlib.builtins
154
 
if not hasattr(bzrlib.builtins, "cmd_annotate"):
155
 
    commands.append(annotate.cmd_annotate)
156
287
if not hasattr(bzrlib.builtins, "cmd_push"):
157
288
    commands.append(push.cmd_push)
158
289
else:
161
292
from errors import NoPyBaz
162
293
try:
163
294
    import baz_import
 
295
    commands.append(baz_import.cmd_baz_import_branch)
164
296
    commands.append(baz_import.cmd_baz_import)
165
297
 
166
298
except NoPyBaz:
 
299
    class cmd_baz_import_branch(bzrlib.commands.Command):
 
300
        """Disabled. (Requires PyBaz)   <BZRTOOLS>"""
 
301
        takes_args = ['to_location?', 'from_branch?', 'reuse_history*']
 
302
        takes_options = ['verbose', Option('max-count', type=int)]
 
303
        def run(self, to_location=None, from_branch=None, fast=False, 
 
304
                max_count=None, verbose=False, dry_run=False,
 
305
                reuse_history_list=[]):
 
306
            print "This command is disabled.  Please install PyBaz."
 
307
 
 
308
 
167
309
    class cmd_baz_import(bzrlib.commands.Command):
168
 
        """Disabled. (Requires PyBaz)"""
169
 
        takes_args = ['to_root_dir?', 'from_archive?']
170
 
        takes_options = ['verbose']
171
 
        def run(self, to_root_dir=None, from_archive=None, verbose=False):
172
 
            print "This command is disabled.  Please install PyBaz."
173
 
    commands.append(cmd_baz_import)
 
310
        """Disabled. (Requires PyBaz)   <BZRTOOLS>"""
 
311
        takes_args = ['to_root_dir?', 'from_archive?', 'reuse_history*']
 
312
        takes_options = ['verbose', Option('prefixes', type=str,
 
313
                         help="Prefixes of branches to import")]
 
314
        def run(self, to_root_dir=None, from_archive=None, verbose=False,
 
315
                reuse_history_list=[], prefixes=None):
 
316
                print "This command is disabled.  Please install PyBaz."
 
317
    commands.extend((cmd_baz_import_branch, cmd_baz_import))
174
318
 
175
319
 
176
320
if hasattr(bzrlib.commands, 'register_command'):
182
326
 
183
327
 
184
328
def test_suite():
185
 
    from doctest import DocTestSuite
186
 
    from unittest import TestSuite, TestLoader
 
329
    import baz_import
 
330
    from bzrlib.tests.TestUtil import TestLoader
 
331
    import tests
 
332
    from doctest import DocTestSuite, ELLIPSIS
 
333
    from unittest import TestSuite
187
334
    import clean_tree
188
 
    import blackbox
189
 
    import shelf_tests
 
335
    import zap
 
336
    import tests.blackbox
 
337
    import tests.shelf_tests
190
338
    result = TestSuite()
191
 
    result.addTest(DocTestSuite(bzrtools))
 
339
    result.addTest(DocTestSuite(bzrtools, optionflags=ELLIPSIS))
192
340
    result.addTest(clean_tree.test_suite())
193
 
    result.addTest(TestLoader().loadTestsFromModule(shelf_tests))
194
 
    result.addTest(blackbox.test_suite())
 
341
    result.addTest(DocTestSuite(baz_import))
 
342
    result.addTest(tests.test_suite())
 
343
    result.addTest(TestLoader().loadTestsFromModule(tests.shelf_tests))
 
344
    result.addTest(tests.blackbox.test_suite())
 
345
    result.addTest(zap.test_suite())
195
346
    return result