~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Aaron Bentley
  • Date: 2005-11-10 21:41:44 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20051110214144-834e918cd2a88101
Handled status code again

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
"""
5
5
import bzrlib.commands
6
6
import push
7
 
from errors import CommandError
8
 
from patchsource import BzrPatchSource
 
7
import annotate
9
8
from shelf import Shelf
10
9
import sys
11
10
import os.path
12
11
from bzrlib.option import Option
13
12
import bzrlib.branch
14
13
from bzrlib.errors import BzrCommandError
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
 
 
 
14
sys.path.append(os.path.dirname(__file__))
 
15
from reweave_inventory import cmd_fix
23
16
 
24
17
Option.OPTIONS['ignored'] = Option('ignored',
25
18
        help='delete all ignored files.')
30
23
        help='show files to delete instead of deleting them.')
31
24
 
32
25
class cmd_clean_tree(bzrlib.commands.Command):
33
 
    """Remove unwanted files from working tree.  <BZRTOOLS>
 
26
    """Remove unwanted files from working tree.
34
27
    Normally, ignored files are left alone.
35
28
    """
36
29
    takes_options = ['ignored', 'detritus', 'dry-run']
38
31
        from clean_tree import clean_tree
39
32
        clean_tree('.', ignored=ignored, detritus=detritus, dry_run=dry_run)
40
33
 
 
34
Option.OPTIONS['no-collapse'] = Option('no-collapse')
 
35
Option.OPTIONS['no-antialias'] = Option('no-antialias')
 
36
Option.OPTIONS['cluster'] = Option('cluster')
41
37
Option.OPTIONS['merge-branch'] = Option('merge-branch',type=str)
42
38
 
43
39
class cmd_graph_ancestry(bzrlib.commands.Command):
44
 
    """Produce ancestry graphs using dot.  <BZRTOOLS>
 
40
    """Produce ancestry graphs using dot.
45
41
    
46
42
    Output format is detected according to file extension.  Some of the more
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.
 
43
    common output formats are png, gif, svg, ps.  An extension of '.dot' will
 
44
    cause a dot graph file to be produced.
50
45
 
51
46
    Branches are labeled r?, where ? is the revno.  If they have no revno,
52
47
    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".
55
48
    
56
49
    If --merge-branch is specified, the two branches are compared and a merge
57
50
    base is selected.
62
55
    red      OTHER history
63
56
    orange   COMMON history
64
57
    blue     COMMON non-history ancestor
65
 
    green    Merge base (COMMON ancestor farthest from the null revision)
66
 
    dotted   Ghost revision (missing from branch storage)
 
58
    dotted   Missing from branch storage
67
59
 
68
 
    Ancestry is usually collapsed by skipping revisions with a single parent
 
60
    Ancestry is usually collapsed by removing revisions with a single parent
69
61
    and descendant.  The number of skipped revisions is shown on the arrow.
70
62
    This feature can be disabled with --no-collapse.
71
63
 
76
68
    be disabled with --no-antialias.
77
69
    """
78
70
    takes_args = ['branch', 'file']
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.")]
 
71
    takes_options = ['no-collapse', 'no-antialias', 'merge-branch', 'cluster']
85
72
    def run(self, branch, file, no_collapse=False, no_antialias=False,
86
73
        merge_branch=None, cluster=False):
87
74
        import graph
93
80
                                  not no_antialias, merge_branch, ranking)
94
81
 
95
82
class cmd_fetch_ghosts(bzrlib.commands.Command):
96
 
    """Attempt to retrieve ghosts from another branch.  <BZRTOOLS>
 
83
    """Attempt to retrieve ghosts from another branch.
97
84
    If the other branch is not supplied, the last-pulled branch is used.
98
85
    """
99
86
    aliases = ['fetch-missing']
106
93
strip_help="""Strip the smallest prefix containing num leading slashes  from \
107
94
each file name found in the patch file."""
108
95
Option.OPTIONS['strip'] = Option('strip', type=int, help=strip_help)
109
 
Option.OPTIONS['bzrdiff'] = Option('bzrdiff',type=None,
110
 
                                help="""Handle extra bzr tags""")
111
96
class cmd_patch(bzrlib.commands.Command):
112
 
    """Apply a named patch to the current tree.  <BZRTOOLS>
 
97
    """Apply a named patch to the current tree.
113
98
    """
114
99
    takes_args = ['filename?']
115
 
    takes_options = ['strip','bzrdiff']
116
 
    def run(self, filename=None, strip=-1, bzrdiff=0):
 
100
    takes_options = ['strip']
 
101
    def run(self, filename=None, strip=0):
117
102
        from patch import patch
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
 
103
        from bzrlib.branch import Branch
 
104
        b = Branch.open_containing('.')[0]
 
105
        return patch(b, filename, strip)
123
106
 
124
 
        return patch(wt, filename, strip, legacy= not bzrdiff)
125
107
 
126
108
class cmd_shelve(bzrlib.commands.Command):
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.
 
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.
148
115
    """
149
 
 
150
116
    takes_args = ['file*']
151
 
    takes_options = ['message', 'revision',
152
 
            Option('all', help='Shelve all changes without prompting')]
153
 
 
 
117
    takes_options = ['all', 'message', 'revision']
154
118
    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
 
155
124
        if revision is not None and revision:
156
125
            if len(revision) == 1:
157
126
                revision = revision[0]
158
127
            else:
159
 
                raise CommandError("shelve only accepts a single revision "
 
128
                raise BzrCommandError("shelve only accepts a single revision "
160
129
                                  "parameter.")
161
130
 
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)
 
131
        s = Shelf(branchdir)
 
132
        return s.shelve(all, message, revision, file_list)
212
133
 
213
134
 
214
135
class cmd_unshelve(bzrlib.commands.Command):
215
 
    """Restore the most recently shelved changes to current tree.  <BZRTOOLS>
216
 
    See 'shelve' for more information.
 
136
    """Restore previously-shelved changes to the current tree.
 
137
    See also 'shelve'.
217
138
    """
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
 
 
 
139
    def run(self):
 
140
        s = Shelf('.')
 
141
        return s.unshelve()
228
142
 
229
143
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
 
    """
247
144
    def run(self):
248
145
        import shell
249
146
        return shell.run_shell()
250
147
 
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
 
 
 
148
commands = [cmd_shelve, cmd_unshelve, cmd_clean_tree, cmd_graph_ancestry,
 
149
            cmd_fetch_ghosts, cmd_patch, cmd_shell, cmd_fix]
282
150
 
283
151
command_decorators = []
284
152
 
285
 
 
286
153
import bzrlib.builtins
 
154
if not hasattr(bzrlib.builtins, "cmd_annotate"):
 
155
    commands.append(annotate.cmd_annotate)
287
156
if not hasattr(bzrlib.builtins, "cmd_push"):
288
157
    commands.append(push.cmd_push)
289
158
else:
292
161
from errors import NoPyBaz
293
162
try:
294
163
    import baz_import
295
 
    commands.append(baz_import.cmd_baz_import_branch)
296
164
    commands.append(baz_import.cmd_baz_import)
297
165
 
298
166
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=[]):
 
167
    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):
306
172
            print "This command is disabled.  Please install PyBaz."
307
 
 
308
 
 
309
 
    class cmd_baz_import(bzrlib.commands.Command):
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))
 
173
    commands.append(cmd_baz_import)
318
174
 
319
175
 
320
176
if hasattr(bzrlib.commands, 'register_command'):
326
182
 
327
183
 
328
184
def test_suite():
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
 
185
    from doctest import DocTestSuite
 
186
    from unittest import TestSuite, TestLoader
334
187
    import clean_tree
335
 
    import zap
336
 
    import tests.blackbox
337
 
    import tests.shelf_tests
 
188
    import blackbox
 
189
    import shelf_tests
338
190
    result = TestSuite()
339
 
    result.addTest(DocTestSuite(bzrtools, optionflags=ELLIPSIS))
 
191
    result.addTest(DocTestSuite(bzrtools))
340
192
    result.addTest(clean_tree.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())
 
193
    result.addTest(TestLoader().loadTestsFromModule(shelf_tests))
 
194
    result.addTest(blackbox.test_suite())
346
195
    return result