3
Various useful plugins for working with bzr.
7
from errors import CommandError
8
from patchsource import BzrPatchSource
9
from shelf import Shelf
12
from bzrlib.option import Option
14
from bzrlib.errors import BzrCommandError
15
from reweave_inventory import cmd_fix
16
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__),
18
from bzrlib import DEFAULT_IGNORE
21
DEFAULT_IGNORE.append('./.shelf')
22
DEFAULT_IGNORE.append('./.bzr-shelf*')
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.')
33
class cmd_clean_tree(bzrlib.commands.Command):
34
"""Remove unwanted files from working tree.
35
Normally, ignored files are left alone.
37
takes_options = ['ignored', 'detritus', 'dry-run']
38
def run(self, ignored=False, detritus=False, dry_run=False):
39
from clean_tree import clean_tree
40
clean_tree('.', ignored=ignored, detritus=detritus, dry_run=dry_run)
42
Option.OPTIONS['merge-branch'] = Option('merge-branch',type=str)
44
class cmd_graph_ancestry(bzrlib.commands.Command):
45
"""Produce ancestry graphs using dot.
47
Output format is detected according to file extension. Some of the more
48
common output formats are html, png, gif, svg, ps. An extension of '.dot'
49
will cause a dot graph file to be produced. HTML output has mouseovers
50
that show the commit message.
52
Branches are labeled r?, where ? is the revno. If they have no revno,
53
with the last 5 characters of their revision identifier are used instead.
55
The value starting with d is "(maximum) distance from the null revision".
57
If --merge-branch is specified, the two branches are compared and a merge
65
blue COMMON non-history ancestor
66
green Merge base (COMMON ancestor farthest from the null revision)
67
dotted Ghost revision (missing from branch storage)
69
Ancestry is usually collapsed by skipping revisions with a single parent
70
and descendant. The number of skipped revisions is shown on the arrow.
71
This feature can be disabled with --no-collapse.
73
By default, revisions are ordered by distance from root, but they can be
74
clustered instead using --cluster.
76
If available, rsvg is used to antialias PNG and JPEG output, but this can
77
be disabled with --no-antialias.
79
takes_args = ['branch', 'file']
80
takes_options = [Option('no-collapse', help="Do not skip simple nodes"),
81
Option('no-antialias',
82
help="Do not use rsvg to produce antialiased output"),
83
Option('merge-branch', type=str,
84
help="Use this branch to calcuate a merge base"),
85
Option('cluster', help="Use clustered output.")]
86
def run(self, branch, file, no_collapse=False, no_antialias=False,
87
merge_branch=None, cluster=False):
93
graph.write_ancestry_file(branch, file, not no_collapse,
94
not no_antialias, merge_branch, ranking)
96
class cmd_fetch_ghosts(bzrlib.commands.Command):
97
"""Attempt to retrieve ghosts from another branch.
98
If the other branch is not supplied, the last-pulled branch is used.
100
aliases = ['fetch-missing']
101
takes_args = ['branch?']
102
takes_options = [Option('no-fix')]
103
def run(self, branch=None, no_fix=False):
104
from fetch_ghosts import fetch_ghosts
105
fetch_ghosts(branch, no_fix)
107
strip_help="""Strip the smallest prefix containing num leading slashes from \
108
each file name found in the patch file."""
109
Option.OPTIONS['strip'] = Option('strip', type=int, help=strip_help)
110
Option.OPTIONS['bzrdiff'] = Option('bzrdiff',type=None,
111
help="""Handle extra bzr tags""")
112
class cmd_patch(bzrlib.commands.Command):
113
"""Apply a named patch to the current tree.
115
takes_args = ['filename?']
116
takes_options = ['strip','bzrdiff']
117
def run(self, filename=None, strip=-1, bzrdiff=0):
118
from patch import patch
119
from bzrlib.branch import Branch
120
b = Branch.open_containing('.')[0]
122
if bzrdiff: strip = 0
125
return patch(b, filename, strip, legacy= not bzrdiff)
127
class cmd_shelve(bzrlib.commands.Command):
128
"""Temporarily set aside some changes from the current tree.
130
Shelve allows you to temporarily put changes you've made "on the shelf",
131
ie. out of the way, until a later time when you can bring them back from
132
the shelf with the 'unshelve' command.
134
Shelve is intended to help separate several sets of text changes that have
135
been inappropriately mingled. If you just want to get rid of all changes
136
(text and otherwise) and you don't need to restore them later, use revert.
137
If you want to shelve all text changes at once, use shelve --all.
139
By default shelve asks you what you want to shelve, press '?' at the
140
prompt to get help. To shelve everything run shelve --all.
142
You can put multiple items on the shelf, each time you run unshelve the
143
most recently shelved changes will be reinstated.
145
If filenames are specified, only the changes to those files will be
146
shelved, other files will be left untouched.
148
If a revision is specified, changes since that revision will be shelved.
151
takes_args = ['file*']
152
takes_options = ['message', 'revision',
153
Option('all', help='Shelve all changes without prompting')]
155
def run(self, all=False, file_list=None, message=None, revision=None):
156
if revision is not None and revision:
157
if len(revision) == 1:
158
revision = revision[0]
160
raise CommandError("shelve only accepts a single revision "
163
source = BzrPatchSource(revision, file_list)
164
s = Shelf(source.base)
165
s.shelve(source, all, message)
168
class cmd_shelf(bzrlib.commands.Command):
169
"""Perform various operations on your shelved patches. See also shelve.
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.
178
takes_args = ['subcommand', 'args*']
180
def run(self, subcommand, args_list):
183
source = BzrPatchSource()
184
s = Shelf(source.base)
186
if subcommand == 'ls' or subcommand == 'list':
187
self.__check_no_args(args_list, "shelf list takes no arguments!")
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])
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!")
203
print subcommand, args_list
204
print >>sys.stderr, "Unknown shelf subcommand '%s'" % subcommand
206
def __check_one_arg(self, args, msg):
207
if args is None or len(args) != 1:
208
raise CommandError(msg)
210
def __check_no_args(self, args, msg):
212
raise CommandError(msg)
215
class cmd_unshelve(bzrlib.commands.Command):
216
"""Restore the most recently shelved changes to the current tree.
217
See 'shelve' for more information.
220
Option('all', help='Unshelve all changes without prompting'),
221
Option('force', help='Force unshelving even if errors occur'),
223
def run(self, all=False, force=False):
224
source = BzrPatchSource()
225
s = Shelf(source.base)
226
s.unshelve(source, all, force)
230
class cmd_shell(bzrlib.commands.Command):
231
"""Begin an interactive shell tailored for bzr.
232
Bzr commands can be used without typing bzr first, and will be run natively
233
when possible. Tab completion is tailored for bzr. The shell prompt shows
234
the branch nick, revno, and path.
236
If it encounters any moderately complicated shell command, it will punt to
241
bzr bzrtools:287/> status
244
bzr bzrtools:287/> status --[TAB][TAB]
245
--all --help --revision --show-ids
246
bzr bzrtools:287/> status --
250
return shell.run_shell()
252
class cmd_branch_history(bzrlib.commands.Command):
254
Display the revision history with reference to lines of development.
256
Each different committer or branch nick is considered a different line of
257
development. Committers are treated as the same if they have the same
258
name, or if they have the same email address.
260
takes_args = ["branch?"]
261
def run(self, branch=None):
262
from branchhistory import branch_history
263
return branch_history(branch)
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]
269
command_decorators = []
271
command_decorators = []
273
import bzrlib.builtins
274
if not hasattr(bzrlib.builtins, "cmd_push"):
275
commands.append(push.cmd_push)
277
command_decorators.append(push.cmd_push)
279
from errors import NoPyBaz
282
commands.append(baz_import.cmd_baz_import_branch)
283
commands.append(baz_import.cmd_baz_import)
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."
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))
307
if hasattr(bzrlib.commands, 'register_command'):
308
for command in commands:
309
bzrlib.commands.register_command(command)
310
for command in command_decorators:
311
command._original_command = bzrlib.commands.register_command(
317
from bzrlib.tests.TestUtil import TestLoader
319
from doctest import DocTestSuite, ELLIPSIS
320
from unittest import TestSuite
325
result.addTest(DocTestSuite(bzrtools, optionflags=ELLIPSIS))
326
result.addTest(clean_tree.test_suite())
327
result.addTest(DocTestSuite(baz_import))
328
result.addTest(tests.test_suite())
329
result.addTest(TestLoader().loadTestsFromModule(shelf_tests))
330
result.addTest(blackbox.test_suite())