~abentley/bzrtools/bzrtools.dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/usr/bin/python
"""\
Various useful plugins for working with bzr.
"""
import bzrlib.commands
import push
from shelf import Shelf
import sys
import os.path
from bzrlib.option import Option
import bzrlib.branch
from bzrlib.errors import BzrCommandError
sys.path.append(os.path.dirname(__file__))
from reweave_inventory import cmd_fix

Option.OPTIONS['ignored'] = Option('ignored',
        help='delete all ignored files.')
Option.OPTIONS['detritus'] = Option('detritus',
        help='delete conflict files merge backups, and failed selftest dirs.' +
              '(*.THIS, *.BASE, *.OTHER, *~, *.tmp')
Option.OPTIONS['dry-run'] = Option('dry-run',
        help='show files to delete instead of deleting them.')

class cmd_clean_tree(bzrlib.commands.Command):
    """Remove unwanted files from working tree.
    Normally, ignored files are left alone.
    """
    takes_options = ['ignored', 'detritus', 'dry-run']
    def run(self, ignored=False, detritus=False, dry_run=False):
        from clean_tree import clean_tree
        clean_tree('.', ignored=ignored, detritus=detritus, dry_run=dry_run)

Option.OPTIONS['merge-branch'] = Option('merge-branch',type=str)

class cmd_graph_ancestry(bzrlib.commands.Command):
    """Produce ancestry graphs using dot.
    
    Output format is detected according to file extension.  Some of the more
    common output formats are html, png, gif, svg, ps.  An extension of '.dot'
    will cause a dot graph file to be produced.  HTML output has mouseovers
    that show the commit message.

    Branches are labeled r?, where ? is the revno.  If they have no revno,
    with the last 5 characters of their revision identifier are used instead.

    The value starting with d is "(maximum) distance from the null revision".
    
    If --merge-branch is specified, the two branches are compared and a merge
    base is selected.
    
    Legend:
    white    normal revision
    yellow   THIS  history
    red      OTHER history
    orange   COMMON history
    blue     COMMON non-history ancestor
    green    Merge base (COMMON ancestor farthest from the null revision)
    dotted   Ghost revision (missing from branch storage)

    Ancestry is usually collapsed by skipping revisions with a single parent
    and descendant.  The number of skipped revisions is shown on the arrow.
    This feature can be disabled with --no-collapse.

    By default, revisions are ordered by distance from root, but they can be
    clustered instead using --cluster.

    If available, rsvg is used to antialias PNG and JPEG output, but this can
    be disabled with --no-antialias.
    """
    takes_args = ['branch', 'file']
    takes_options = [Option('no-collapse', help="Do not skip simple nodes"), 
                     Option('no-antialias',
                     help="Do not use rsvg to produce antialiased output"), 
                     Option('merge-branch', type=str, 
                     help="Use this branch to calcuate a merge base"), 
                     Option('cluster', help="Use clustered output.")]
    def run(self, branch, file, no_collapse=False, no_antialias=False,
        merge_branch=None, cluster=False):
        import graph
        if cluster:
            ranking = "cluster"
        else:
            ranking = "forced"
        graph.write_ancestry_file(branch, file, not no_collapse, 
                                  not no_antialias, merge_branch, ranking)

class cmd_fetch_ghosts(bzrlib.commands.Command):
    """Attempt to retrieve ghosts from another branch.
    If the other branch is not supplied, the last-pulled branch is used.
    """
    aliases = ['fetch-missing']
    takes_args = ['branch?']
    takes_options = [Option('no-fix')]
    def run(self, branch=None, no_fix=False):
        from fetch_ghosts import fetch_ghosts
        fetch_ghosts(branch, no_fix)

strip_help="""Strip the smallest prefix containing num leading slashes  from \
each file name found in the patch file."""
Option.OPTIONS['strip'] = Option('strip', type=int, help=strip_help)
class cmd_patch(bzrlib.commands.Command):
    """Apply a named patch to the current tree.
    """
    takes_args = ['filename?']
    takes_options = ['strip']
    def run(self, filename=None, strip=1):
        from patch import patch
        from bzrlib.branch import Branch
        b = Branch.open_containing('.')[0]
        return patch(b, filename, strip)


class cmd_shelve(bzrlib.commands.Command):
    """Temporarily remove some text changes from the current tree.
    Use 'unshelve' to restore these changes.

    Shelve is intended to help separate several sets of text changes that have
    been inappropriately mingled.  If you just want to get rid of all changes
    (text and otherwise) and you don't need to restore them later, use revert.
    If you want to shelve all text changes at once, use shelve --all.

    If filenames are specified, only changes to those files will be shelved.
    If a revision is specified, all changes since that revision will may be
    shelved.
    """
    takes_args = ['file*']
    takes_options = [Option('all', 
                            help='Shelve all changes without prompting'), 
                     'message', 'revision']
    def run(self, all=False, file_list=None, message=None, revision=None):
        if file_list is not None and len(file_list) > 0:
            branchdir = file_list[0]
        else:
            branchdir = '.'

        if revision is not None and revision:
            if len(revision) == 1:
                revision = revision[0]
            else:
                raise BzrCommandError("shelve only accepts a single revision "
                                  "parameter.")

        s = Shelf(branchdir)
        return s.shelve(all, message, revision, file_list)


class cmd_unshelve(bzrlib.commands.Command):
    """Restore previously-shelved changes to the current tree.
    See also 'shelve'.
    """
    def run(self):
        s = Shelf('.')
        return s.unshelve()

class cmd_shell(bzrlib.commands.Command):
    """Begin an interactive shell tailored for bzr.
    Bzr commands can be used without typing bzr first, and will be run natively
    when possible.  Tab completion is tailored for bzr.  The shell prompt shows
    the branch nick, revno, and path.

    If it encounters any moderately complicated shell command, it will punt to
    the system shell.

    Example:
    $ bzr shell
    bzr bzrtools:287/> status
    modified:
      __init__.py
    bzr bzrtools:287/> status --[TAB][TAB]
    --all        --help       --revision   --show-ids
    bzr bzrtools:287/> status --
    """
    def run(self):
        import shell
        return shell.run_shell()

class cmd_branch_history(bzrlib.commands.Command):
    """\
    Display the revision history with reference to lines of development.

    Each different committer or branch nick is considered a different line of
    development.  Committers are treated as the same if they have the same
    name, or if they have the same email address.
    """
    takes_args = ["branch?"]
    def run(self, branch=None):
        from branchhistory import branch_history 
        return branch_history(branch)

commands = [cmd_shelve, cmd_unshelve, cmd_clean_tree, cmd_graph_ancestry,
            cmd_fetch_ghosts, cmd_patch, cmd_shell, cmd_fix, cmd_branch_history]

command_decorators = []

import bzrlib.builtins
if not hasattr(bzrlib.builtins, "cmd_push"):
    commands.append(push.cmd_push)
else:
    command_decorators.append(push.cmd_push)

from errors import NoPyBaz
try:
    import baz_import
    commands.append(baz_import.cmd_baz_import)

except NoPyBaz:
    class cmd_baz_import(bzrlib.commands.Command):
        """Disabled. (Requires PyBaz)"""
        takes_args = ['to_root_dir?', 'from_archive?']
        takes_options = ['verbose']
        def run(self, to_root_dir=None, from_archive=None, verbose=False):
            print "This command is disabled.  Please install PyBaz."
    commands.append(cmd_baz_import)


if hasattr(bzrlib.commands, 'register_command'):
    for command in commands:
        bzrlib.commands.register_command(command)
    for command in command_decorators:
        command._original_command = bzrlib.commands.register_command(
            command, True)


def test_suite():
    from doctest import DocTestSuite, ELLIPSIS
    from unittest import TestSuite, TestLoader
    import clean_tree
    import blackbox
    import shelf_tests
    result = TestSuite()
    result.addTest(DocTestSuite(bzrtools, optionflags=ELLIPSIS))
    result.addTest(clean_tree.test_suite())
    result.addTest(TestLoader().loadTestsFromModule(shelf_tests))
    result.addTest(blackbox.test_suite())
    return result