[PATCH 4 of 9] histedit: add torule method to histedit action objects

Mateusz Kwapich mitrandir at fb.com
Wed Dec 2 14:22:56 CST 2015


# HG changeset patch
# User Mateusz Kwapich <mitrandir at fb.com>
# Date 1449087541 28800
#      Wed Dec 02 12:19:01 2015 -0800
# Node ID 5fbe77bc94ddd267a65b9a5f4563cf7845053ad0
# Parent  9de112c4ad9af076221545fc36e09e5b13e639be
histedit: add torule method to histedit action objects

To make histedit action objects responsible for understanding
the format of their action lines we are adding a torule method
which for a histedit action will return a string which can be
saved in histedit state or shown in text editor when editing the
plan.

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -359,6 +359,23 @@
             raise error.Abort(_('unknown changeset %s listed')
                               % ha[:12])
 
+    def torule(self):
+        """build a histedit rule line for an action
+
+        by default lines are in the form:
+        <hash> <rev> <summary>
+        """
+        ctx = self.repo[self.node]
+        summary = ''
+        if ctx.description():
+            summary = ctx.description().splitlines()[0]
+        line = '%s %s %d %s' % (self.verb, ctx, ctx.rev(), summary)
+        # trim to 75 columns by default so it's not stupidly wide in my editor
+        # (the 5 more are left for verb)
+        maxlen = self.repo.ui.configint('histedit', 'linelen', default=80)
+        maxlen = max(maxlen, 22) # avoid truncating hash
+        return util.ellipsis(line, maxlen)
+
     def constraints(self):
         """Return a set of constrains that this action should be verified for
         """


More information about the Mercurial-devel mailing list