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 |
from shelf import Shelf |
|
8 |
import sys |
|
9 |
import os.path |
|
10 |
from bzrlib.option import Option |
|
0.1.22
by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there. |
11 |
import bzrlib.branch |
0.1.39
by Michael Ellerman
Fix shelve and unshelve to pass location to Shelf(). |
12 |
from bzrlib.errors import BzrCommandError |
246
by Aaron Bentley
Merged shelf_v2 |
13 |
sys.path.append(os.path.dirname(__file__)) |
277
by Aaron Bentley
Renamed force-reweave-inventory to fix |
14 |
from reweave_inventory import cmd_fix |
246
by Aaron Bentley
Merged shelf_v2 |
15 |
|
16 |
Option.OPTIONS['ignored'] = Option('ignored', |
|
17 |
help='delete all ignored files.') |
|
265
by Aaron Bentley
Fixed spelling of detritus |
18 |
Option.OPTIONS['detritus'] = Option('detritus', |
246
by Aaron Bentley
Merged shelf_v2 |
19 |
help='delete conflict files merge backups, and failed selftest dirs.' + |
20 |
'(*.THIS, *.BASE, *.OTHER, *~, *.tmp') |
|
21 |
Option.OPTIONS['dry-run'] = Option('dry-run', |
|
22 |
help='show files to delete instead of deleting them.') |
|
23 |
||
24 |
class cmd_clean_tree(bzrlib.commands.Command): |
|
25 |
"""Remove unwanted files from working tree.
|
|
26 |
Normally, ignored files are left alone.
|
|
27 |
"""
|
|
265
by Aaron Bentley
Fixed spelling of detritus |
28 |
takes_options = ['ignored', 'detritus', 'dry-run'] |
29 |
def run(self, ignored=False, detritus=False, dry_run=False): |
|
246
by Aaron Bentley
Merged shelf_v2 |
30 |
from clean_tree import clean_tree |
265
by Aaron Bentley
Fixed spelling of detritus |
31 |
clean_tree('.', ignored=ignored, detritus=detritus, dry_run=dry_run) |
246
by Aaron Bentley
Merged shelf_v2 |
32 |
|
33 |
Option.OPTIONS['merge-branch'] = Option('merge-branch',type=str) |
|
34 |
||
35 |
class cmd_graph_ancestry(bzrlib.commands.Command): |
|
36 |
"""Produce ancestry graphs using dot.
|
|
37 |
|
|
38 |
Output format is detected according to file extension. Some of the more
|
|
296
by Aaron Bentley
Updated graph-ancestry help |
39 |
common output formats are html, png, gif, svg, ps. An extension of '.dot'
|
40 |
will cause a dot graph file to be produced. HTML output has mouseovers
|
|
41 |
that show the commit message.
|
|
246
by Aaron Bentley
Merged shelf_v2 |
42 |
|
43 |
Branches are labeled r?, where ? is the revno. If they have no revno,
|
|
44 |
with the last 5 characters of their revision identifier are used instead.
|
|
296
by Aaron Bentley
Updated graph-ancestry help |
45 |
|
46 |
The value starting with d is "(maximum) distance from the null revision".
|
|
246
by Aaron Bentley
Merged shelf_v2 |
47 |
|
48 |
If --merge-branch is specified, the two branches are compared and a merge
|
|
49 |
base is selected.
|
|
50 |
|
|
51 |
Legend:
|
|
52 |
white normal revision
|
|
53 |
yellow THIS history
|
|
54 |
red OTHER history
|
|
55 |
orange COMMON history
|
|
56 |
blue COMMON non-history ancestor
|
|
296
by Aaron Bentley
Updated graph-ancestry help |
57 |
green Merge base (COMMON ancestor farthest from the null revision)
|
58 |
dotted Ghost revision (missing from branch storage)
|
|
246
by Aaron Bentley
Merged shelf_v2 |
59 |
|
296
by Aaron Bentley
Updated graph-ancestry help |
60 |
Ancestry is usually collapsed by skipping revisions with a single parent
|
246
by Aaron Bentley
Merged shelf_v2 |
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'] |
|
296
by Aaron Bentley
Updated graph-ancestry help |
71 |
takes_options = [Option('no-collapse', help="Do not skip simple nodes"), |
72 |
Option('no-antialias', |
|
73 |
help="Do not use rsvg to produce antialiased output"), |
|
74 |
Option('merge-branch', type=str, |
|
75 |
help="Use this branch to calcuate a merge base"), |
|
76 |
Option('cluster', help="Use clustered output.")] |
|
246
by Aaron Bentley
Merged shelf_v2 |
77 |
def run(self, branch, file, no_collapse=False, no_antialias=False, |
78 |
merge_branch=None, cluster=False): |
|
79 |
import graph |
|
80 |
if cluster: |
|
81 |
ranking = "cluster" |
|
82 |
else: |
|
83 |
ranking = "forced" |
|
84 |
graph.write_ancestry_file(branch, file, not no_collapse, |
|
85 |
not no_antialias, merge_branch, ranking) |
|
86 |
||
87 |
class cmd_fetch_ghosts(bzrlib.commands.Command): |
|
88 |
"""Attempt to retrieve ghosts from another branch.
|
|
89 |
If the other branch is not supplied, the last-pulled branch is used.
|
|
90 |
"""
|
|
91 |
aliases = ['fetch-missing'] |
|
92 |
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 |
93 |
takes_options = [Option('no-fix')] |
94 |
def run(self, branch=None, no_fix=False): |
|
246
by Aaron Bentley
Merged shelf_v2 |
95 |
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 |
96 |
fetch_ghosts(branch, no_fix) |
246
by Aaron Bentley
Merged shelf_v2 |
97 |
|
98 |
strip_help="""Strip the smallest prefix containing num leading slashes from \ |
|
99 |
each file name found in the patch file."""
|
|
100 |
Option.OPTIONS['strip'] = Option('strip', type=int, help=strip_help) |
|
101 |
class cmd_patch(bzrlib.commands.Command): |
|
102 |
"""Apply a named patch to the current tree.
|
|
103 |
"""
|
|
104 |
takes_args = ['filename?'] |
|
105 |
takes_options = ['strip'] |
|
320
by Aaron Bentley
Updated to match new bzr diff behaviour |
106 |
def run(self, filename=None, strip=1): |
246
by Aaron Bentley
Merged shelf_v2 |
107 |
from patch import patch |
108 |
from bzrlib.branch import Branch |
|
109 |
b = Branch.open_containing('.')[0] |
|
110 |
return patch(b, filename, strip) |
|
111 |
||
0.1.22
by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there. |
112 |
|
113 |
class cmd_shelve(bzrlib.commands.Command): |
|
289
by Aaron Bentley
Updated shelf help |
114 |
"""Temporarily remove some text changes from the current tree.
|
0.1.22
by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there. |
115 |
Use 'unshelve' to restore these changes.
|
116 |
||
289
by Aaron Bentley
Updated shelf help |
117 |
Shelve is intended to help separate several sets of text changes that have
|
118 |
been inappropriately mingled. If you just want to get rid of all changes
|
|
119 |
(text and otherwise) and you don't need to restore them later, use revert.
|
|
120 |
If you want to shelve all text changes at once, use shelve --all.
|
|
121 |
||
122 |
If filenames are specified, only changes to those files will be shelved.
|
|
0.1.22
by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there. |
123 |
If a revision is specified, all changes since that revision will may be
|
289
by Aaron Bentley
Updated shelf help |
124 |
shelved.
|
0.1.22
by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there. |
125 |
"""
|
126 |
takes_args = ['file*'] |
|
289
by Aaron Bentley
Updated shelf help |
127 |
takes_options = [Option('all', |
128 |
help='Shelve all changes without prompting'), |
|
129 |
'message', 'revision'] |
|
0.1.28
by Michael Ellerman
Implement "bzr shelve --all". |
130 |
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(). |
131 |
if file_list is not None and len(file_list) > 0: |
132 |
branchdir = file_list[0] |
|
133 |
else: |
|
134 |
branchdir = '.' |
|
135 |
||
0.1.22
by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there. |
136 |
if revision is not None and revision: |
0.1.39
by Michael Ellerman
Fix shelve and unshelve to pass location to Shelf(). |
137 |
if len(revision) == 1: |
138 |
revision = revision[0] |
|
0.1.22
by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there. |
139 |
else: |
0.1.39
by Michael Ellerman
Fix shelve and unshelve to pass location to Shelf(). |
140 |
raise BzrCommandError("shelve only accepts a single revision " |
141 |
"parameter.") |
|
0.1.22
by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there. |
142 |
|
0.1.39
by Michael Ellerman
Fix shelve and unshelve to pass location to Shelf(). |
143 |
s = Shelf(branchdir) |
144 |
return s.shelve(all, message, revision, file_list) |
|
0.1.22
by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there. |
145 |
|
246
by Aaron Bentley
Merged shelf_v2 |
146 |
|
0.1.22
by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there. |
147 |
class cmd_unshelve(bzrlib.commands.Command): |
148 |
"""Restore previously-shelved changes to the current tree.
|
|
149 |
See also 'shelve'.
|
|
150 |
"""
|
|
151 |
def run(self): |
|
0.1.39
by Michael Ellerman
Fix shelve and unshelve to pass location to Shelf(). |
152 |
s = Shelf('.') |
282
by Aaron Bentley
Fixed unshelve return code |
153 |
return s.unshelve() |
0.1.22
by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there. |
154 |
|
249
by Aaron Bentley
Got the shell basics working properly |
155 |
class cmd_shell(bzrlib.commands.Command): |
287
by Aaron Bentley
Added shell docstring |
156 |
"""Begin an interactive shell tailored for bzr.
|
157 |
Bzr commands can be used without typing bzr first, and will be run natively
|
|
158 |
when possible. Tab completion is tailored for bzr. The shell prompt shows
|
|
159 |
the branch nick, revno, and path.
|
|
160 |
||
161 |
If it encounters any moderately complicated shell command, it will punt to
|
|
162 |
the system shell.
|
|
163 |
||
164 |
Example:
|
|
165 |
$ bzr shell
|
|
166 |
bzr bzrtools:287/> status
|
|
167 |
modified:
|
|
168 |
__init__.py
|
|
169 |
bzr bzrtools:287/> status --[TAB][TAB]
|
|
170 |
--all --help --revision --show-ids
|
|
171 |
bzr bzrtools:287/> status --
|
|
172 |
"""
|
|
249
by Aaron Bentley
Got the shell basics working properly |
173 |
def run(self): |
174 |
import shell |
|
281
by Aaron Bentley
Handled whitespace branch names better |
175 |
return shell.run_shell() |
246
by Aaron Bentley
Merged shelf_v2 |
176 |
|
292
by Aaron Bentley
Introduced branch-history command |
177 |
class cmd_branch_history(bzrlib.commands.Command): |
178 |
"""\
|
|
179 |
Display the revision history with reference to lines of development.
|
|
180 |
||
293
by Aaron Bentley
Updated help |
181 |
Each different committer or branch nick is considered a different line of
|
182 |
development. Committers are treated as the same if they have the same
|
|
183 |
name, or if they have the same email address.
|
|
292
by Aaron Bentley
Introduced branch-history command |
184 |
"""
|
185 |
takes_args = ["branch?"] |
|
186 |
def run(self, branch=None): |
|
187 |
from branchhistory import branch_history |
|
188 |
return branch_history(branch) |
|
189 |
||
246
by Aaron Bentley
Merged shelf_v2 |
190 |
commands = [cmd_shelve, cmd_unshelve, cmd_clean_tree, cmd_graph_ancestry, |
292
by Aaron Bentley
Introduced branch-history command |
191 |
cmd_fetch_ghosts, cmd_patch, cmd_shell, cmd_fix, cmd_branch_history] |
246
by Aaron Bentley
Merged shelf_v2 |
192 |
|
271
by Aaron Bentley
Cherry-picked Robert's diff and push fixes |
193 |
command_decorators = [] |
194 |
||
246
by Aaron Bentley
Merged shelf_v2 |
195 |
import bzrlib.builtins |
196 |
if not hasattr(bzrlib.builtins, "cmd_push"): |
|
197 |
commands.append(push.cmd_push) |
|
271
by Aaron Bentley
Cherry-picked Robert's diff and push fixes |
198 |
else: |
199 |
command_decorators.append(push.cmd_push) |
|
246
by Aaron Bentley
Merged shelf_v2 |
200 |
|
201 |
from errors import NoPyBaz |
|
202 |
try: |
|
203 |
import baz_import |
|
204 |
commands.append(baz_import.cmd_baz_import) |
|
205 |
||
206 |
except NoPyBaz: |
|
207 |
class cmd_baz_import(bzrlib.commands.Command): |
|
208 |
"""Disabled. (Requires PyBaz)"""
|
|
209 |
takes_args = ['to_root_dir?', 'from_archive?'] |
|
210 |
takes_options = ['verbose'] |
|
211 |
def run(self, to_root_dir=None, from_archive=None, verbose=False): |
|
212 |
print "This command is disabled. Please install PyBaz." |
|
213 |
commands.append(cmd_baz_import) |
|
214 |
||
271
by Aaron Bentley
Cherry-picked Robert's diff and push fixes |
215 |
|
246
by Aaron Bentley
Merged shelf_v2 |
216 |
if hasattr(bzrlib.commands, 'register_command'): |
217 |
for command in commands: |
|
218 |
bzrlib.commands.register_command(command) |
|
271
by Aaron Bentley
Cherry-picked Robert's diff and push fixes |
219 |
for command in command_decorators: |
220 |
command._original_command = bzrlib.commands.register_command( |
|
221 |
command, True) |
|
222 |
||
0.1.29
by Michael Ellerman
Add basic tests for shelve --all, and unshelve. |
223 |
|
224 |
def test_suite(): |
|
246
by Aaron Bentley
Merged shelf_v2 |
225 |
from doctest import DocTestSuite |
226 |
from unittest import TestSuite, TestLoader |
|
227 |
import clean_tree |
|
228 |
import blackbox |
|
247
by Aaron Bentley
Renamed tests.py to shelf_tests.py |
229 |
import shelf_tests |
246
by Aaron Bentley
Merged shelf_v2 |
230 |
result = TestSuite() |
231 |
result.addTest(DocTestSuite(bzrtools)) |
|
232 |
result.addTest(clean_tree.test_suite()) |
|
247
by Aaron Bentley
Renamed tests.py to shelf_tests.py |
233 |
result.addTest(TestLoader().loadTestsFromModule(shelf_tests)) |
246
by Aaron Bentley
Merged shelf_v2 |
234 |
result.addTest(blackbox.test_suite()) |
235 |
return result |