Mercurial > hg
comparison hgext/histedit.py @ 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 | a2d869e22b5e |
children | 671da7d34804 |
comparison
equal
deleted
inserted
replaced
24139:73b3218bb078 | 24140:5a64b676c5d3 |
---|---|
640 raise util.Abort(_('%s is not an ancestor of working directory') % | 640 raise util.Abort(_('%s is not an ancestor of working directory') % |
641 node.short(root)) | 641 node.short(root)) |
642 | 642 |
643 ctxs = [repo[r] for r in revs] | 643 ctxs = [repo[r] for r in revs] |
644 if not rules: | 644 if not rules: |
645 rules = '\n'.join([makedesc(c) for c in ctxs]) | 645 rules = ruleeditor(repo, ui, [['pick', c] for c in ctxs], |
646 rules += '\n\n' | 646 editcomment=editcomment % (node.short(root), |
647 rules += editcomment % (node.short(root), node.short(topmost)) | 647 node.short(topmost))) |
648 rules = ui.edit(rules, ui.username()) | |
649 # Save edit rules in .hg/histedit-last-edit.txt in case | |
650 # the user needs to ask for help after something | |
651 # surprising happens. | |
652 f = open(repo.join('histedit-last-edit.txt'), 'w') | |
653 f.write(rules) | |
654 f.close() | |
655 else: | 648 else: |
656 if rules == '-': | 649 if rules == '-': |
657 f = sys.stdin | 650 f = sys.stdin |
658 else: | 651 else: |
659 f = open(rules) | 652 f = open(rules) |
823 if c.description(): | 816 if c.description(): |
824 summary = c.description().splitlines()[0] | 817 summary = c.description().splitlines()[0] |
825 line = 'pick %s %d %s' % (c, c.rev(), summary) | 818 line = 'pick %s %d %s' % (c, c.rev(), summary) |
826 # trim to 80 columns so it's not stupidly wide in my editor | 819 # trim to 80 columns so it's not stupidly wide in my editor |
827 return util.ellipsis(line, 80) | 820 return util.ellipsis(line, 80) |
821 | |
822 def ruleeditor(repo, ui, rules, editcomment=""): | |
823 """open an editor to edit rules | |
824 | |
825 rules are in the format [ [act, ctx], ...] like in state.rules | |
826 """ | |
827 rules = '\n'.join([makedesc(repo[rev]) for [act, rev] in rules]) | |
828 rules += '\n\n' | |
829 rules += editcomment | |
830 rules = ui.edit(rules, ui.username()) | |
831 | |
832 # Save edit rules in .hg/histedit-last-edit.txt in case | |
833 # the user needs to ask for help after something | |
834 # surprising happens. | |
835 f = open(repo.join('histedit-last-edit.txt'), 'w') | |
836 f.write(rules) | |
837 f.close() | |
838 | |
839 return rules | |
828 | 840 |
829 def verifyrules(rules, repo, ctxs): | 841 def verifyrules(rules, repo, ctxs): |
830 """Verify that there exists exactly one edit rule per given changeset. | 842 """Verify that there exists exactly one edit rule per given changeset. |
831 | 843 |
832 Will abort if there are to many or too few rules, a malformed rule, | 844 Will abort if there are to many or too few rules, a malformed rule, |