1
# Copyright (C) 2004 Aaron Bentley
2
# <aaron.bentley@utoronto.ca>
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
sys.path=[os.path.realpath(os.path.dirname(__file__)+"/..")]+sys.path
26
from pylon import errors
31
__docformat__ = "restructuredtext"
32
__doc__ = "Native replay command"
34
def read_changeset(revision):
35
my_dir = pylon.util.tmpdir(os.getcwd())
36
changeset = revision.get_patch(my_dir)
37
real = pylon.read_arch_changeset(changeset)
42
def __init__(self, tree, reverse, munge_opts):
44
self.reverse = reverse
45
self.munge_opts = munge_opts
46
self.last_changeset = None
48
def handle_revision(self, revision):
49
if self.last_changeset is None:
50
cmdutil.chatter("Reading %s" % str(revision))
51
self.last_changeset = read_changeset(revision)
53
cmdutil.chatter("Combining with %s" % str(revision))
54
next_changeset = read_changeset(revision)
55
self.last_changeset = pylon.compose_changesets(self.last_changeset,
61
if self.last_changeset is None:
63
cmdutil.chatter("Applying changeset")
64
inventory = pylon.get_id_filename_map(self.tree)
65
pylon.add_inventory_missing(inventory, self.last_changeset,
67
pylon.apply_changeset(self.last_changeset, inventory, self.tree,
68
pylon.ArchConflictHandler(self.tree),
72
class ApplyNativeHandler:
73
def __init__(self, tree, reverse, munge_opts):
75
self.reverse = reverse
76
self.did_nothing = True
77
self.munge_opts = munge_opts
79
def handle_revision(self, revision):
80
self.did_nothing = False
81
cmdutil.chatter("Applying %s" % str(revision))
82
self.last_changeset = read_changeset(revision)
83
inventory = pylon.get_id_filename_map(self.tree)
84
pylon.add_inventory_missing(inventory, self.last_changeset,
86
conflict_handler = pylon.ArchConflictHandler(self.tree)
87
pylon.apply_changeset(self.last_changeset, inventory, self.tree,
88
conflict_handler, self.reverse)
89
if conflict_handler.stop_conflicts:
95
return not self.did_nothing
98
def __init__(self, tree, reverse, munge_opts):
100
self.reverse = reverse
101
self.did_nothing = True
102
self.munge_opts = munge_opts
104
def handle_revision(self, revision):
105
self.did_nothing = False
106
cmdutil.chatter("Applying %s" % str(revision))
107
result = pylon.replay(self.tree, revision, cmdutil.colorize,
108
reverse=self.reverse, munge_opts=self.munge_opts)
112
return not self.did_nothing
114
class Replay(commands.BaseCommand):
115
"""Apply a revision's changeset to the current tree"""
117
self.description = self.__doc__
119
def get_completer(self, arg, index):
120
return cmdutil.merge_completions(arch.tree_root("."), arg, index)
122
def do_command(self, cmdargs):
124
tree = arch.tree_root(".")
125
except arch.errors.TreeRootError, e:
126
raise errors.CommandFailedWrapper(e)
128
parser = self.get_parser()
129
(options, args) = parser.parse_args(cmdargs)
130
action = options.type
131
if action == "default":
132
action = "skip-present"
134
if options.logs_only:
135
munge_opts = pylon.MungeOpts()
136
munge_opts.all_types(True)
137
munge_opts.add_keep_pattern('^\./\{arch\}/[^=].*')
144
if munge_opts is not None or action == "skip-conflicts":
145
revision_handler = ApplyHandler(tree, options.reverse, munge_opts)
147
revision_handler = options.method(tree, options.reverse, munge_opts)
148
if isinstance(revision_handler, ComposeHandler):
150
options.reverse_list = not options.reverse_list
154
if options.type == "default" and arg is not None:
155
result = cmdutil.determine_version_revision_tree(arg, tree)
156
if isinstance(result, arch.Revision):
158
if revisions == None:
159
revisions = cmdutil.revision_iterator(tree, action, [arg],
160
options.reverse_list,
163
for revision in revisions:
164
if isinstance(revision, arch.Patchlog):
165
revision = revision.revision
166
cmdutil.ensure_archive_registered(revision.archive)
167
status = revision_handler.handle_revision(revision)
170
if not revision_handler.finalize():
171
cmdutil.chatter("Tree is already up to date")
174
def get_parser(self):
175
parser = cmdutil.CmdOptionParser("fai revisions [revision]")
176
select = cmdutil.OptionGroup(parser, "Selection options",
177
"Control which revisions are applied. These options"
178
" are mutually exclusive. If more than one is"
179
" specified, the last is used.")
180
cmdutil.add_revision_iter_options(select)
181
select.add_option("--skip-conflicts", action="store_const",
182
const="skip-conflicts", dest="type",
183
help="Revisions that can be applied without"
184
"producing conflicts")
186
parser.add_option_group(select)
187
parser.add_option("-r", "--reverse", action="store_true",
188
dest="reverse", help="Apply changeset(s) in reverse")
189
parser.add_option("--reverse-list", action="store_true",
191
help="Apply revisions in reverse order")
192
parser.add_option("--patch-logs-only", action="store_true",
194
help="Apply log changes only")
195
native = "read_arch_changeset" in dir(pylon)
196
parser.set_defaults(method=ApplyHandler)
198
parser.add_option("--native", action="store_const", dest="method",
199
help="Use native changeset method",
200
const=ApplyNativeHandler)
201
parser.add_option("--combine", action="store_const", dest="method",
202
help="Combine changesets before applying",
203
const=ComposeHandler)
205
def help(self, parser=None):
207
Prints a help message.
209
:param parser: If supplied, the parser to use for generating help. If \
210
not supplied, it is retrieved.
211
:type parser: cmdutil.CmdOptionParser
214
parser=self.get_parser()
218
def add_command(commands):
219
commands["replay"] = Replay
221
# arch-tag: cd6b5159-30ee-410b-8ad4-7437b75f98cd