Mercurial > hg
changeset 24140:5a64b676c5d3
histedit: extract method ruleeditor
Extract functionality of editing histedit rules to separate method so we can
reuse it in upcoming --edit-plan option.
author | Mateusz Kwapich <mitrandir@fb.com> |
---|---|
date | Mon, 23 Feb 2015 10:57:27 -0800 |
parents | 73b3218bb078 |
children | 671da7d34804 |
files | hgext/histedit.py |
diffstat | 1 files changed, 22 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/histedit.py Tue Feb 24 11:37:07 2015 -0500 +++ b/hgext/histedit.py Mon Feb 23 10:57:27 2015 -0800 @@ -642,16 +642,9 @@ ctxs = [repo[r] for r in revs] if not rules: - rules = '\n'.join([makedesc(c) for c in ctxs]) - rules += '\n\n' - rules += editcomment % (node.short(root), node.short(topmost)) - rules = ui.edit(rules, ui.username()) - # Save edit rules in .hg/histedit-last-edit.txt in case - # the user needs to ask for help after something - # surprising happens. - f = open(repo.join('histedit-last-edit.txt'), 'w') - f.write(rules) - f.close() + rules = ruleeditor(repo, ui, [['pick', c] for c in ctxs], + editcomment=editcomment % (node.short(root), + node.short(topmost))) else: if rules == '-': f = sys.stdin @@ -826,6 +819,25 @@ # trim to 80 columns so it's not stupidly wide in my editor return util.ellipsis(line, 80) +def ruleeditor(repo, ui, rules, editcomment=""): + """open an editor to edit rules + + rules are in the format [ [act, ctx], ...] like in state.rules + """ + rules = '\n'.join([makedesc(repo[rev]) for [act, rev] in rules]) + rules += '\n\n' + rules += editcomment + rules = ui.edit(rules, ui.username()) + + # Save edit rules in .hg/histedit-last-edit.txt in case + # the user needs to ask for help after something + # surprising happens. + f = open(repo.join('histedit-last-edit.txt'), 'w') + f.write(rules) + f.close() + + return rules + def verifyrules(rules, repo, ctxs): """Verify that there exists exactly one edit rule per given changeset.