[PATCH] histedit: editcomment method to histedit actions
Mateusz Kwapich
mitrandir at fb.com
Tue Dec 8 19:46:10 UTC 2015
# HG changeset patch
# User Mateusz Kwapich <mitrandir at fb.com>
# Date 1449603153 28800
# Tue Dec 08 11:32:33 2015 -0800
# Node ID b7f518564771929ff03a57523fdaba2b8121ac0d
# Parent 93f42371f4b0ebbe28fc93233283f08da788ee26
histedit: editcomment method to histedit actions
Let each action show its own help in histedit editor. The comments
have priorities for sorting purposes.
diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -207,21 +207,6 @@
# leave the attribute unspecified.
testedwith = 'internal'
-# i18n: command names and abbreviations must remain untranslated
-editcomment = _("""# Edit history between %s and %s
-#
-# Commits are listed from least to most recent
-#
-# Commands:
-# p, pick = use commit
-# e, edit = use commit, but stop for amending
-# f, fold = use commit, but combine it with the one above
-# r, roll = like fold, but discard this commit's description
-# d, drop = remove commit from history
-# m, mess = edit commit message without changing commit content
-#
-""")
-
class histeditstate(object):
def __init__(self, repo, parentctxnode=None, actions=None, keep=None,
topmost=None, replacements=None, lock=None, wlock=None):
@@ -445,6 +430,15 @@
return ctx, []
return ctx, [(self.node, (ctx.node(),))]
+ @classmethod
+ def editcomment(self):
+ """Return a help line which will be visible as a coments below initial
+ rules. Your line should <= 78 charactes ("# " will be prepended).
+
+ For example for pick command you can return "p, pick = use commit"
+ """
+ return None
+
def commitfuncfor(repo, src):
"""Build a commit function for the replacement of <src>
@@ -589,6 +583,10 @@
@addhisteditaction(['pick', 'p'])
class pick(histeditaction):
+ @classmethod
+ def editcomment(self):
+ return 10, _("p, pick = use commit")
+
def run(self):
rulectx = self.repo[self.node]
if rulectx.parents()[0].node() == self.state.parentctxnode:
@@ -599,6 +597,10 @@
@addhisteditaction(['edit', 'e'])
class edit(histeditaction):
+ @classmethod
+ def editcomment(self):
+ return 20, _("e, edit = use commit, but stop for amending")
+
def run(self):
repo = self.repo
rulectx = repo[self.node]
@@ -614,6 +616,10 @@
@addhisteditaction(['fold', 'f'])
class fold(histeditaction):
+ @classmethod
+ def editcomment(self):
+ return 30, _("f, fold = use commit, but combine it with the one above")
+
def continuedirty(self):
repo = self.repo
rulectx = repo[self.node]
@@ -733,11 +739,19 @@
when the last fold operation runs we can show the user all the
commit messages in their editor.
"""
+ @classmethod
+ def editcomment(self):
+ return None
+
def skipprompt(self):
return True
@addhisteditaction(["roll", "r"])
class rollup(fold):
+ @classmethod
+ def editcomment(self):
+ return 40, _("r, roll = like fold, but discard this commit's description")
+
def mergedescs(self):
return False
@@ -746,12 +760,20 @@
@addhisteditaction(["drop", "d"])
class drop(histeditaction):
+ @classmethod
+ def editcomment(self):
+ return 50, _("d, drop = remove commit from history")
+
def run(self):
parentctx = self.repo[self.state.parentctxnode]
return parentctx, [(self.node, tuple())]
@addhisteditaction(["mess", "m"])
class message(histeditaction):
+ @classmethod
+ def editcomment(self):
+ return 60, _("m, mess = edit commit message without changing commit content")
+
def commiteditor(self):
return cmdutil.getcommiteditor(edit=True, editform='histedit.mess')
@@ -951,7 +973,7 @@
elif goal == 'edit-plan':
state.read()
if not rules:
- comment = editcomment % (node.short(state.parentctxnode),
+ comment = editcomment(node.short(state.parentctxnode),
node.short(state.topmost))
rules = ruleeditor(repo, ui, state.actions, comment)
else:
@@ -1036,7 +1058,7 @@
ctxs = [repo[r] for r in revs]
if not rules:
- comment = editcomment % (node.short(root), node.short(topmost))
+ comment = editcomment(node.short(root), node.short(topmost))
actions = [pick(state, r) for r in revs]
rules = ruleeditor(repo, ui, actions, comment)
else:
@@ -1157,6 +1179,19 @@
hint=_('see "hg help phases" for details'))
return [c.node() for c in ctxs]
+def editcomment(old, new):
+ pricomments = filter(None, [act.editcomment() for act in actionlist])
+ comments = [comment for (pri, comment) in sorted(pricomments)]
+ return _("""# Edit history between %s and %s
+#
+# Commits are listed from least to most recent
+#
+# Commands:
+%s
+#
+"""
+ ) % (old, new, '\n'.join(["# %s" % c for c in comments]))
+
def ruleeditor(repo, ui, actions, editcomment=""):
"""open an editor to edit rules
More information about the Mercurial-devel
mailing list