~abentley/bzrtools/bzrtools.dev

124 by Aaron Bentley
Added docstring for bzrtools
1
"""\
2
Various useful plugins for working with bzr.
3
"""
93 by Aaron Bentley
Used the bzr 0.5+ plugin stuff
4
import bzrlib.commands
5
import push
6
import annotate
7
import shelf
119 by aaron.bentley at utoronto
Added conflict-awareness tools
8
import conflicts
132 by Aaron Bentley
brute-forced bzrtools path into sys.path so baz-import works
9
import sys
10
import os.path
147.2.2 by Aaron Bentley
Committed debugging changes
11
#sys.path.insert(0, os.path.realpath(os.path.dirname(__file__)))
118 by aaron.bentley at utoronto
Added clean-tree command
12
13
bzrlib.commands.OPTIONS['ignored'] = None
14
15
class cmd_clean_tree(bzrlib.commands.Command):
16
    """Remove unwanted files from working tree.
17
    Normally, ignored files are left alone.  The --ignored flag will cause them
18
    to be deleted as well.
19
    """
20
    takes_options = ['ignored']
21
    def run(self, ignored=False):
22
        import clean_tree
23
        clean_tree.clean_tree(ignored=ignored)
24
119 by aaron.bentley at utoronto
Added conflict-awareness tools
25
class cmd_conflicted(bzrlib.commands.Command):
26
    """List files that have conflicts
27
    """
28
    takes_options = ['ignored']
29
    def run(self, ignored=False):
30
        import clean_tree
31
        clean_tree.clean_tree(ignored=ignored)
118 by aaron.bentley at utoronto
Added clean-tree command
32
136 by Aaron Bentley
Allowed disabling ancestry collapsing
33
bzrlib.commands.OPTIONS['no-collapse'] = None
143 by Aaron Bentley
Used rsvga for nice antialiasing
34
bzrlib.commands.OPTIONS['no-antialias'] = None
178 by Aaron Bentley
Switched from clusters to forced ranking
35
bzrlib.commands.OPTIONS['cluster'] = None
160 by Aaron Bentley
Restored old graph-ancestry functionality
36
bzrlib.commands.OPTIONS['merge-branch'] = str
136 by Aaron Bentley
Allowed disabling ancestry collapsing
37
128 by Aaron Bentley
Got initial graphing functionality working
38
class cmd_graph_ancestry(bzrlib.commands.Command):
136 by Aaron Bentley
Allowed disabling ancestry collapsing
39
    """Produce ancestry graphs using dot.
40
    
41
    Output format is detected according to file extension.  Some of the more
137 by Aaron Bentley
Put dotted outlines on missing revisions
42
    common output formats are png, gif, svg, ps.  An extension of '.dot' will
43
    cause a dot graph file to be produced.
136 by Aaron Bentley
Allowed disabling ancestry collapsing
44
185 by Aaron Bentley
Updated help
45
    Branches are labeled r?, where ? is the revno.  If they have no revno,
46
    with the last 5 characters of their revision identifier are used instead.
47
    
48
    If --merge-branch is specified, the two branches are compared and a merge
49
    base is selected.
50
    
51
    Legend:
190 by Aaron Bentley
Set normal revisions to white
52
    white    normal revision
185 by Aaron Bentley
Updated help
53
    yellow   THIS  history
54
    red      OTHER history
55
    orange   COMMON history
191 by Aaron Bentley
tweaked docs
56
    blue     COMMON non-history ancestor
185 by Aaron Bentley
Updated help
57
    dotted   Missing from branch storage
181 by Aaron Bentley
Updated help
58
59
    Ancestry is usually collapsed by removing revisions with a single parent
60
    and descendant.  The number of skipped revisions is shown on the arrow.
61
    This feature can be disabled with --no-collapse.
62
63
    By default, revisions are ordered by distance from root, but they can be
64
    clustered instead using --cluster.
65
191 by Aaron Bentley
tweaked docs
66
    If available, rsvg is used to antialias PNG and JPEG output, but this can
67
    be disabled with --no-antialias.
136 by Aaron Bentley
Allowed disabling ancestry collapsing
68
    """
131 by Aaron Bentley
Added required filename parameter
69
    takes_args = ['branch', 'file']
178 by Aaron Bentley
Switched from clusters to forced ranking
70
    takes_options = ['no-collapse', 'no-antialias', 'merge-branch', 'cluster']
160 by Aaron Bentley
Restored old graph-ancestry functionality
71
    def run(self, branch, file, no_collapse=False, no_antialias=False,
178 by Aaron Bentley
Switched from clusters to forced ranking
72
        merge_branch=None, cluster=False):
128 by Aaron Bentley
Got initial graphing functionality working
73
        import graph
178 by Aaron Bentley
Switched from clusters to forced ranking
74
        if cluster:
75
            ranking = "cluster"
76
        else:
77
            ranking = "forced"
143 by Aaron Bentley
Used rsvga for nice antialiasing
78
        graph.write_ancestry_file(branch, file, not no_collapse, 
178 by Aaron Bentley
Switched from clusters to forced ranking
79
                                  not no_antialias, merge_branch, ranking)
128 by Aaron Bentley
Got initial graphing functionality working
80
144 by aaron.bentley at utoronto
Added fetch-missing command
81
class cmd_fetch_missing(bzrlib.commands.Command):
150 by abentley
Made fetch_missing use the x-pull file
82
    """Attempt to retrieve missing ancestors from another branch.
83
    If the other branch is not supplied, the last-pulled branch is used.
144 by aaron.bentley at utoronto
Added fetch-missing command
84
    """
150 by abentley
Made fetch_missing use the x-pull file
85
    takes_args = ['branch?']
86
    def run(self, branch=None):
144 by aaron.bentley at utoronto
Added fetch-missing command
87
        from fetch_missing import fetch_missing
88
        fetch_missing(branch)
89
152 by Aaron Bentley
Added new bzr patch command
90
class cmd_patch(bzrlib.commands.Command):
91
    """Apply a named patch to the current tree.
92
    """
93
    takes_args = ['filename?']
94
    takes_options = ['strip']
95
    def run(self, filename=None, strip=0):
96
        from patch import patch
97
        from bzrlib.branch import Branch
158 by Aaron Bentley
Updated to match API changes
98
        b = Branch.open_containing('.')
152 by Aaron Bentley
Added new bzr patch command
99
        return patch(b, filename, strip)
100
101
102
100 by Aaron Bentley
Fixed up the baz-import plugin
103
commands = [push.cmd_push, annotate.cmd_annotate, shelf.cmd_shelve, 
122 by aaron.bentley at utoronto
Added resolve command
104
            shelf.cmd_unshelve, cmd_clean_tree, conflicts.cmd_conflicts,
152 by Aaron Bentley
Added new bzr patch command
105
            conflicts.cmd_resolve, cmd_graph_ancestry, cmd_fetch_missing,
106
            cmd_patch]
105 by Aaron Bentley
Fixed NoPyBaz detection
107
from errors import NoPyBaz
100 by Aaron Bentley
Fixed up the baz-import plugin
108
try:
109
    import baz_import
147.1.11 by Robert Collins
move baz-import to baz-import-branch
110
    commands.append(baz_import.cmd_baz_import_branch)
100 by Aaron Bentley
Fixed up the baz-import plugin
111
    commands.append(baz_import.cmd_baz_import)
105 by Aaron Bentley
Fixed NoPyBaz detection
112
113
except NoPyBaz:
100 by Aaron Bentley
Fixed up the baz-import plugin
114
    class cmd_baz_import(bzrlib.commands.Command):
115
        """Disabled. (Requires PyBaz)"""
116
    commands.append(cmd_baz_import)
117
94 by Aaron Bentley
Adjsted to match plugin api
118
if hasattr(bzrlib.commands, 'register_command'):
93 by Aaron Bentley
Used the bzr 0.5+ plugin stuff
119
    for command in commands:
94 by Aaron Bentley
Adjsted to match plugin api
120
        bzrlib.commands.register_command(command)
147 by Robert Collins
make bzr selftest run the plugins tests, and fix them
121
122
def test_suite():
147.1.2 by Robert Collins
test empty import and tagged branches
123
    import baz_import
147.1.1 by Robert Collins
start adding baz_import unit test cases
124
    import tests
147 by Robert Collins
make bzr selftest run the plugins tests, and fix them
125
    from doctest import DocTestSuite
147.1.1 by Robert Collins
start adding baz_import unit test cases
126
    from unittest import TestSuite
127
    result = TestSuite()
128
    result.addTest(DocTestSuite(bzrtools))
147.1.2 by Robert Collins
test empty import and tagged branches
129
    result.addTest(DocTestSuite(baz_import))
147.1.1 by Robert Collins
start adding baz_import unit test cases
130
    result.addTest(tests.test_suite())
131
    return result