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

login
register
mail settings
Submitter Jordi Gutiérrez Hermoso
Date Nov. 14, 2019, 7:58 p.m.
Message ID <0ad29bd65ab45822e2e2.1573761503@chloe>
Download mbox | patch
Permalink /patch/43188/
State Accepted
Headers show

Comments

Jordi Gutiérrez Hermoso - Nov. 14, 2019, 7:58 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 0ad29bd65ab45822e2e2a6630860269832aca2fe
# Parent  ab9b0a20b9e6b7f1f16f643486ff20a6d44ca2d5
histeditrule: split __bytes__ 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 bytestring. 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. 15, 2019, 11:58 a.m.
On Thu, 14 Nov 2019 14:58:23 -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 0ad29bd65ab45822e2e2a6630860269832aca2fe
> # Parent  ab9b0a20b9e6b7f1f16f643486ff20a6d44ca2d5
> histeditrule: split __bytes__ property into prefix and desc

Queued, thanks.

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -1119,32 +1119,42 @@  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'%s%s' % (self.prefix, self.desc)
+
+    __str__ = encoding.strmethod(__bytes__)
+
+    @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: