Patchwork [1,of,3] histeditrule: split __str__ property into prefix and desc

login
register
mail settings
Submitter Jordi Gutiérrez Hermoso
Date Nov. 7, 2019, 8:31 p.m.
Message ID <45aea2365bcb5f89d20b.1573158706@chloe>
Download mbox | patch
Permalink /patch/42906/
State New
Headers show

Comments

Jordi Gutiérrez Hermoso - Nov. 7, 2019, 8:31 p.m.
# HG changeset patch
# User Jordi Gutiérrez Hermoso <jordigh@octave.org>
# Date 1572478029 14400
#      Wed Oct 30 19:27:09 2019 -0400
# Node ID 45aea2365bcb5f89d20bb1907d75175246da3d05
# Parent  ab9b0a20b9e6b7f1f16f643486ff20a6d44ca2d5
histeditrule: split __str__ property into prefix and desc

In order to be able to colourise the description of the rule, we need
to have it as a separate string. Curses doesn't make it easy to take
existing text on the screen and give it different properties; we can
only add new text with new properties.
Yuya Nishihara - Nov. 9, 2019, 2:05 a.m.
On Thu, 07 Nov 2019 15:31:46 -0500, Jordi Gutiérrez Hermoso wrote:
> # HG changeset patch
> # User Jordi Gutiérrez Hermoso <jordigh@octave.org>
> # Date 1572478029 14400
> #      Wed Oct 30 19:27:09 2019 -0400
> # Node ID 45aea2365bcb5f89d20bb1907d75175246da3d05
> # Parent  ab9b0a20b9e6b7f1f16f643486ff20a6d44ca2d5
> histeditrule: split __str__ property into prefix and desc


>          # The carets point to the changeset being folded into ("roll this
>          # changeset into the changeset above").
> +        return b'{}{}'.format(self.prefix, self.desc)

Use printf-style formatting. b''.format() doesn't work on Python 3.

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -1119,33 +1119,43 @@  class histeditrule(object):
         self.conflicts = []
 
     def __bytes__(self):
-        # Some actions ('fold' and 'roll') combine a patch with a previous one.
-        # Add a marker showing which patch they apply to, and also omit the
-        # description for 'roll' (since it will get discarded). Example display:
+        # Example display of several histeditrules:
         #
         #  #10 pick   316392:06a16c25c053   add option to skip tests
-        #  #11 ^roll  316393:71313c964cc5
+        #  #11 ^roll  316393:71313c964cc5   <RED>oops a fixup commit</RED>
         #  #12 pick   316394:ab31f3973b0d   include mfbt for mozilla-config.h
         #  #13 ^fold  316395:14ce5803f4c3   fix warnings
         #
         # The carets point to the changeset being folded into ("roll this
         # changeset into the changeset above").
+        return b'{}{}'.format(self.prefix, self.desc)
+
+    @property
+    def prefix(self):
+        # Some actions ('fold' and 'roll') combine a patch with a
+        # previous one. Add a marker showing which patch they apply
+        # to.
         action = ACTION_LABELS.get(self.action, self.action)
+
         h = self.ctx.hex()[0:12]
         r = self.ctx.rev()
-        desc = self.ctx.description().splitlines()[0].strip()
-        if self.action == b'roll':
-            desc = b''
-        return b"#%s %s %d:%s   %s" % (
+
+        return b"#%s %s %d:%s   " % (
             (b'%d' % self.origpos).ljust(2),
             action.ljust(6),
             r,
-            h,
-            desc,
+            h
         )
 
     __str__ = encoding.strmethod(__bytes__)
 
+    @property
+    def desc(self):
+        # This is split off from the prefix property so that we can
+        # separately make the description for 'roll' red (since it
+        # will get discarded).
+        return self.ctx.description().splitlines()[0].strip()
+
     def checkconflicts(self, other):
         if other.pos > self.pos and other.origpos <= self.origpos:
             if set(other.ctx.files()) & set(self.ctx.files()) != set():