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
|
#!/usr/bin/python
"""\
Various useful plugins for working with bzr.
"""
import bzrlib.commands
import push
import annotate
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__))
Option.OPTIONS['ignored'] = Option('ignored',
help='delete all ignored files.')
Option.OPTIONS['detrius'] = Option('detrius',
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', 'detrius', 'dry-run']
def run(self, ignored=False, detrius=False, dry_run=False):
from clean_tree import clean_tree
clean_tree('.', ignored=ignored, detrius=detrius, dry_run=dry_run)
Option.OPTIONS['no-collapse'] = Option('no-collapse')
Option.OPTIONS['no-antialias'] = Option('no-antialias')
Option.OPTIONS['cluster'] = Option('cluster')
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 png, gif, svg, ps. An extension of '.dot' will
cause a dot graph file to be produced.
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.
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
dotted Missing from branch storage
Ancestry is usually collapsed by removing 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 = ['no-collapse', 'no-antialias', 'merge-branch', 'cluster']
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?']
def run(self, branch=None):
from fetch_ghosts import fetch_ghosts
fetch_ghosts(branch)
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=0):
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 changes from the current tree.
Use 'unshelve' to restore these changes.
If filenames are specified, only changes to those files will be unshelved.
If a revision is specified, all changes since that revision will may be
unshelved.
"""
takes_args = ['file*']
takes_options = ['all', '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):
def run(self):
import shell
shell.run_shell()
commands = [cmd_shelve, cmd_unshelve, cmd_clean_tree, cmd_graph_ancestry,
cmd_fetch_ghosts, cmd_patch, cmd_shell]
import bzrlib.builtins
if not hasattr(bzrlib.builtins, "cmd_annotate"):
commands.append(annotate.cmd_annotate)
if not hasattr(bzrlib.builtins, "cmd_push"):
commands.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)
def test_suite():
from doctest import DocTestSuite
from unittest import TestSuite, TestLoader
import clean_tree
import blackbox
import shelf_tests
result = TestSuite()
result.addTest(DocTestSuite(bzrtools))
result.addTest(clean_tree.test_suite())
result.addTest(TestLoader().loadTestsFromModule(shelf_tests))
result.addTest(blackbox.test_suite())
return result
|