~abentley/bzrtools/bzrtools.dev

612 by Aaron Bentley
Update email address
1
# Copyright (C) 2005, 2006, 2007 Aaron Bentley <aaron@aaronbentley.com>
460 by Aaron Bentley
Add encoding parameter everywhere
2
# Copyright (C) 2005, 2006 Canonical Limited.
3
# Copyright (C) 2006 Michael Ellerman.
4
#
5
#    This program is free software; you can redistribute it and/or modify
6
#    it under the terms of the GNU General Public License as published by
7
#    the Free Software Foundation; either version 2 of the License, or
8
#    (at your option) any later version.
9
#
10
#    This program is distributed in the hope that it will be useful,
11
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
#    GNU General Public License for more details.
14
#
15
#    You should have received a copy of the GNU General Public License
16
#    along with this program; if not, write to the Free Software
17
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
428 by Aaron Bentley
Add version number, check against bzrlib version
19
import bzrlib
20
512 by Aaron Bentley
More import-time fixups
21
from bzrlib.lazy_import import lazy_import
22
lazy_import(globals(), """
577.1.1 by Aaron Bentley
bzr switch works when the source branch is renamed
23
from bzrlib import help, urlutils
512 by Aaron Bentley
More import-time fixups
24
import shelf
25
""")
428 by Aaron Bentley
Add version number, check against bzrlib version
26
568 by Aaron Bentley
Don't check version when running non-bzrtools commands
27
from command import BzrToolsCommand
650 by Aaron Bentley
Remove references to PyBaz
28
from errors import CommandError
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
29
from patchsource import BzrPatchSource
246 by Aaron Bentley
Merged shelf_v2
30
import sys
31
import os.path
399 by Aaron Bentley
Implement cdiff (based on old Fai code)
32
33
import bzrlib.builtins
34
import bzrlib.commands
577.1.1 by Aaron Bentley
bzr switch works when the source branch is renamed
35
from bzrlib.branch import Branch
36
from bzrlib.bzrdir import BzrDir
410 by Aaron Bentley
Ensure the option settings come from the right 'diff' in colordiff
37
from bzrlib.commands import get_cmd_object
0.1.39 by Michael Ellerman
Fix shelve and unshelve to pass location to Shelf().
38
from bzrlib.errors import BzrCommandError
423 by Aaron Bentley
Add runtime ignores for shelf
39
import bzrlib.ignores
577.1.1 by Aaron Bentley
bzr switch works when the source branch is renamed
40
from bzrlib.trace import note
680.1.3 by Benoît Pierre
Add --color=MODE option to cdiff; MODE can be:
41
from bzrlib.option import Option, RegistryOption
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
42
568 by Aaron Bentley
Don't check version when running non-bzrtools commands
43
from command import BzrToolsCommand
465 by Aaron Bentley
Add show-paths command from Alexander Belchenko
44
246 by Aaron Bentley
Merged shelf_v2
45
568 by Aaron Bentley
Don't check version when running non-bzrtools commands
46
class cmd_clean_tree(BzrToolsCommand):
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
47
    """Remove unwanted files from working tree.
417 by Aaron Bentley
Update clean-tree docs
48
49
    By default, only unknown files, not ignored files, are deleted.  Versioned
50
    files are never deleted.
51
52
    Another class is 'detritus', which includes files emitted by bzr during
53
    normal operations and selftests.  (The value of these files decreases with
54
    time.)
55
56
    If no options are specified, unknown files are deleted.  Otherwise, option
57
    flags are respected, and may be combined.
58
59
    To check what clean-tree will do, use --dry-run.
246 by Aaron Bentley
Merged shelf_v2
60
    """
553.1.1 by Vincent Ladeuil
Fix option help strings to comply with the style guide.
61
    takes_options = [Option('ignored', help='Delete all ignored files.'),
62
                     Option('detritus', help='Delete conflict files, merge'
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
63
                            ' backups, and failed selftest dirs.'),
64
                     Option('unknown',
553.1.1 by Vincent Ladeuil
Fix option help strings to comply with the style guide.
65
                            help='Delete files unknown to bzr (default).'),
66
                     Option('dry-run', help='Show files to delete instead of'
667 by Aaron Bentley
Add prompts before deleting in clean-tree
67
                            ' deleting them.'),
68
                     Option('force', help='Do not prompt before deleting.')]
69
    def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
70
            force=False):
246 by Aaron Bentley
Merged shelf_v2
71
        from clean_tree import clean_tree
415.1.1 by Adeodato Simó
Make clean-tree --detritus or --ignored not delete also unknown files,
72
        if not (unknown or ignored or detritus):
73
            unknown = True
667 by Aaron Bentley
Add prompts before deleting in clean-tree
74
        if dry_run:
75
            force = True
416 by Aaron Bentley
clean-tree --detritus no longer implies --unknown
76
        clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus, 
667 by Aaron Bentley
Add prompts before deleting in clean-tree
77
                   dry_run=dry_run, no_prompt=force)
246 by Aaron Bentley
Merged shelf_v2
78
445 by Aaron Bentley
Remove shove, tweak imports, docs
79
568 by Aaron Bentley
Don't check version when running non-bzrtools commands
80
class cmd_graph_ancestry(BzrToolsCommand):
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
81
    """Produce ancestry graphs using dot.
246 by Aaron Bentley
Merged shelf_v2
82
    
83
    Output format is detected according to file extension.  Some of the more
296 by Aaron Bentley
Updated graph-ancestry help
84
    common output formats are html, png, gif, svg, ps.  An extension of '.dot'
85
    will cause a dot graph file to be produced.  HTML output has mouseovers
86
    that show the commit message.
246 by Aaron Bentley
Merged shelf_v2
87
88
    Branches are labeled r?, where ? is the revno.  If they have no revno,
89
    with the last 5 characters of their revision identifier are used instead.
296 by Aaron Bentley
Updated graph-ancestry help
90
91
    The value starting with d is "(maximum) distance from the null revision".
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
92
246 by Aaron Bentley
Merged shelf_v2
93
    If --merge-branch is specified, the two branches are compared and a merge
94
    base is selected.
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
95
246 by Aaron Bentley
Merged shelf_v2
96
    Legend:
97
    white    normal revision
98
    yellow   THIS  history
99
    red      OTHER history
100
    orange   COMMON history
101
    blue     COMMON non-history ancestor
296 by Aaron Bentley
Updated graph-ancestry help
102
    green    Merge base (COMMON ancestor farthest from the null revision)
103
    dotted   Ghost revision (missing from branch storage)
246 by Aaron Bentley
Merged shelf_v2
104
296 by Aaron Bentley
Updated graph-ancestry help
105
    Ancestry is usually collapsed by skipping revisions with a single parent
246 by Aaron Bentley
Merged shelf_v2
106
    and descendant.  The number of skipped revisions is shown on the arrow.
107
    This feature can be disabled with --no-collapse.
108
109
    By default, revisions are ordered by distance from root, but they can be
110
    clustered instead using --cluster.
111
112
    If available, rsvg is used to antialias PNG and JPEG output, but this can
113
    be disabled with --no-antialias.
114
    """
546 by Aaron Bentley
Fix argument handling in graph-ancestry
115
    takes_args = ['file', 'merge_branch?']
553.1.1 by Vincent Ladeuil
Fix option help strings to comply with the style guide.
116
    takes_options = [Option('no-collapse', help="Do not skip simple nodes."),
296 by Aaron Bentley
Updated graph-ancestry help
117
                     Option('no-antialias',
553.1.1 by Vincent Ladeuil
Fix option help strings to comply with the style guide.
118
                     help="Do not use rsvg to produce antialiased output."),
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
119
                     Option('merge-branch', type=str,
553.1.1 by Vincent Ladeuil
Fix option help strings to comply with the style guide.
120
                     help="Use this branch to calcuate a merge base."),
476.1.2 by Aaron Bentley
graph-ancestry can restrict the number of nodes shown by distance
121
                     Option('cluster', help="Use clustered output."),
544 by Aaron Bentley
Update graph-ancestry to support new graph API
122
                     Option('max-distance',
553.1.1 by Vincent Ladeuil
Fix option help strings to comply with the style guide.
123
                            help="Show no nodes farther than this.", type=int),
544 by Aaron Bentley
Update graph-ancestry to support new graph API
124
                     Option('directory',
125
                            help='Source branch to use (default is current'
553.1.1 by Vincent Ladeuil
Fix option help strings to comply with the style guide.
126
                            ' directory).',
544 by Aaron Bentley
Update graph-ancestry to support new graph API
127
                            short_name='d',
128
                            type=unicode),
129
                    ]
546 by Aaron Bentley
Fix argument handling in graph-ancestry
130
    def run(self, file, merge_branch=None, no_collapse=False,
131
            no_antialias=False, cluster=False, max_distance=100,
132
            directory='.'):
544 by Aaron Bentley
Update graph-ancestry to support new graph API
133
        if max_distance == -1:
134
            max_distance = None
246 by Aaron Bentley
Merged shelf_v2
135
        import graph
136
        if cluster:
137
            ranking = "cluster"
138
        else:
139
            ranking = "forced"
544 by Aaron Bentley
Update graph-ancestry to support new graph API
140
        graph.write_ancestry_file(directory, file, not no_collapse,
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
141
                                  not no_antialias, merge_branch, ranking,
476.1.2 by Aaron Bentley
graph-ancestry can restrict the number of nodes shown by distance
142
                                  max_distance=max_distance)
246 by Aaron Bentley
Merged shelf_v2
143
445 by Aaron Bentley
Remove shove, tweak imports, docs
144
568 by Aaron Bentley
Don't check version when running non-bzrtools commands
145
class cmd_fetch_ghosts(BzrToolsCommand):
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
146
    """Attempt to retrieve ghosts from another branch.
246 by Aaron Bentley
Merged shelf_v2
147
    If the other branch is not supplied, the last-pulled branch is used.
148
    """
149
    aliases = ['fetch-missing']
150
    takes_args = ['branch?']
558 by Aaron Bentley
Fix the --no-fix option of fetch-ghosts
151
    takes_options = [Option('no-fix', help="Skip additional synchonization.")]
275.1.3 by Daniel Silverstone
Fix up fetch_ghosts to lock the branches, and to invoke bzr fix if it fetches any ghosts into the tree
152
    def run(self, branch=None, no_fix=False):
246 by Aaron Bentley
Merged shelf_v2
153
        from fetch_ghosts import fetch_ghosts
275.1.3 by Daniel Silverstone
Fix up fetch_ghosts to lock the branches, and to invoke bzr fix if it fetches any ghosts into the tree
154
        fetch_ghosts(branch, no_fix)
246 by Aaron Bentley
Merged shelf_v2
155
156
strip_help="""Strip the smallest prefix containing num leading slashes  from \
157
each file name found in the patch file."""
445 by Aaron Bentley
Remove shove, tweak imports, docs
158
159
568 by Aaron Bentley
Don't check version when running non-bzrtools commands
160
class cmd_patch(BzrToolsCommand):
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
161
    """Apply a named patch to the current tree.
246 by Aaron Bentley
Merged shelf_v2
162
    """
163
    takes_args = ['filename?']
496 by Aaron Bentley
Add --silent option to patch
164
    takes_options = [Option('strip', type=int, help=strip_help),
553.1.1 by Vincent Ladeuil
Fix option help strings to comply with the style guide.
165
                     Option('silent', help='Suppress chatter.')]
496 by Aaron Bentley
Add --silent option to patch
166
    def run(self, filename=None, strip=None, silent=False):
246 by Aaron Bentley
Merged shelf_v2
167
        from patch import patch
340 by Aaron Bentley
Fixed patch on checkouts
168
        from bzrlib.workingtree import WorkingTree
169
        wt = WorkingTree.open_containing('.')[0]
473 by Aaron Bentley
Clean up patch command (support http urls again)
170
        if strip is None:
171
            strip = 0
496 by Aaron Bentley
Add --silent option to patch
172
        return patch(wt, filename, strip, silent)
246 by Aaron Bentley
Merged shelf_v2
173
427 by Aaron Bentley
Merge latest changes from Shelf
174
668 by Aaron Bentley
Rename shelve/unshelve to shelve1/unshelve1, alias to old names
175
class cmd_shelve1(BzrToolsCommand):
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
176
    """Temporarily set aside some changes from the current tree.
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
177
178
    Shelve allows you to temporarily put changes you've made "on the shelf",
179
    ie. out of the way, until a later time when you can bring them back from
669 by Aaron Bentley
Update docs
180
    the shelf with the 'unshelve1' command.
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
181
289 by Aaron Bentley
Updated shelf help
182
    Shelve is intended to help separate several sets of text changes that have
183
    been inappropriately mingled.  If you just want to get rid of all changes
184
    (text and otherwise) and you don't need to restore them later, use revert.
669 by Aaron Bentley
Update docs
185
    If you want to shelve all text changes at once, use shelve1 --all.
289 by Aaron Bentley
Updated shelf help
186
669 by Aaron Bentley
Update docs
187
    By default shelve1 asks you what you want to shelve, press '?' at the
188
    prompt to get help. To shelve everything run shelve1 --all.
0.1.90 by Michael Ellerman
Update help text to try and be clearer, some stolen from bzrtools.
189
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
190
    If filenames are specified, only the changes to those files will be
191
    shelved, other files will be left untouched.
192
193
    If a revision is specified, changes since that revision will be shelved.
0.1.113 by Michael Ellerman
Support for unshelving in arbitrary order.
194
195
    You can put multiple items on the shelf. Normally each time you run
669 by Aaron Bentley
Update docs
196
    unshelve1 the most recently shelved changes will be reinstated. However,
0.1.113 by Michael Ellerman
Support for unshelving in arbitrary order.
197
    you can also unshelve changes in a different order by explicitly
669 by Aaron Bentley
Update docs
198
    specifiying which changes to unshelve1. This works best when the changes
0.1.113 by Michael Ellerman
Support for unshelving in arbitrary order.
199
    don't depend on each other.
0.7.3 by Michael Ellerman
Add a reference from 'shelve' help to 'shelf'.
200
201
    While you have patches on the shelf you can view and manipulate them with
689 by Aaron Bentley
Clarify distinction between shelf1/shelf2 commands
202
    the 'shelf1' command. Run 'bzr shelf1 -h' for more info.
0.1.90 by Michael Ellerman
Update help text to try and be clearer, some stolen from bzrtools.
203
    """
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
204
205
    takes_args = ['file*']
556 by Aaron Bentley
Fix shelf's message parameter
206
    takes_options = [Option('message',
207
            help='A message to associate with the shelved changes.',
561 by Aaron Bentley
Fix shelf message option
208
            short_name='m', type=unicode),
556 by Aaron Bentley
Fix shelf's message parameter
209
            'revision',
553.1.1 by Vincent Ladeuil
Fix option help strings to comply with the style guide.
210
            Option('all', help='Shelve all changes without prompting.'),
211
            Option('no-color', help='Never display changes in color.')]
0.1.90 by Michael Ellerman
Update help text to try and be clearer, some stolen from bzrtools.
212
423.1.4 by Aaron Bentley
Add --no-color option to shelf
213
    def run(self, all=False, file_list=None, message=None, revision=None,
214
            no_color=False):
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
215
        if revision is not None and revision:
216
            if len(revision) == 1:
217
                revision = revision[0]
218
            else:
219
                raise CommandError("shelve only accepts a single revision "
220
                                  "parameter.")
221
222
        source = BzrPatchSource(revision, file_list)
512 by Aaron Bentley
More import-time fixups
223
        s = shelf.Shelf(source.base)
423.1.4 by Aaron Bentley
Add --no-color option to shelf
224
        s.shelve(source, all, message, no_color)
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
225
        return 0
226
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
227
689 by Aaron Bentley
Clarify distinction between shelf1/shelf2 commands
228
# The following classes are only used as subcommands for 'shelf1', they're
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
229
# not to be registered directly with bzr.
230
231
class cmd_shelf_list(bzrlib.commands.Command):
232
    """List the patches on the current shelf."""
233
    aliases = ['list', 'ls']
234
    def run(self):
235
        self.shelf.list()
236
237
238
class cmd_shelf_delete(bzrlib.commands.Command):
239
    """Delete the patch from the current shelf."""
240
    aliases = ['delete', 'del']
241
    takes_args = ['patch']
242
    def run(self, patch):
243
        self.shelf.delete(patch)
244
245
246
class cmd_shelf_switch(bzrlib.commands.Command):
247
    """Switch to the other shelf, create it if necessary."""
248
    aliases = ['switch']
0.1.117 by Michael Ellerman
Arg names with hyphens don't seem to work (broke shelf switch).
249
    takes_args = ['othershelf']
250
    def run(self, othershelf):
512 by Aaron Bentley
More import-time fixups
251
        s = shelf.Shelf(self.shelf.base, othershelf)
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
252
        s.make_default()
253
254
255
class cmd_shelf_show(bzrlib.commands.Command):
0.1.110 by Michael Ellerman
Make the patch argument to 'shelf show' optional.
256
    """Show the contents of the specified or topmost patch."""
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
257
    aliases = ['show', 'cat', 'display']
0.1.110 by Michael Ellerman
Make the patch argument to 'shelf show' optional.
258
    takes_args = ['patch?']
259
    def run(self, patch=None):
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
260
        self.shelf.display(patch)
261
262
263
class cmd_shelf_upgrade(bzrlib.commands.Command):
264
    """Upgrade old format shelves."""
265
    aliases = ['upgrade']
266
    def run(self):
267
        self.shelf.upgrade()
268
269
689 by Aaron Bentley
Clarify distinction between shelf1/shelf2 commands
270
class cmd_shelf1(BzrToolsCommand):
669 by Aaron Bentley
Update docs
271
    """Perform various operations on your shelved patches. See also shelve1."""
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
272
    takes_args = ['subcommand', 'args*']
273
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
274
    subcommands = [cmd_shelf_list, cmd_shelf_delete, cmd_shelf_switch,
275
        cmd_shelf_show, cmd_shelf_upgrade]
276
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
277
    def run(self, subcommand, args_list):
278
        import sys
279
456.1.1 by Aaron Bentley
Fix shelf ls with no args (Alexander Belchenko)
280
        if args_list is None:
281
            args_list = []
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
282
        cmd = self._get_cmd_object(subcommand)
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
283
        source = BzrPatchSource()
512 by Aaron Bentley
More import-time fixups
284
        s = shelf.Shelf(source.base)
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
285
        cmd.shelf = s
0.7.4 by Michael Ellerman
Cope with run_argv_aliases() API change
286
287
        if args_list is None:
288
            args_list = []
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
289
        return cmd.run_argv_aliases(args_list)
290
291
    def _get_cmd_object(self, cmd_name):
292
        for cmd_class in self.subcommands:
293
            for alias in cmd_class.aliases:
294
                if alias == cmd_name:
295
                    return cmd_class()
296
        raise CommandError("Unknown shelf subcommand '%s'" % cmd_name)
297
298
    def help(self):
0.1.111 by Michael Ellerman
Make help for subcommands more readable, print options in help also.
299
        text = ["%s\n\nSubcommands:\n" % self.__doc__]
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
300
301
        for cmd_class in self.subcommands:
0.1.111 by Michael Ellerman
Make help for subcommands more readable, print options in help also.
302
            text.extend(self.sub_help(cmd_class) + ['\n'])
303
304
        return ''.join(text)
305
306
    def sub_help(self, cmd_class):
307
        text = []
308
        cmd_obj = cmd_class()
309
        indent = 2 * ' '
310
531.1.1 by Aaron Bentley
Add test for shelf help, since it's custom
311
        usage = cmd_obj._usage()
0.1.111 by Michael Ellerman
Make help for subcommands more readable, print options in help also.
312
        usage = usage.replace('bzr shelf-', '')
313
        text.append('%s%s\n' % (indent, usage))
314
315
        text.append('%s%s\n' % (2 * indent, cmd_class.__doc__))
316
317
        # Somewhat copied from bzrlib.help.help_on_command_options
318
        option_help = []
319
        for option_name, option in sorted(cmd_obj.options().items()):
320
            if option_name == 'help':
321
                continue
322
            option_help.append('%s--%s' % (3 * indent, option_name))
323
            if option.type is not None:
324
                option_help.append(' %s' % option.argname.upper())
325
            if option.short_name():
326
                option_help.append(', -%s' % option.short_name())
327
            option_help.append('%s%s\n' % (2 * indent, option.help))
328
329
        if len(option_help) > 0:
330
            text.append('%soptions:\n' % (2 * indent))
331
            text.extend(option_help)
332
333
        return text
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
334
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
335
668 by Aaron Bentley
Rename shelve/unshelve to shelve1/unshelve1, alias to old names
336
class cmd_unshelve1(BzrToolsCommand):
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
337
    """Restore shelved changes.
0.1.113 by Michael Ellerman
Support for unshelving in arbitrary order.
338
339
    By default the most recently shelved changes are restored. However if you
340
    specify a patch by name those changes will be restored instead.
341
669 by Aaron Bentley
Update docs
342
    See 'shelve1' for more information.
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
343
    """
0.1.91 by Michael Ellerman
Add --force option to unshelve, which runs the shelved changes through
344
    takes_options = [
553.1.1 by Vincent Ladeuil
Fix option help strings to comply with the style guide.
345
            Option('all', help='Unshelve all changes without prompting.'),
346
            Option('force', help='Force unshelving even if errors occur.'),
347
            Option('no-color', help='Never display changes in color.')
423.1.4 by Aaron Bentley
Add --no-color option to shelf
348
        ]
0.1.113 by Michael Ellerman
Support for unshelving in arbitrary order.
349
    takes_args = ['patch?']
423.1.4 by Aaron Bentley
Add --no-color option to shelf
350
    def run(self, patch=None, all=False, force=False, no_color=False):
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
351
        source = BzrPatchSource()
512 by Aaron Bentley
More import-time fixups
352
        s = shelf.Shelf(source.base)
423.1.4 by Aaron Bentley
Add --no-color option to shelf
353
        s.unshelve(source, patch, all, force, no_color)
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
354
        return 0
355
0.1.22 by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there.
356
568 by Aaron Bentley
Don't check version when running non-bzrtools commands
357
class cmd_shell(BzrToolsCommand):
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
358
    """Begin an interactive shell tailored for bzr.
287 by Aaron Bentley
Added shell docstring
359
    Bzr commands can be used without typing bzr first, and will be run natively
360
    when possible.  Tab completion is tailored for bzr.  The shell prompt shows
361
    the branch nick, revno, and path.
362
363
    If it encounters any moderately complicated shell command, it will punt to
364
    the system shell.
365
366
    Example:
367
    $ bzr shell
368
    bzr bzrtools:287/> status
369
    modified:
370
      __init__.py
371
    bzr bzrtools:287/> status --[TAB][TAB]
372
    --all        --help       --revision   --show-ids
373
    bzr bzrtools:287/> status --
374
    """
249 by Aaron Bentley
Got the shell basics working properly
375
    def run(self):
376
        import shell
281 by Aaron Bentley
Handled whitespace branch names better
377
        return shell.run_shell()
246 by Aaron Bentley
Merged shelf_v2
378
445 by Aaron Bentley
Remove shove, tweak imports, docs
379
568 by Aaron Bentley
Don't check version when running non-bzrtools commands
380
class cmd_branch_history(BzrToolsCommand):
292 by Aaron Bentley
Introduced branch-history command
381
    """\
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
382
    Display the development history of a branch.
292 by Aaron Bentley
Introduced branch-history command
383
293 by Aaron Bentley
Updated help
384
    Each different committer or branch nick is considered a different line of
385
    development.  Committers are treated as the same if they have the same
386
    name, or if they have the same email address.
292 by Aaron Bentley
Introduced branch-history command
387
    """
388
    takes_args = ["branch?"]
389
    def run(self, branch=None):
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
390
        from branchhistory import branch_history
292 by Aaron Bentley
Introduced branch-history command
391
        return branch_history(branch)
392
345 by Aaron Bentley
Added zap command
393
568 by Aaron Bentley
Don't check version when running non-bzrtools commands
394
class cmd_zap(BzrToolsCommand):
345 by Aaron Bentley
Added zap command
395
    """\
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
396
    Remove a lightweight checkout, if it can be done safely.
411 by Aaron Bentley
Update zap documentation
397
398
    This command will remove a lightweight checkout without losing data.  That
399
    means it only removes lightweight checkouts, and only if they have no
400
    uncommitted changes.
401
402
    If --branch is specified, the branch will be deleted too, but only if the
403
    the branch has no new commits (relative to its parent).
345 by Aaron Bentley
Added zap command
404
    """
553.1.1 by Vincent Ladeuil
Fix option help strings to comply with the style guide.
405
    takes_options = [Option("branch", help="Remove associated branch from"
573.1.3 by Aaron Bentley
Allow zap --force to delete modified checkouts
406
                                           " repository."),
407
                     Option('force', help='Delete tree even if contents are'
408
                     ' modified.')]
345 by Aaron Bentley
Added zap command
409
    takes_args = ["checkout"]
573.1.3 by Aaron Bentley
Allow zap --force to delete modified checkouts
410
    def run(self, checkout, branch=False, force=False):
345 by Aaron Bentley
Added zap command
411
        from zap import zap
573.1.3 by Aaron Bentley
Allow zap --force to delete modified checkouts
412
        return zap(checkout, remove_branch=branch, allow_modified=force)
345 by Aaron Bentley
Added zap command
413
414
568 by Aaron Bentley
Don't check version when running non-bzrtools commands
415
class cmd_cbranch(BzrToolsCommand):
349 by Aaron Bentley
Added cbranch command
416
    """
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
417
    Create a new checkout, associated with a new repository branch.
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
418
486 by Aaron Bentley
Support deep cbranch hierarcy via appendpath
419
    When you cbranch, bzr looks up a target location in locations.conf, and
420
    creates the branch there.
421
422
    In your locations.conf, add the following lines:
423
    [/working_directory_root]
424
    cbranch_target = /branch_root
425
    cbranch_target:policy = appendpath
426
427
    This will mean that if you run "bzr cbranch foo/bar foo/baz" in the
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
428
    working directory root, the branch will be created in
486 by Aaron Bentley
Support deep cbranch hierarcy via appendpath
429
    "/branch_root/foo/baz"
430
431
    NOTE: cbranch also supports "cbranch_root", but that behaviour is
432
    deprecated.
349 by Aaron Bentley
Added cbranch command
433
    """
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
434
    takes_options = [Option("lightweight",
596.1.1 by Aaron Bentley
Update cbranch to accelerate checkouts
435
                            help="Create a lightweight checkout."), 'revision',
600 by Aaron Bentley
Rename from-files to files-from, to match bzr proper
436
                     Option('files-from', type=unicode,
596.1.1 by Aaron Bentley
Update cbranch to accelerate checkouts
437
                            help='Accelerate checkout using files from this'
619 by Aaron Bentley
Add support for hard-link in cbranch
438
                                 ' tree.'),
439
                     Option('hardlink',
440
                            help='Hard-link files from source/files-from tree'
441
                            ' where posible.')]
355.1.2 by Aaron Bentley
cbranch mimics checkout wrt --lightweight
442
    takes_args = ["source", "target?"]
596.1.1 by Aaron Bentley
Update cbranch to accelerate checkouts
443
    def run(self, source, target=None, lightweight=False, revision=None,
619 by Aaron Bentley
Add support for hard-link in cbranch
444
            files_from=None, hardlink=False):
349 by Aaron Bentley
Added cbranch command
445
        from cbranch import cbranch
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
446
        return cbranch(source, target, lightweight=lightweight,
619 by Aaron Bentley
Add support for hard-link in cbranch
447
                       revision=revision, files_from=files_from,
448
                       hardlink=hardlink)
355.1.2 by Aaron Bentley
cbranch mimics checkout wrt --lightweight
449
349 by Aaron Bentley
Added cbranch command
450
568 by Aaron Bentley
Don't check version when running non-bzrtools commands
451
class cmd_branches(BzrToolsCommand):
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
452
    """Scan a location for branches"""
352 by Aaron Bentley
Added branches subcommand
453
    takes_args = ["location?"]
454
    def run(self, location=None):
455
        from branches import branches
456
        return branches(location)
457
603 by Aaron Bentley
Update branches, multi-pull to new APIs, create trees
458
class cmd_trees(BzrToolsCommand):
459
    """Scan a location for trees"""
460
    takes_args = ['location?']
461
    def run(self, location='.'):
462
        from bzrlib.workingtree import WorkingTree
463
        from bzrlib.transport import get_transport
464
        t = get_transport(location)
465
        for tree in WorkingTree.find_trees(location):
466
            self.outf.write('%s\n' % t.relpath(
467
                tree.bzrdir.root_transport.base))
353 by Aaron Bentley
Added multi-pull, working on branches and checkouts
468
568 by Aaron Bentley
Don't check version when running non-bzrtools commands
469
class cmd_multi_pull(BzrToolsCommand):
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
470
    """Pull all the branches under a location, e.g. a repository.
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
471
353 by Aaron Bentley
Added multi-pull, working on branches and checkouts
472
    Both branches present in the directory and the branches of checkouts are
473
    pulled.
474
    """
475
    takes_args = ["location?"]
476
    def run(self, location=None):
477
        from bzrlib.transport import get_transport
478
        from bzrtools import iter_branch_tree
479
        if location is None:
480
            location = '.'
481
        t = get_transport(location)
572 by Aaron Bentley
multi-pull reuses connections where possible
482
        possible_transports = []
353 by Aaron Bentley
Added multi-pull, working on branches and checkouts
483
        if not t.listable():
484
            print "Can't list this type of location."
485
            return 3
486
        for branch, wt in iter_branch_tree(t):
487
            if wt is None:
488
                pullable = branch
489
            else:
490
                pullable = wt
491
            parent = branch.get_parent()
492
            if parent is None:
493
                continue
494
            if wt is not None:
495
                base = wt.basedir
496
            else:
497
                base = branch.base
498
            if base.startswith(t.base):
499
                relpath = base[len(t.base):].rstrip('/')
500
            else:
501
                relpath = base
502
            print "Pulling %s from %s" % (relpath, parent)
503
            try:
572 by Aaron Bentley
multi-pull reuses connections where possible
504
                branch_t = get_transport(parent, possible_transports)
505
                pullable.pull(Branch.open_from_transport(branch_t))
353 by Aaron Bentley
Added multi-pull, working on branches and checkouts
506
            except Exception, e:
507
                print e
508
509
603 by Aaron Bentley
Update branches, multi-pull to new APIs, create trees
510
568 by Aaron Bentley
Don't check version when running non-bzrtools commands
511
class cmd_import(BzrToolsCommand):
490 by Aaron Bentley
Improve bzr import docs
512
    """Import sources from a directory, tarball or zip file
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
513
490 by Aaron Bentley
Improve bzr import docs
514
    This command will import a directory, tarball or zip file into a bzr
515
    tree, replacing any versioned files already present.  If a directory is
516
    specified, it is used as the target.  If the directory does not exist, or
517
    is not versioned, it is created.
380 by Aaron Bentley
Got import working decently
518
519
    Tarballs may be gzip or bzip2 compressed.  This is autodetected.
520
490 by Aaron Bentley
Improve bzr import docs
521
    If the tarball or zip has a single root directory, that directory is
522
    stripped when extracting the tarball.  This is not done for directories.
380 by Aaron Bentley
Got import working decently
523
    """
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
524
380 by Aaron Bentley
Got import working decently
525
    takes_args = ['source', 'tree?']
526
    def run(self, source, tree=None):
377 by Aaron Bentley
Got import command working
527
        from upstream_import import do_import
380 by Aaron Bentley
Got import working decently
528
        do_import(source, tree)
377 by Aaron Bentley
Got import command working
529
392.1.1 by Aaron Bentley
Implement 'shove' for moving changes to other trees
530
568 by Aaron Bentley
Don't check version when running non-bzrtools commands
531
class cmd_cdiff(BzrToolsCommand):
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
532
    """A color version of bzr's diff"""
410 by Aaron Bentley
Ensure the option settings come from the right 'diff' in colordiff
533
    takes_args = property(lambda x: get_cmd_object('diff').takes_args)
560 by Aaron Bentley
Update cdiff option definition
534
    takes_options = list(get_cmd_object('diff').takes_options) + [
680.1.3 by Benoît Pierre
Add --color=MODE option to cdiff; MODE can be:
535
        RegistryOption.from_kwargs('color',
536
            'Color mode to use.',
537
            title='Color Mode', value_switches=False, enum_switch=True,
538
            never='Never colorize output.',
539
            auto='Only colorize output if terminal supports it and STDOUT is a'
540
            ' TTY.',
684 by Aaron Bentley
Fix cdiff color switch by deferring to DiffWriter
541
            always='Always colorize output (default).'),
560 by Aaron Bentley
Update cdiff option definition
542
        Option('check-style',
500 by Aaron Bentley
Add help
543
            help='Warn if trailing whitespace or spurious changes have been'
560 by Aaron Bentley
Update cdiff option definition
544
                 ' added.')]
497 by Aaron Bentley
Add optional style checks to colordiff
545
680.1.3 by Benoît Pierre
Add --color=MODE option to cdiff; MODE can be:
546
    def run(self, color='always', check_style=False, *args, **kwargs):
399 by Aaron Bentley
Implement cdiff (based on old Fai code)
547
        from colordiff import colordiff
680.1.3 by Benoît Pierre
Add --color=MODE option to cdiff; MODE can be:
548
        colordiff(color, check_style, *args, **kwargs)
360.1.3 by Aaron Bentley
Add experimental branch-mark command
549
430 by Aaron Bentley
Avoid loading PyBaz unless running baz-import
550
568 by Aaron Bentley
Don't check version when running non-bzrtools commands
551
class cmd_rspush(BzrToolsCommand):
460 by Aaron Bentley
Add encoding parameter everywhere
552
    """Upload this branch to another location using rsync.
553
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
554
    If no location is specified, the last-used location will be used.  To
555
    prevent dirty trees from being uploaded, rspush will error out if there are
556
    unknown files or local changes.  It will also error out if the upstream
557
    directory is non-empty and not an earlier version of the branch.
460 by Aaron Bentley
Add encoding parameter everywhere
558
    """
559
    takes_args = ['location?']
560
    takes_options = [Option('overwrite', help='Ignore differences between'
553.1.1 by Vincent Ladeuil
Fix option help strings to comply with the style guide.
561
                            ' branches and overwrite unconditionally.'),
460 by Aaron Bentley
Add encoding parameter everywhere
562
                     Option('no-tree', help='Do not push the working tree,'
563
                            ' just the .bzr.')]
564
565
    def run(self, location=None, overwrite=False, no_tree=False):
566
        from bzrlib import workingtree
567
        import bzrtools
568
        cur_branch = workingtree.WorkingTree.open_containing(".")[0]
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
569
        bzrtools.rspush(cur_branch, location, overwrite=overwrite,
460 by Aaron Bentley
Add encoding parameter everywhere
570
                      working_tree=not no_tree)
571
572
622 by Aaron Bentley
Add link-tree command
573
class cmd_link_tree(BzrToolsCommand):
574
    """Hardlink matching files to another tree.
575
576
    Only files with identical content and execute bit will be linked.
577
    """
578
    takes_args = ['location']
579
580
    def run(self, location):
581
        from bzrlib import workingtree
582
        from bzrlib.plugins.bzrtools.link_tree import link_tree
583
        target_tree = workingtree.WorkingTree.open_containing(".")[0]
584
        source_tree = workingtree.WorkingTree.open(location)
585
        target_tree.lock_write()
586
        try:
587
            source_tree.lock_read()
588
            try:
589
                link_tree(target_tree, source_tree)
590
            finally:
591
                source_tree.unlock()
592
        finally:
593
            target_tree.unlock()