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
|
#!/usr/bin/python
"""Shelf - temporarily set aside changes, then bring them back."""
import bzrlib.commands
from errors import CommandError
from bzrlib.option import Option
from patchsource import BzrPatchSource
from shelf import Shelf
from bzrlib import DEFAULT_IGNORE
from bzrlib.help import command_usage
DEFAULT_IGNORE.append('./.shelf')
DEFAULT_IGNORE.append('./.bzr-shelf*')
class cmd_shelve(bzrlib.commands.Command):
"""Temporarily set aside some changes from the current tree.
Shelve allows you to temporarily put changes you've made "on the shelf",
ie. out of the way, until a later time when you can bring them back from
the shelf with the 'unshelve' command.
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.
By default shelve asks you what you want to shelve, press '?' at the
prompt to get help. To shelve everything run shelve --all.
You can put multiple items on the shelf, each time you run unshelve the
most recently shelved changes will be reinstated.
If filenames are specified, only the changes to those files will be
shelved, other files will be left untouched.
If a revision is specified, changes since that revision will be shelved.
"""
takes_args = ['file*']
takes_options = ['message', 'revision',
Option('all', help='Shelve all changes without prompting')]
def run(self, all=False, file_list=None, message=None, revision=None):
if revision is not None and revision:
if len(revision) == 1:
revision = revision[0]
else:
raise CommandError("shelve only accepts a single revision "
"parameter.")
source = BzrPatchSource(revision, file_list)
s = Shelf(source.base)
s.shelve(source, all, message)
return 0
# The following classes are only used as subcommands for 'shelf', they're
# not to be registered directly with bzr.
class cmd_shelf_list(bzrlib.commands.Command):
"""List the patches on the current shelf."""
aliases = ['list', 'ls']
def run(self):
self.shelf.list()
class cmd_shelf_delete(bzrlib.commands.Command):
"""Delete the patch from the current shelf."""
aliases = ['delete', 'del']
takes_args = ['patch']
def run(self, patch):
self.shelf.delete(patch)
class cmd_shelf_switch(bzrlib.commands.Command):
"""Switch to the other shelf, create it if necessary."""
aliases = ['switch']
takes_args = ['other-shelf']
def run(self, other_shelf):
s = Shelf(self.shelf.base, other_shelf)
s.make_default()
class cmd_shelf_show(bzrlib.commands.Command):
"""Show the contents of the specified or topmost patch."""
aliases = ['show', 'cat', 'display']
takes_args = ['patch?']
def run(self, patch=None):
self.shelf.display(patch)
class cmd_shelf_upgrade(bzrlib.commands.Command):
"""Upgrade old format shelves."""
aliases = ['upgrade']
def run(self):
self.shelf.upgrade()
class cmd_shelf(bzrlib.commands.Command):
"""Perform various operations on your shelved patches. See also shelve."""
takes_args = ['subcommand', 'args*']
subcommands = [cmd_shelf_list, cmd_shelf_delete, cmd_shelf_switch,
cmd_shelf_show, cmd_shelf_upgrade]
def run(self, subcommand, args_list):
import sys
cmd = self._get_cmd_object(subcommand)
source = BzrPatchSource()
s = Shelf(source.base)
cmd.shelf = s
return cmd.run_argv_aliases(args_list)
def _get_cmd_object(self, cmd_name):
for cmd_class in self.subcommands:
for alias in cmd_class.aliases:
if alias == cmd_name:
return cmd_class()
raise CommandError("Unknown shelf subcommand '%s'" % cmd_name)
def help(self):
text = ["%s\n\nSubcommands:\n" % self.__doc__]
for cmd_class in self.subcommands:
text.extend(self.sub_help(cmd_class) + ['\n'])
return ''.join(text)
def sub_help(self, cmd_class):
text = []
cmd_obj = cmd_class()
indent = 2 * ' '
usage = command_usage(cmd_obj)
usage = usage.replace('bzr shelf-', '')
text.append('%s%s\n' % (indent, usage))
text.append('%s%s\n' % (2 * indent, cmd_class.__doc__))
# Somewhat copied from bzrlib.help.help_on_command_options
option_help = []
for option_name, option in sorted(cmd_obj.options().items()):
if option_name == 'help':
continue
option_help.append('%s--%s' % (3 * indent, option_name))
if option.type is not None:
option_help.append(' %s' % option.argname.upper())
if option.short_name():
option_help.append(', -%s' % option.short_name())
option_help.append('%s%s\n' % (2 * indent, option.help))
if len(option_help) > 0:
text.append('%soptions:\n' % (2 * indent))
text.extend(option_help)
return text
class cmd_unshelve(bzrlib.commands.Command):
"""Restore the most recently shelved changes to the current tree.
See 'shelve' for more information.
"""
takes_options = [
Option('all', help='Unshelve all changes without prompting'),
Option('force', help='Force unshelving even if errors occur'),
]
def run(self, all=False, force=False):
source = BzrPatchSource()
s = Shelf(source.base)
s.unshelve(source, all, force)
return 0
bzrlib.commands.register_command(cmd_shelf)
bzrlib.commands.register_command(cmd_shelve)
bzrlib.commands.register_command(cmd_unshelve)
def test_suite():
from bzrlib.tests.TestUtil import TestLoader
import tests
return TestLoader().loadTestsFromModule(tests)
|