##// END OF EJS Templates
histedit: add a new histeditaction class...
Durham Goode -
r24765:bdf84cc2 default
parent child Browse files
Show More
@@ -304,6 +304,72 b' class histeditstate(object):'
304 304 def clear(self):
305 305 self.repo.vfs.unlink('histedit-state')
306 306
307 class histeditaction(object):
308 def __init__(self, state, node):
309 self.state = state
310 self.repo = state.repo
311 self.node = node
312
313 @classmethod
314 def fromrule(cls, state, rule):
315 """Parses the given rule, returning an instance of the histeditaction.
316 """
317 repo = state.repo
318 rulehash = rule.strip().split(' ', 1)[0]
319 try:
320 node = repo[rulehash].node()
321 except error.RepoError:
322 raise util.Abort(_('unknown changeset %s listed') % rulehash[:12])
323 return cls(state, node)
324
325 def run(self):
326 """Runs the action. The default behavior is simply apply the action's
327 rulectx onto the current parentctx."""
328 self.applychange()
329 self.continuedirty()
330 return self.continueclean()
331
332 def applychange(self):
333 """Applies the changes from this action's rulectx onto the current
334 parentctx, but does not commit them."""
335 repo = self.repo
336 rulectx = repo[self.node]
337 hg.update(repo, self.state.parentctxnode)
338 stats = applychanges(repo.ui, repo, rulectx, {})
339 if stats and stats[3] > 0:
340 raise error.InterventionRequired(_('Fix up the change and run '
341 'hg histedit --continue'))
342
343 def continuedirty(self):
344 """Continues the action when changes have been applied to the working
345 copy. The default behavior is to commit the dirty changes."""
346 repo = self.repo
347 rulectx = repo[self.node]
348
349 editor = self.commiteditor()
350 commit = commitfuncfor(repo, rulectx)
351
352 commit(text=rulectx.description(), user=rulectx.user(),
353 date=rulectx.date(), extra=rulectx.extra(), editor=editor)
354
355 def commiteditor(self):
356 """The editor to be used to edit the commit message."""
357 return False
358
359 def continueclean(self):
360 """Continues the action when the working copy is clean. The default
361 behavior is to accept the current commit as the new version of the
362 rulectx."""
363 ctx = self.repo['.']
364 if ctx.node() == self.state.parentctxnode:
365 self.repo.ui.warn(_('%s: empty changeset\n') %
366 node.short(self.node))
367 return ctx, [(self.node, tuple())]
368 if ctx.node() == self.node:
369 # Nothing changed
370 return ctx, []
371 return ctx, [(self.node, (ctx.node(),))]
372
307 373 def commitfuncfor(repo, src):
308 374 """Build a commit function for the replacement of <src>
309 375
General Comments 0
You need to be logged in to leave comments. Login now