0.1.22
by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there. |
1 |
#!/usr/bin/python
|
246
by Aaron Bentley
Merged shelf_v2 |
2 |
"""\
|
3 |
Various useful plugins for working with bzr.
|
|
4 |
"""
|
|
0.1.22
by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there. |
5 |
import bzrlib.commands |
246
by Aaron Bentley
Merged shelf_v2 |
6 |
import push |
7 |
import annotate |
|
8 |
from shelf import Shelf |
|
9 |
import sys |
|
10 |
import os.path |
|
11 |
from bzrlib.option import Option |
|
0.1.22
by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there. |
12 |
import bzrlib.branch |
0.1.39
by Michael Ellerman
Fix shelve and unshelve to pass location to Shelf(). |
13 |
from bzrlib.errors import BzrCommandError |
246
by Aaron Bentley
Merged shelf_v2 |
14 |
sys.path.append(os.path.dirname(__file__)) |
277
by Aaron Bentley
Renamed force-reweave-inventory to fix |
15 |
from reweave_inventory import cmd_fix |
246
by Aaron Bentley
Merged shelf_v2 |
16 |
|
17 |
Option.OPTIONS['ignored'] = Option('ignored', |
|
18 |
help='delete all ignored files.') |
|
265
by Aaron Bentley
Fixed spelling of detritus |
19 |
Option.OPTIONS['detritus'] = Option('detritus', |
246
by Aaron Bentley
Merged shelf_v2 |
20 |
help='delete conflict files merge backups, and failed selftest dirs.' + |
21 |
'(*.THIS, *.BASE, *.OTHER, *~, *.tmp') |
|
22 |
Option.OPTIONS['dry-run'] = Option('dry-run', |
|
23 |
help='show files to delete instead of deleting them.') |
|
24 |
||
25 |
class cmd_clean_tree(bzrlib.commands.Command): |
|
26 |
"""Remove unwanted files from working tree.
|
|
27 |
Normally, ignored files are left alone.
|
|
28 |
"""
|
|
265
by Aaron Bentley
Fixed spelling of detritus |
29 |
takes_options = ['ignored', 'detritus', 'dry-run'] |
30 |
def run(self, ignored=False, detritus=False, dry_run=False): |
|
246
by Aaron Bentley
Merged shelf_v2 |
31 |
from clean_tree import clean_tree |
265
by Aaron Bentley
Fixed spelling of detritus |
32 |
clean_tree('.', ignored=ignored, detritus=detritus, dry_run=dry_run) |
246
by Aaron Bentley
Merged shelf_v2 |
33 |
|
34 |
Option.OPTIONS['no-collapse'] = Option('no-collapse') |
|
35 |
Option.OPTIONS['no-antialias'] = Option('no-antialias') |
|
36 |
Option.OPTIONS['cluster'] = Option('cluster') |
|
37 |
Option.OPTIONS['merge-branch'] = Option('merge-branch',type=str) |
|
38 |
||
39 |
class cmd_graph_ancestry(bzrlib.commands.Command): |
|
40 |
"""Produce ancestry graphs using dot.
|
|
41 |
|
|
42 |
Output format is detected according to file extension. Some of the more
|
|
43 |
common output formats are png, gif, svg, ps. An extension of '.dot' will
|
|
44 |
cause a dot graph file to be produced.
|
|
45 |
||
46 |
Branches are labeled r?, where ? is the revno. If they have no revno,
|
|
47 |
with the last 5 characters of their revision identifier are used instead.
|
|
48 |
|
|
49 |
If --merge-branch is specified, the two branches are compared and a merge
|
|
50 |
base is selected.
|
|
51 |
|
|
52 |
Legend:
|
|
53 |
white normal revision
|
|
54 |
yellow THIS history
|
|
55 |
red OTHER history
|
|
56 |
orange COMMON history
|
|
57 |
blue COMMON non-history ancestor
|
|
58 |
dotted Missing from branch storage
|
|
59 |
||
60 |
Ancestry is usually collapsed by removing revisions with a single parent
|
|
61 |
and descendant. The number of skipped revisions is shown on the arrow.
|
|
62 |
This feature can be disabled with --no-collapse.
|
|
63 |
||
64 |
By default, revisions are ordered by distance from root, but they can be
|
|
65 |
clustered instead using --cluster.
|
|
66 |
||
67 |
If available, rsvg is used to antialias PNG and JPEG output, but this can
|
|
68 |
be disabled with --no-antialias.
|
|
69 |
"""
|
|
70 |
takes_args = ['branch', 'file'] |
|
71 |
takes_options = ['no-collapse', 'no-antialias', 'merge-branch', 'cluster'] |
|
72 |
def run(self, branch, file, no_collapse=False, no_antialias=False, |
|
73 |
merge_branch=None, cluster=False): |
|
74 |
import graph |
|
75 |
if cluster: |
|
76 |
ranking = "cluster" |
|
77 |
else: |
|
78 |
ranking = "forced" |
|
79 |
graph.write_ancestry_file(branch, file, not no_collapse, |
|
80 |
not no_antialias, merge_branch, ranking) |
|
81 |
||
82 |
class cmd_fetch_ghosts(bzrlib.commands.Command): |
|
83 |
"""Attempt to retrieve ghosts from another branch.
|
|
84 |
If the other branch is not supplied, the last-pulled branch is used.
|
|
85 |
"""
|
|
86 |
aliases = ['fetch-missing'] |
|
87 |
takes_args = ['branch?'] |
|
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 |
88 |
takes_options = [Option('no-fix')] |
89 |
def run(self, branch=None, no_fix=False): |
|
246
by Aaron Bentley
Merged shelf_v2 |
90 |
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 |
91 |
fetch_ghosts(branch, no_fix) |
246
by Aaron Bentley
Merged shelf_v2 |
92 |
|
93 |
strip_help="""Strip the smallest prefix containing num leading slashes from \ |
|
94 |
each file name found in the patch file."""
|
|
95 |
Option.OPTIONS['strip'] = Option('strip', type=int, help=strip_help) |
|
96 |
class cmd_patch(bzrlib.commands.Command): |
|
97 |
"""Apply a named patch to the current tree.
|
|
98 |
"""
|
|
99 |
takes_args = ['filename?'] |
|
100 |
takes_options = ['strip'] |
|
101 |
def run(self, filename=None, strip=0): |
|
102 |
from patch import patch |
|
103 |
from bzrlib.branch import Branch |
|
104 |
b = Branch.open_containing('.')[0] |
|
105 |
return patch(b, filename, strip) |
|
106 |
||
0.1.22
by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there. |
107 |
|
108 |
class cmd_shelve(bzrlib.commands.Command): |
|
109 |
"""Temporarily remove some changes from the current tree.
|
|
110 |
Use 'unshelve' to restore these changes.
|
|
111 |
||
112 |
If filenames are specified, only changes to those files will be unshelved.
|
|
113 |
If a revision is specified, all changes since that revision will may be
|
|
114 |
unshelved.
|
|
115 |
"""
|
|
116 |
takes_args = ['file*'] |
|
0.1.28
by Michael Ellerman
Implement "bzr shelve --all". |
117 |
takes_options = ['all', 'message', 'revision'] |
118 |
def run(self, all=False, file_list=None, message=None, revision=None): |
|
0.1.39
by Michael Ellerman
Fix shelve and unshelve to pass location to Shelf(). |
119 |
if file_list is not None and len(file_list) > 0: |
120 |
branchdir = file_list[0] |
|
121 |
else: |
|
122 |
branchdir = '.' |
|
123 |
||
0.1.22
by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there. |
124 |
if revision is not None and revision: |
0.1.39
by Michael Ellerman
Fix shelve and unshelve to pass location to Shelf(). |
125 |
if len(revision) == 1: |
126 |
revision = revision[0] |
|
0.1.22
by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there. |
127 |
else: |
0.1.39
by Michael Ellerman
Fix shelve and unshelve to pass location to Shelf(). |
128 |
raise BzrCommandError("shelve only accepts a single revision " |
129 |
"parameter.") |
|
0.1.22
by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there. |
130 |
|
0.1.39
by Michael Ellerman
Fix shelve and unshelve to pass location to Shelf(). |
131 |
s = Shelf(branchdir) |
132 |
return s.shelve(all, message, revision, file_list) |
|
0.1.22
by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there. |
133 |
|
246
by Aaron Bentley
Merged shelf_v2 |
134 |
|
0.1.22
by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there. |
135 |
class cmd_unshelve(bzrlib.commands.Command): |
136 |
"""Restore previously-shelved changes to the current tree.
|
|
137 |
See also 'shelve'.
|
|
138 |
"""
|
|
139 |
def run(self): |
|
0.1.39
by Michael Ellerman
Fix shelve and unshelve to pass location to Shelf(). |
140 |
s = Shelf('.') |
282
by Aaron Bentley
Fixed unshelve return code |
141 |
return s.unshelve() |
0.1.22
by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there. |
142 |
|
249
by Aaron Bentley
Got the shell basics working properly |
143 |
class cmd_shell(bzrlib.commands.Command): |
144 |
def run(self): |
|
145 |
import shell |
|
281
by Aaron Bentley
Handled whitespace branch names better |
146 |
return shell.run_shell() |
246
by Aaron Bentley
Merged shelf_v2 |
147 |
|
148 |
commands = [cmd_shelve, cmd_unshelve, cmd_clean_tree, cmd_graph_ancestry, |
|
277
by Aaron Bentley
Renamed force-reweave-inventory to fix |
149 |
cmd_fetch_ghosts, cmd_patch, cmd_shell, cmd_fix] |
246
by Aaron Bentley
Merged shelf_v2 |
150 |
|
271
by Aaron Bentley
Cherry-picked Robert's diff and push fixes |
151 |
command_decorators = [] |
152 |
||
246
by Aaron Bentley
Merged shelf_v2 |
153 |
import bzrlib.builtins |
154 |
if not hasattr(bzrlib.builtins, "cmd_annotate"): |
|
155 |
commands.append(annotate.cmd_annotate) |
|
156 |
if not hasattr(bzrlib.builtins, "cmd_push"): |
|
157 |
commands.append(push.cmd_push) |
|
271
by Aaron Bentley
Cherry-picked Robert's diff and push fixes |
158 |
else: |
159 |
command_decorators.append(push.cmd_push) |
|
246
by Aaron Bentley
Merged shelf_v2 |
160 |
|
161 |
from errors import NoPyBaz |
|
162 |
try: |
|
163 |
import baz_import |
|
164 |
commands.append(baz_import.cmd_baz_import) |
|
165 |
||
166 |
except NoPyBaz: |
|
167 |
class cmd_baz_import(bzrlib.commands.Command): |
|
168 |
"""Disabled. (Requires PyBaz)"""
|
|
169 |
takes_args = ['to_root_dir?', 'from_archive?'] |
|
170 |
takes_options = ['verbose'] |
|
171 |
def run(self, to_root_dir=None, from_archive=None, verbose=False): |
|
172 |
print "This command is disabled. Please install PyBaz." |
|
173 |
commands.append(cmd_baz_import) |
|
174 |
||
271
by Aaron Bentley
Cherry-picked Robert's diff and push fixes |
175 |
|
246
by Aaron Bentley
Merged shelf_v2 |
176 |
if hasattr(bzrlib.commands, 'register_command'): |
177 |
for command in commands: |
|
178 |
bzrlib.commands.register_command(command) |
|
271
by Aaron Bentley
Cherry-picked Robert's diff and push fixes |
179 |
for command in command_decorators: |
180 |
command._original_command = bzrlib.commands.register_command( |
|
181 |
command, True) |
|
182 |
||
0.1.29
by Michael Ellerman
Add basic tests for shelve --all, and unshelve. |
183 |
|
184 |
def test_suite(): |
|
246
by Aaron Bentley
Merged shelf_v2 |
185 |
from doctest import DocTestSuite |
186 |
from unittest import TestSuite, TestLoader |
|
187 |
import clean_tree |
|
188 |
import blackbox |
|
247
by Aaron Bentley
Renamed tests.py to shelf_tests.py |
189 |
import shelf_tests |
246
by Aaron Bentley
Merged shelf_v2 |
190 |
result = TestSuite() |
191 |
result.addTest(DocTestSuite(bzrtools)) |
|
192 |
result.addTest(clean_tree.test_suite()) |
|
247
by Aaron Bentley
Renamed tests.py to shelf_tests.py |
193 |
result.addTest(TestLoader().loadTestsFromModule(shelf_tests)) |
246
by Aaron Bentley
Merged shelf_v2 |
194 |
result.addTest(blackbox.test_suite()) |
195 |
return result |