~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Aaron Bentley
  • Date: 2006-03-16 15:06:54 UTC
  • Revision ID: abentley@panoramicfeedback.com-20060316150654-9eabd1c1d7ea804e
Fixed checkout handling in Shelve

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
1
2
"""\
2
3
Various useful plugins for working with bzr.
3
4
"""
4
 
 
5
 
import bzrlib
6
 
 
7
 
 
8
 
__version__ = '0.11.0'
9
 
 
10
 
 
11
 
version_info = tuple(int(n) for n in __version__.split('.'))
12
 
 
13
 
 
14
 
def check_bzrlib_version(desired):
15
 
    """Check that bzrlib is compatible.
16
 
 
17
 
    If version is < bzrtools version, assume incompatible.
18
 
    If version == bzrtools version, assume completely compatible
19
 
    If version == bzrtools version + 1, assume compatible, with deprecations
20
 
    Otherwise, assume incompatible.
21
 
    """
22
 
    desired_plus = (desired[0], desired[1]+1)
23
 
    bzrlib_version = bzrlib.version_info[:2]
24
 
    if bzrlib_version == desired:
25
 
        return
26
 
    try:
27
 
        from bzrlib.trace import warning
28
 
    except ImportError:
29
 
        # get the message out any way we can
30
 
        from warnings import warn as warning
31
 
    if bzrlib_version < desired:
32
 
        warning('Installed bzr version %s is too old to be used with bzrtools'
33
 
                ' %s.' % (bzrlib.__version__, __version__))
34
 
        # Not using BzrNewError, because it may not exist.
35
 
        raise Exception, ('Version mismatch', version_info)
36
 
    else:
37
 
        warning('Bzrtools is not up to date with installed bzr version %s.'
38
 
                ' \nThere should be a newer version available, e.g. %i.%i.' 
39
 
                % (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
40
 
        if bzrlib_version != desired_plus:
41
 
            raise Exception, 'Version mismatch'
42
 
 
43
 
 
44
 
check_bzrlib_version(version_info[:2])
45
 
 
46
 
 
47
 
import rspush
48
 
from errors import CommandError, NoPyBaz
 
5
import bzrlib.commands
 
6
import push
 
7
from errors import CommandError
49
8
from patchsource import BzrPatchSource
50
9
from shelf import Shelf
51
 
from switch import cmd_switch
52
10
import sys
53
11
import os.path
54
 
 
55
 
import bzrlib.builtins
 
12
from bzrlib.option import Option
56
13
import bzrlib.branch
57
 
import bzrlib.commands
58
 
from bzrlib.commands import get_cmd_object
59
14
from bzrlib.errors import BzrCommandError
60
 
from bzrlib.help import command_usage
61
 
import bzrlib.ignores
62
 
from bzrlib.option import Option
 
15
from reweave_inventory import cmd_fix
63
16
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), 
64
 
                                                 "external")))
65
 
 
66
 
bzrlib.ignores.add_runtime_ignores(['./.shelf'])
67
 
 
 
17
                                                 "external")))
 
18
from bzrlib import DEFAULT_IGNORE
 
19
 
 
20
 
 
21
DEFAULT_IGNORE.append('./.shelf')
 
22
DEFAULT_IGNORE.append('./.bzr-shelf*')
 
23
 
 
24
 
 
25
Option.OPTIONS['ignored'] = Option('ignored',
 
26
        help='delete all ignored files.')
 
27
Option.OPTIONS['detritus'] = Option('detritus',
 
28
        help='delete conflict files merge backups, and failed selftest dirs.' +
 
29
              '(*.THIS, *.BASE, *.OTHER, *~, *.tmp')
 
30
Option.OPTIONS['dry-run'] = Option('dry-run',
 
31
        help='show files to delete instead of deleting them.')
68
32
 
69
33
class cmd_clean_tree(bzrlib.commands.Command):
70
34
    """Remove unwanted files from working tree.
71
 
 
72
 
    By default, only unknown files, not ignored files, are deleted.  Versioned
73
 
    files are never deleted.
74
 
 
75
 
    Another class is 'detritus', which includes files emitted by bzr during
76
 
    normal operations and selftests.  (The value of these files decreases with
77
 
    time.)
78
 
 
79
 
    If no options are specified, unknown files are deleted.  Otherwise, option
80
 
    flags are respected, and may be combined.
81
 
 
82
 
    To check what clean-tree will do, use --dry-run.
 
35
    Normally, ignored files are left alone.
83
36
    """
84
 
    takes_options = [Option('ignored', help='delete all ignored files.'), 
85
 
                     Option('detritus', help='delete conflict files, merge'
86
 
                            ' backups, and failed selftest dirs.'), 
87
 
                     Option('unknown', 
88
 
                            help='delete files unknown to bzr.  (default)'),
89
 
                     Option('dry-run', help='show files to delete instead of'
90
 
                            ' deleting them.')]
91
 
    def run(self, unknown=False, ignored=False, detritus=False, dry_run=False):
 
37
    takes_options = ['ignored', 'detritus', 'dry-run']
 
38
    def run(self, ignored=False, detritus=False, dry_run=False):
92
39
        from clean_tree import clean_tree
93
 
        if not (unknown or ignored or detritus):
94
 
            unknown = True
95
 
        clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus, 
96
 
                   dry_run=dry_run)
 
40
        clean_tree('.', ignored=ignored, detritus=detritus, dry_run=dry_run)
97
41
 
 
42
Option.OPTIONS['merge-branch'] = Option('merge-branch',type=str)
98
43
 
99
44
class cmd_graph_ancestry(bzrlib.commands.Command):
100
45
    """Produce ancestry graphs using dot.
148
93
        graph.write_ancestry_file(branch, file, not no_collapse, 
149
94
                                  not no_antialias, merge_branch, ranking)
150
95
 
151
 
 
152
96
class cmd_fetch_ghosts(bzrlib.commands.Command):
153
97
    """Attempt to retrieve ghosts from another branch.
154
98
    If the other branch is not supplied, the last-pulled branch is used.
162
106
 
163
107
strip_help="""Strip the smallest prefix containing num leading slashes  from \
164
108
each file name found in the patch file."""
 
109
Option.OPTIONS['strip'] = Option('strip', type=int, help=strip_help)
165
110
Option.OPTIONS['bzrdiff'] = Option('bzrdiff',type=None,
166
111
                                help="""Handle extra bzr tags""")
167
 
 
168
 
 
169
112
class cmd_patch(bzrlib.commands.Command):
170
113
    """Apply a named patch to the current tree.
171
114
    """
172
115
    takes_args = ['filename?']
173
 
    takes_options = [Option('strip', type=int, help=strip_help)]
 
116
    takes_options = ['strip','bzrdiff']
174
117
    def run(self, filename=None, strip=-1, bzrdiff=0):
175
118
        from patch import patch
176
 
        from bzrlib.workingtree import WorkingTree
177
 
        wt = WorkingTree.open_containing('.')[0]
 
119
        from bzrlib.branch import Branch
 
120
        b = Branch.open_containing('.')[0]
178
121
        if strip == -1:
179
122
            if bzrdiff: strip = 0
180
 
            else:       strip = 0
181
 
 
182
 
        return patch(wt, filename, strip, legacy= not bzrdiff)
183
 
 
 
123
            else:       strip = 1
 
124
 
 
125
        return patch(b, filename, strip, legacy= not bzrdiff)
184
126
 
185
127
class cmd_shelve(bzrlib.commands.Command):
186
128
    """Temporarily set aside some changes from the current tree.
197
139
    By default shelve asks you what you want to shelve, press '?' at the
198
140
    prompt to get help. To shelve everything run shelve --all.
199
141
 
 
142
    You can put multiple items on the shelf, each time you run unshelve the
 
143
    most recently shelved changes will be reinstated.
 
144
 
200
145
    If filenames are specified, only the changes to those files will be
201
146
    shelved, other files will be left untouched.
202
147
 
203
148
    If a revision is specified, changes since that revision will be shelved.
204
 
 
205
 
    You can put multiple items on the shelf. Normally each time you run
206
 
    unshelve the most recently shelved changes will be reinstated. However,
207
 
    you can also unshelve changes in a different order by explicitly
208
 
    specifiying which changes to unshelve. This works best when the changes
209
 
    don't depend on each other.
210
 
 
211
 
    While you have patches on the shelf you can view and manipulate them with
212
 
    the 'shelf' command. Run 'bzr shelf -h' for more info.
213
149
    """
214
150
 
215
151
    takes_args = ['file*']
216
152
    takes_options = ['message', 'revision',
217
 
            Option('all', help='Shelve all changes without prompting'), 
218
 
            Option('no-color', help='Never display changes in color')]
 
153
            Option('all', help='Shelve all changes without prompting')]
219
154
 
220
 
    def run(self, all=False, file_list=None, message=None, revision=None,
221
 
            no_color=False):
 
155
    def run(self, all=False, file_list=None, message=None, revision=None):
222
156
        if revision is not None and revision:
223
157
            if len(revision) == 1:
224
158
                revision = revision[0]
228
162
 
229
163
        source = BzrPatchSource(revision, file_list)
230
164
        s = Shelf(source.base)
231
 
        s.shelve(source, all, message, no_color)
 
165
        s.shelve(source, all, message)
232
166
        return 0
233
167
 
234
 
 
235
 
# The following classes are only used as subcommands for 'shelf', they're
236
 
# not to be registered directly with bzr.
237
 
 
238
 
class cmd_shelf_list(bzrlib.commands.Command):
239
 
    """List the patches on the current shelf."""
240
 
    aliases = ['list', 'ls']
241
 
    def run(self):
242
 
        self.shelf.list()
243
 
 
244
 
 
245
 
class cmd_shelf_delete(bzrlib.commands.Command):
246
 
    """Delete the patch from the current shelf."""
247
 
    aliases = ['delete', 'del']
248
 
    takes_args = ['patch']
249
 
    def run(self, patch):
250
 
        self.shelf.delete(patch)
251
 
 
252
 
 
253
 
class cmd_shelf_switch(bzrlib.commands.Command):
254
 
    """Switch to the other shelf, create it if necessary."""
255
 
    aliases = ['switch']
256
 
    takes_args = ['othershelf']
257
 
    def run(self, othershelf):
258
 
        s = Shelf(self.shelf.base, othershelf)
259
 
        s.make_default()
260
 
 
261
 
 
262
 
class cmd_shelf_show(bzrlib.commands.Command):
263
 
    """Show the contents of the specified or topmost patch."""
264
 
    aliases = ['show', 'cat', 'display']
265
 
    takes_args = ['patch?']
266
 
    def run(self, patch=None):
267
 
        self.shelf.display(patch)
268
 
 
269
 
 
270
 
class cmd_shelf_upgrade(bzrlib.commands.Command):
271
 
    """Upgrade old format shelves."""
272
 
    aliases = ['upgrade']
273
 
    def run(self):
274
 
        self.shelf.upgrade()
275
 
 
276
 
 
277
168
class cmd_shelf(bzrlib.commands.Command):
278
 
    """Perform various operations on your shelved patches. See also shelve."""
 
169
    """Perform various operations on your shelved patches. See also shelve.
 
170
 
 
171
    Subcommands:
 
172
        list   (ls)           List the patches on the current shelf.
 
173
        delete (del) <patch>  Delete a patch from the current shelf.
 
174
        switch       <shelf>  Switch to the named shelf, create it if necessary.
 
175
        show         <patch>  Show the contents of the specified patch.
 
176
        upgrade               Upgrade old format shelves.
 
177
    """
279
178
    takes_args = ['subcommand', 'args*']
280
179
 
281
 
    subcommands = [cmd_shelf_list, cmd_shelf_delete, cmd_shelf_switch,
282
 
        cmd_shelf_show, cmd_shelf_upgrade]
283
 
 
284
180
    def run(self, subcommand, args_list):
285
181
        import sys
286
182
 
287
 
        cmd = self._get_cmd_object(subcommand)
288
183
        source = BzrPatchSource()
289
184
        s = Shelf(source.base)
290
 
        cmd.shelf = s
291
 
        return cmd.run_argv_aliases(args_list)
292
 
 
293
 
    def _get_cmd_object(self, cmd_name):
294
 
        for cmd_class in self.subcommands:
295
 
            for alias in cmd_class.aliases:
296
 
                if alias == cmd_name:
297
 
                    return cmd_class()
298
 
        raise CommandError("Unknown shelf subcommand '%s'" % cmd_name)
299
 
 
300
 
    def help(self):
301
 
        text = ["%s\n\nSubcommands:\n" % self.__doc__]
302
 
 
303
 
        for cmd_class in self.subcommands:
304
 
            text.extend(self.sub_help(cmd_class) + ['\n'])
305
 
 
306
 
        return ''.join(text)
307
 
 
308
 
    def sub_help(self, cmd_class):
309
 
        text = []
310
 
        cmd_obj = cmd_class()
311
 
        indent = 2 * ' '
312
 
 
313
 
        usage = command_usage(cmd_obj)
314
 
        usage = usage.replace('bzr shelf-', '')
315
 
        text.append('%s%s\n' % (indent, usage))
316
 
 
317
 
        text.append('%s%s\n' % (2 * indent, cmd_class.__doc__))
318
 
 
319
 
        # Somewhat copied from bzrlib.help.help_on_command_options
320
 
        option_help = []
321
 
        for option_name, option in sorted(cmd_obj.options().items()):
322
 
            if option_name == 'help':
323
 
                continue
324
 
            option_help.append('%s--%s' % (3 * indent, option_name))
325
 
            if option.type is not None:
326
 
                option_help.append(' %s' % option.argname.upper())
327
 
            if option.short_name():
328
 
                option_help.append(', -%s' % option.short_name())
329
 
            option_help.append('%s%s\n' % (2 * indent, option.help))
330
 
 
331
 
        if len(option_help) > 0:
332
 
            text.append('%soptions:\n' % (2 * indent))
333
 
            text.extend(option_help)
334
 
 
335
 
        return text
 
185
 
 
186
        if subcommand == 'ls' or subcommand == 'list':
 
187
            self.__check_no_args(args_list, "shelf list takes no arguments!")
 
188
            s.list()
 
189
        elif subcommand == 'delete' or subcommand == 'del':
 
190
            self.__check_one_arg(args_list, "shelf delete takes one argument!")
 
191
            s.delete(args_list[0])
 
192
        elif subcommand == 'switch':
 
193
            self.__check_one_arg(args_list, "shelf switch takes one argument!")
 
194
            s = Shelf(source.base, args_list[0])
 
195
            s.make_default()
 
196
        elif subcommand == 'show':
 
197
            self.__check_one_arg(args_list, "shelf show takes one argument!")
 
198
            s.display(args_list[0])
 
199
        elif subcommand == 'upgrade':
 
200
            self.__check_no_args(args_list, "shelf upgrade takes no arguments!")
 
201
            s.upgrade()
 
202
        else:
 
203
            print subcommand, args_list
 
204
            print >>sys.stderr, "Unknown shelf subcommand '%s'" % subcommand
 
205
 
 
206
    def __check_one_arg(self, args, msg):
 
207
        if args is None or len(args) != 1:
 
208
            raise CommandError(msg)
 
209
 
 
210
    def __check_no_args(self, args, msg):
 
211
        if args is not None:
 
212
            raise CommandError(msg)
336
213
 
337
214
 
338
215
class cmd_unshelve(bzrlib.commands.Command):
339
 
    """Restore shelved changes.
340
 
 
341
 
    By default the most recently shelved changes are restored. However if you
342
 
    specify a patch by name those changes will be restored instead.
343
 
 
 
216
    """Restore the most recently shelved changes to the current tree.
344
217
    See 'shelve' for more information.
345
218
    """
346
219
    takes_options = [
347
220
            Option('all', help='Unshelve all changes without prompting'),
348
221
            Option('force', help='Force unshelving even if errors occur'),
349
 
            Option('no-color', help='Never display changes in color')
350
 
        ]
351
 
    takes_args = ['patch?']
352
 
    def run(self, patch=None, all=False, force=False, no_color=False):
 
222
    ]
 
223
    def run(self, all=False, force=False):
353
224
        source = BzrPatchSource()
354
225
        s = Shelf(source.base)
355
 
        s.unshelve(source, patch, all, force, no_color)
 
226
        s.unshelve(source, all, force)
356
227
        return 0
357
228
 
358
229
 
378
249
        import shell
379
250
        return shell.run_shell()
380
251
 
381
 
 
382
252
class cmd_branch_history(bzrlib.commands.Command):
383
253
    """\
384
 
    Display the development history of a branch.
 
254
    Display the revision history with reference to lines of development.
385
255
 
386
256
    Each different committer or branch nick is considered a different line of
387
257
    development.  Committers are treated as the same if they have the same
392
262
        from branchhistory import branch_history 
393
263
        return branch_history(branch)
394
264
 
395
 
 
396
 
class cmd_zap(bzrlib.commands.Command):
397
 
    """\
398
 
    Remove a lightweight checkout, if it can be done safely.
399
 
 
400
 
    This command will remove a lightweight checkout without losing data.  That
401
 
    means it only removes lightweight checkouts, and only if they have no
402
 
    uncommitted changes.
403
 
 
404
 
    If --branch is specified, the branch will be deleted too, but only if the
405
 
    the branch has no new commits (relative to its parent).
406
 
    """
407
 
    takes_options = [Option("branch", help="Remove associtated branch from"
408
 
                                           " repository")]
409
 
    takes_args = ["checkout"]
410
 
    def run(self, checkout, branch=False):
411
 
        from zap import zap
412
 
        return zap(checkout, remove_branch=branch)
413
 
 
414
 
 
415
 
class cmd_cbranch(bzrlib.commands.Command):
416
 
    """
417
 
    Create a new checkout, associated with a new repository branch.
418
 
    
419
 
    When you cbranch, bzr looks up the repository associated with your current
420
 
    directory in locations.conf.  It creates a new branch in that repository
421
 
    with the same name and relative path as the checkout you request.
422
 
 
423
 
    The locations.conf parameter is "cbranch_root".  So if you want 
424
 
    cbranch operations in /home/jrandom/bigproject to produce branches in 
425
 
    /home/jrandom/bigproject/repository, you'd add this:
426
 
 
427
 
    [/home/jrandom/bigproject]
428
 
    cbranch_root = /home/jrandom/bigproject/repository
429
 
 
430
 
    Note that if "/home/jrandom/bigproject/repository" isn't a repository,
431
 
    standalone branches will be produced.  Standalone branches will also
432
 
    be produced if the source branch is in 0.7 format (or earlier).
433
 
    """
434
 
    takes_options = [Option("lightweight", 
435
 
                            help="Create a lightweight checkout"), 'revision']
436
 
    takes_args = ["source", "target?"]
437
 
    def run(self, source, target=None, lightweight=False, revision=None):
438
 
        from cbranch import cbranch
439
 
        return cbranch(source, target, lightweight=lightweight, 
440
 
                       revision=revision)
441
 
 
442
 
 
443
 
class cmd_branches(bzrlib.commands.Command):
444
 
    """Scan a location for branches"""
445
 
    takes_args = ["location?"]
446
 
    def run(self, location=None):
447
 
        from branches import branches
448
 
        return branches(location)
449
 
 
450
 
 
451
 
class cmd_multi_pull(bzrlib.commands.Command):
452
 
    """Pull all the branches under a location, e.g. a repository.
453
 
    
454
 
    Both branches present in the directory and the branches of checkouts are
455
 
    pulled.
456
 
    """
457
 
    takes_args = ["location?"]
458
 
    def run(self, location=None):
459
 
        from bzrlib.branch import Branch
460
 
        from bzrlib.transport import get_transport
461
 
        from bzrtools import iter_branch_tree
462
 
        if location is None:
463
 
            location = '.'
464
 
        t = get_transport(location)
465
 
        if not t.listable():
466
 
            print "Can't list this type of location."
467
 
            return 3
468
 
        for branch, wt in iter_branch_tree(t):
469
 
            if wt is None:
470
 
                pullable = branch
471
 
            else:
472
 
                pullable = wt
473
 
            parent = branch.get_parent()
474
 
            if parent is None:
475
 
                continue
476
 
            if wt is not None:
477
 
                base = wt.basedir
478
 
            else:
479
 
                base = branch.base
480
 
            if base.startswith(t.base):
481
 
                relpath = base[len(t.base):].rstrip('/')
482
 
            else:
483
 
                relpath = base
484
 
            print "Pulling %s from %s" % (relpath, parent)
485
 
            try:
486
 
                pullable.pull(Branch.open(parent))
487
 
            except Exception, e:
488
 
                print e
489
 
 
490
 
 
491
 
class cmd_branch_mark(bzrlib.commands.Command):
492
 
    """
493
 
    Add, view or list branch markers <EXPERIMENTAL>
494
 
 
495
 
    To add a mark, do 'bzr branch-mark MARK'.
496
 
    To list marks, do 'bzr branch-mark' (this lists all marks for the branch's
497
 
    repository).
498
 
    To delete a mark, do 'bzr branch-mark --delete MARK'
499
 
 
500
 
    These marks can be used to track a branch's status.
501
 
    """
502
 
    takes_args = ['mark?', 'branch?']
503
 
    takes_options = [Option('delete', help='Delete this mark')]
504
 
    def run(self, mark=None, branch=None, delete=False):
505
 
        from branch_mark import branch_mark
506
 
        branch_mark(mark, branch, delete)
507
 
 
508
 
 
509
 
class cmd_import(bzrlib.commands.Command):
510
 
    """Import sources from a tarball
511
 
    
512
 
    This command will import a tarball into a bzr tree, replacing any versioned
513
 
    files already present.  If a directory is specified, it is used as the
514
 
    target.  If the directory does not exist, or is not versioned, it is
515
 
    created.
516
 
 
517
 
    Tarballs may be gzip or bzip2 compressed.  This is autodetected.
518
 
 
519
 
    If the tarball has a single root directory, that directory is stripped
520
 
    when extracting the tarball.
521
 
    """
522
 
    
523
 
    takes_args = ['source', 'tree?']
524
 
    def run(self, source, tree=None):
525
 
        from upstream_import import do_import
526
 
        do_import(source, tree)
527
 
 
528
 
 
529
 
class cmd_cdiff(bzrlib.commands.Command):
530
 
    """A color version of bzr's diff"""
531
 
    takes_args = property(lambda x: get_cmd_object('diff').takes_args)
532
 
    takes_options = property(lambda x: get_cmd_object('diff').takes_options)
533
 
    def run(*args, **kwargs):
534
 
        from colordiff import colordiff
535
 
        colordiff(*args, **kwargs)
536
 
 
537
 
 
538
 
class cmd_baz_import(bzrlib.commands.Command):
539
 
    """Import an Arch or Baz archive into a bzr repository.
540
 
 
541
 
    This command should be used on local archives (or mirrors) only.  It is
542
 
    quite slow on remote archives.
543
 
    
544
 
    reuse_history allows you to specify any previous imports you 
545
 
    have done of different archives, which this archive has branches
546
 
    tagged from. This will dramatically reduce the time to convert 
547
 
    the archive as it will not have to convert the history already
548
 
    converted in that other branch.
549
 
 
550
 
    If you specify prefixes, only branches whose names start with that prefix
551
 
    will be imported.  Skipped branches will be listed, so you can import any
552
 
    branches you missed by accident.  Here's an example of doing a partial
553
 
    import from thelove@canonical.com:
554
 
    bzr baz-import thelove thelove@canonical.com --prefixes dists:talloc-except
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
 
 
560
 
    def run(self, to_root_dir, from_archive, verbose=False,
561
 
            reuse_history_list=[], prefixes=None):
562
 
        from errors import NoPyBaz
563
 
        try:
564
 
            import baz_import
565
 
            baz_import.baz_import(to_root_dir, from_archive,
566
 
                                  verbose, reuse_history_list, prefixes)
567
 
        except NoPyBaz:
568
 
            print "This command is disabled.  Please install PyBaz."
569
 
 
570
 
 
571
 
class cmd_baz_import_branch(bzrlib.commands.Command):
572
 
    """Import an Arch or Baz branch into a bzr branch."""
573
 
    takes_args = ['to_location', 'from_branch?', 'reuse_history*']
574
 
    takes_options = ['verbose', Option('max-count', type=int)]
575
 
 
576
 
    def run(self, to_location, from_branch=None, fast=False, max_count=None,
577
 
            verbose=False, dry_run=False, reuse_history_list=[]):
578
 
        from errors import NoPyBaz
579
 
        try:
580
 
            import baz_import
581
 
            baz_import.baz_import_branch(to_location, from_branch, fast, 
582
 
                                         max_count, verbose, dry_run,
583
 
                                         reuse_history_list)
584
 
        except NoPyBaz:
585
 
            print "This command is disabled.  Please install PyBaz."
586
 
 
587
 
 
588
 
commands = [
589
 
            cmd_baz_import,
590
 
            cmd_baz_import_branch,
591
 
            cmd_branches,
592
 
            cmd_branch_history,
593
 
            cmd_branch_mark,
594
 
            cmd_cbranch,  
595
 
            cmd_cdiff,
596
 
            cmd_clean_tree,
597
 
            cmd_fetch_ghosts,
598
 
            cmd_graph_ancestry,
599
 
            cmd_import,
600
 
            cmd_multi_pull,
601
 
            cmd_patch,
602
 
            cmd_shelf, 
603
 
            cmd_shell,
604
 
            cmd_shelve, 
605
 
            cmd_switch,
606
 
            cmd_unshelve, 
607
 
            cmd_zap,            
608
 
            ]
609
 
 
610
 
commands.append(rspush.cmd_rspush)
 
265
commands = [cmd_shelve, cmd_unshelve, cmd_shelf, cmd_clean_tree,
 
266
            cmd_graph_ancestry, cmd_fetch_ghosts, cmd_patch, cmd_shell,
 
267
            cmd_fix, cmd_branch_history]
 
268
 
 
269
command_decorators = []
 
270
 
 
271
command_decorators = []
 
272
 
 
273
import bzrlib.builtins
 
274
if not hasattr(bzrlib.builtins, "cmd_push"):
 
275
    commands.append(push.cmd_push)
 
276
else:
 
277
    command_decorators.append(push.cmd_push)
 
278
 
 
279
from errors import NoPyBaz
 
280
try:
 
281
    import baz_import
 
282
    commands.append(baz_import.cmd_baz_import_branch)
 
283
    commands.append(baz_import.cmd_baz_import)
 
284
 
 
285
except NoPyBaz:
 
286
    class cmd_baz_import_branch(bzrlib.commands.Command):
 
287
        """Disabled. (Requires PyBaz)"""
 
288
        takes_args = ['to_location?', 'from_branch?', 'reuse_history*']
 
289
        takes_options = ['verbose', Option('max-count', type=int)]
 
290
        def run(self, to_location=None, from_branch=None, fast=False, 
 
291
                max_count=None, verbose=False, dry_run=False,
 
292
                reuse_history_list=[]):
 
293
            print "This command is disabled.  Please install PyBaz."
 
294
 
 
295
 
 
296
    class cmd_baz_import(bzrlib.commands.Command):
 
297
        """Disabled. (Requires PyBaz)"""
 
298
        takes_args = ['to_root_dir?', 'from_archive?', 'reuse_history*']
 
299
        takes_options = ['verbose', Option('prefixes', type=str,
 
300
                         help="Prefixes of branches to import")]
 
301
        def run(self, to_root_dir=None, from_archive=None, verbose=False,
 
302
                reuse_history_list=[], prefixes=None):
 
303
                print "This command is disabled.  Please install PyBaz."
 
304
    commands.extend((cmd_baz_import_branch, cmd_baz_import))
 
305
 
611
306
 
612
307
if hasattr(bzrlib.commands, 'register_command'):
613
308
    for command in commands:
614
309
        bzrlib.commands.register_command(command)
 
310
    for command in command_decorators:
 
311
        command._original_command = bzrlib.commands.register_command(
 
312
            command, True)
615
313
 
616
314
 
617
315
def test_suite():
 
316
    import baz_import
618
317
    from bzrlib.tests.TestUtil import TestLoader
619
318
    import tests
620
319
    from doctest import DocTestSuite, ELLIPSIS
621
320
    from unittest import TestSuite
622
 
    import tests.clean_tree
623
 
    import upstream_import
624
 
    import zap
625
 
    import tests.blackbox
626
 
    import tests.shelf_tests
 
321
    import clean_tree
 
322
    import blackbox
 
323
    import shelf_tests
627
324
    result = TestSuite()
628
325
    result.addTest(DocTestSuite(bzrtools, optionflags=ELLIPSIS))
629
 
    result.addTest(tests.clean_tree.test_suite())
630
 
    try:
631
 
        import baz_import
632
 
        result.addTest(DocTestSuite(baz_import))
633
 
    except NoPyBaz:
634
 
        pass
 
326
    result.addTest(clean_tree.test_suite())
 
327
    result.addTest(DocTestSuite(baz_import))
635
328
    result.addTest(tests.test_suite())
636
 
    result.addTest(TestLoader().loadTestsFromModule(tests.shelf_tests))
637
 
    result.addTest(tests.blackbox.test_suite())
638
 
    result.addTest(upstream_import.test_suite())
639
 
    result.addTest(zap.test_suite())
 
329
    result.addTest(TestLoader().loadTestsFromModule(shelf_tests))
 
330
    result.addTest(blackbox.test_suite())
640
331
    return result