~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Aaron Bentley
  • Date: 2006-03-16 14:59:04 UTC
  • mfrom: (325.1.3 bzrtools)
  • Revision ID: abentley@panoramicfeedback.com-20060316145904-c004cd0222a1f1c8
Merge shelf v2 again

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
 
"""Shelf - temporarily set aside changes, then bring them back."""
3
 
 
 
2
"""\
 
3
Various useful plugins for working with bzr.
 
4
"""
4
5
import bzrlib.commands
 
6
import push
5
7
from errors import CommandError
6
 
from bzrlib.option import Option
7
8
from patchsource import BzrPatchSource
8
9
from shelf import Shelf
 
10
import sys
 
11
import os.path
 
12
from bzrlib.option import Option
 
13
import bzrlib.branch
 
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__), 
 
17
                                                 "external")))
9
18
from bzrlib import DEFAULT_IGNORE
10
19
 
 
20
 
11
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.')
 
32
 
 
33
class cmd_clean_tree(bzrlib.commands.Command):
 
34
    """Remove unwanted files from working tree.
 
35
    Normally, ignored files are left alone.
 
36
    """
 
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)
 
41
 
 
42
Option.OPTIONS['merge-branch'] = Option('merge-branch',type=str)
 
43
 
 
44
class cmd_graph_ancestry(bzrlib.commands.Command):
 
45
    """Produce ancestry graphs using dot.
 
46
    
 
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.
 
51
 
 
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.
 
54
 
 
55
    The value starting with d is "(maximum) distance from the null revision".
 
56
    
 
57
    If --merge-branch is specified, the two branches are compared and a merge
 
58
    base is selected.
 
59
    
 
60
    Legend:
 
61
    white    normal revision
 
62
    yellow   THIS  history
 
63
    red      OTHER history
 
64
    orange   COMMON history
 
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)
 
68
 
 
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.
 
72
 
 
73
    By default, revisions are ordered by distance from root, but they can be
 
74
    clustered instead using --cluster.
 
75
 
 
76
    If available, rsvg is used to antialias PNG and JPEG output, but this can
 
77
    be disabled with --no-antialias.
 
78
    """
 
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):
 
88
        import graph
 
89
        if cluster:
 
90
            ranking = "cluster"
 
91
        else:
 
92
            ranking = "forced"
 
93
        graph.write_ancestry_file(branch, file, not no_collapse, 
 
94
                                  not no_antialias, merge_branch, ranking)
 
95
 
 
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.
 
99
    """
 
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)
 
106
 
 
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.
 
114
    """
 
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]
 
121
        if strip == -1:
 
122
            if bzrdiff: strip = 0
 
123
            else:       strip = 1
 
124
 
 
125
        return patch(b, filename, strip, legacy= not bzrdiff)
12
126
 
13
127
class cmd_shelve(bzrlib.commands.Command):
14
 
    """Temporarily set aside some changes to the current working tree.
 
128
    """Temporarily set aside some changes from the current tree.
15
129
 
16
130
    Shelve allows you to temporarily put changes you've made "on the shelf",
17
131
    ie. out of the way, until a later time when you can bring them back from
18
132
    the shelf with the 'unshelve' command.
19
133
 
 
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.
 
138
 
 
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.
 
141
 
20
142
    You can put multiple items on the shelf, each time you run unshelve the
21
143
    most recently shelved changes will be reinstated.
22
144
 
24
146
    shelved, other files will be left untouched.
25
147
 
26
148
    If a revision is specified, changes since that revision will be shelved.
 
149
    """
27
150
 
28
 
    By default shelve asks you what you want to shelve, press "?" at the 
29
 
    prompt to get help on the UI. To shelve everything run 'shelve --all'.
30
 
    """
31
151
    takes_args = ['file*']
32
 
    takes_options = [Option('all'), 'message', 'revision']
 
152
    takes_options = ['message', 'revision',
 
153
            Option('all', help='Shelve all changes without prompting')]
 
154
 
33
155
    def run(self, all=False, file_list=None, message=None, revision=None):
34
156
        if revision is not None and revision:
35
157
            if len(revision) == 1:
44
166
        return 0
45
167
 
46
168
class cmd_shelf(bzrlib.commands.Command):
47
 
    """Perform various operations on your shelved patches.
 
169
    """Perform various operations on your shelved patches. See also shelve.
48
170
 
49
171
    Subcommands:
50
172
        list   (ls)           List the patches on the current shelf.
51
173
        delete (del) <patch>  Delete a patch from the current shelf.
52
174
        switch       <shelf>  Switch to the named shelf, create it if necessary.
53
175
        show         <patch>  Show the contents of the specified patch.
 
176
        upgrade               Upgrade old format shelves.
54
177
    """
55
178
    takes_args = ['subcommand', 'args*']
56
179
 
73
196
        elif subcommand == 'show':
74
197
            self.__check_one_arg(args_list, "shelf show takes one argument!")
75
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()
76
202
        else:
77
203
            print subcommand, args_list
78
204
            print >>sys.stderr, "Unknown shelf subcommand '%s'" % subcommand
79
205
 
80
206
    def __check_one_arg(self, args, msg):
81
207
        if args is None or len(args) != 1:
82
 
            raise BzrCommandError(msg)
 
208
            raise CommandError(msg)
83
209
 
84
210
    def __check_no_args(self, args, msg):
85
211
        if args is not None:
86
 
            raise BzrCommandError(msg)
 
212
            raise CommandError(msg)
 
213
 
87
214
 
88
215
class cmd_unshelve(bzrlib.commands.Command):
89
 
    """Reinstate the most recently shelved changes.
 
216
    """Restore the most recently shelved changes to the current tree.
90
217
    See 'shelve' for more information.
91
218
    """
92
 
    takes_options = [Option('all')]
93
 
    def run(self, all=False):
 
219
    takes_options = [
 
220
            Option('all', help='Unshelve all changes without prompting'),
 
221
            Option('force', help='Force unshelving even if errors occur'),
 
222
    ]
 
223
    def run(self, all=False, force=False):
94
224
        source = BzrPatchSource()
95
225
        s = Shelf(source.base)
96
 
        s.unshelve(source, all)
 
226
        s.unshelve(source, all, force)
97
227
        return 0
98
228
 
99
 
bzrlib.commands.register_command(cmd_shelf)
100
 
bzrlib.commands.register_command(cmd_shelve)
101
 
bzrlib.commands.register_command(cmd_unshelve)
 
229
 
 
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.
 
235
 
 
236
    If it encounters any moderately complicated shell command, it will punt to
 
237
    the system shell.
 
238
 
 
239
    Example:
 
240
    $ bzr shell
 
241
    bzr bzrtools:287/> status
 
242
    modified:
 
243
      __init__.py
 
244
    bzr bzrtools:287/> status --[TAB][TAB]
 
245
    --all        --help       --revision   --show-ids
 
246
    bzr bzrtools:287/> status --
 
247
    """
 
248
    def run(self):
 
249
        import shell
 
250
        return shell.run_shell()
 
251
 
 
252
class cmd_branch_history(bzrlib.commands.Command):
 
253
    """\
 
254
    Display the revision history with reference to lines of development.
 
255
 
 
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.
 
259
    """
 
260
    takes_args = ["branch?"]
 
261
    def run(self, branch=None):
 
262
        from branchhistory import branch_history 
 
263
        return branch_history(branch)
 
264
 
 
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
 
 
306
 
 
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(
 
312
            command, True)
 
313
 
102
314
 
103
315
def test_suite():
 
316
    import baz_import
104
317
    from bzrlib.tests.TestUtil import TestLoader
105
318
    import tests
106
 
    return TestLoader().loadTestsFromModule(tests)
 
319
    from doctest import DocTestSuite, ELLIPSIS
 
320
    from unittest import TestSuite
 
321
    import clean_tree
 
322
    import blackbox
 
323
    import shelf_tests
 
324
    result = 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())
 
331
    return result