comparison mercurial/commands.py @ 18689:12721a20ed30

backout: call cmdutil.commit directly instead of commands.commit This cleans up the messiness of having one command call another, and makes the backout command robust against changes to the commit command.
author Kevin Bullock <kbullock@ringworld.org>
date Tue, 12 Feb 2013 16:36:44 +0000
parents 79107fad06aa
children 5bef0655f2e9
comparison
equal deleted inserted replaced
18688:79107fad06aa 18689:12721a20ed30
454 454
455 # the backout should appear on the same branch 455 # the backout should appear on the same branch
456 wlock = repo.wlock() 456 wlock = repo.wlock()
457 try: 457 try:
458 branch = repo.dirstate.branch() 458 branch = repo.dirstate.branch()
459 bheads = repo.branchheads(branch)
459 hg.clean(repo, node, show_stats=False) 460 hg.clean(repo, node, show_stats=False)
460 repo.dirstate.setbranch(branch) 461 repo.dirstate.setbranch(branch)
461 rctx = scmutil.revsingle(repo, hex(parent)) 462 rctx = scmutil.revsingle(repo, hex(parent))
462 cmdutil.revert(ui, repo, rctx, repo.dirstate.parents()) 463 cmdutil.revert(ui, repo, rctx, repo.dirstate.parents())
463 if not opts.get('merge') and op1 != node: 464 if not opts.get('merge') and op1 != node:
465 ui.setconfig('ui', 'forcemerge', opts.get('tool', '')) 466 ui.setconfig('ui', 'forcemerge', opts.get('tool', ''))
466 return hg.update(repo, op1) 467 return hg.update(repo, op1)
467 finally: 468 finally:
468 ui.setconfig('ui', 'forcemerge', '') 469 ui.setconfig('ui', 'forcemerge', '')
469 470
471 e = cmdutil.commiteditor
470 if not opts['message'] and not opts['logfile']: 472 if not opts['message'] and not opts['logfile']:
471 # we don't translate commit messages 473 # we don't translate commit messages
472 opts['message'] = "Backed out changeset %s" % short(node) 474 opts['message'] = "Backed out changeset %s" % short(node)
473 opts['force_editor'] = True 475 e = cmdutil.commitforceeditor
474 commit(ui, repo, **opts) 476
477 def commitfunc(ui, repo, message, match, opts):
478 return repo.commit(message, opts.get('user'), opts.get('date'),
479 match, editor=e)
480 newnode = cmdutil.commit(ui, repo, commitfunc, [], opts)
481 cmdutil.commitstatus(repo, newnode, branch, bheads)
475 482
476 def nice(node): 483 def nice(node):
477 return '%d:%s' % (repo.changelog.rev(node), short(node)) 484 return '%d:%s' % (repo.changelog.rev(node), short(node))
478 ui.status(_('changeset %s backs out changeset %s\n') % 485 ui.status(_('changeset %s backs out changeset %s\n') %
479 (nice(repo.changelog.tip()), nice(node))) 486 (nice(repo.changelog.tip()), nice(node)))