delta icon indicating copy to clipboard operation
delta copied to clipboard

🚀 Syntax highlight for git patches frontmatter

Open nahharris opened this issue 1 year ago • 7 comments

Delta currently has an amazing support for git patch files (generated with git format-patch). But it would be nice if delta had some level of syntax highlight also in the patch frontmatter just like some terminal text editors do when one's writting a commit.

Fields like Subject, From, Date, etc could be colored with some special color, and also email strings like <[email protected]>

Example

Helix editor: the signed-off-by and other markers in the footer of a commit message are highlighted.

image

nahharris avatar Sep 19 '24 02:09 nahharris

Hi @OJarrisonn, could you post an example plain text snippet that you'd like delta to syntax highlight?

dandavison avatar Sep 19 '24 16:09 dandavison

Sure thing

From git@z Thu Jan  1 00:00:00 1970
Subject: [PATCH v1 1/2] accel-config/test: Add parameter for specifying dev
 and wq
From: Rex Zhang <[email protected]>
Date: Wed, 25 Oct 2023 16:52:58 +0800
Message-Id: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit

About the script iaa_user_test_runner.sh, previously, the only one behavior
is to enable dev and wq firstly than invoke iaa_test, then the iaa_test
will find which dev and wq are enabled automatically.
For enabling the dev and wq outside the script, the script indentify the
enabled dev and wq, then pass the dev and wq into iaa_test as a parameter.

Signed-off-by: Rex Zhang <[email protected]>
---
 test/iaa_user_test_runner.sh | 149 +++++++++++++++++++----------------
 1 file changed, 83 insertions(+), 66 deletions(-)

diff --git a/test/iaa_user_test_runner.sh b/test/iaa_user_test_runner.sh
index e3a6663..d85d043 100755
--- a/test/iaa_user_test_runner.sh
+++ b/test/iaa_user_test_runner.sh
@@ -6,7 +6,18 @@
 
 rc="$EXIT_SKIP"
 
-IAA=iax1
+DEV_OPT=""
+input1=$1
+if [ "$input1" == "--skip-config" ]; then
+   DEV=`ls /dev/iax/ | sed -ne 's|wq\([^.]\+\)\(.*\)|iax\1/wq\1\2|p'`
+   DEV=`echo $DEV | cut -f1 -d' '`
+   IAA=`echo $DEV | cut -f1 -d/`
+   DEV_OPT="-d $DEV"
+   echo "$DEV"
+else
+   IAA=iax1
+fi
+echo "$IAA"
 WQ0=wq1.4
 WQ1=wq1.1
 DBDF=`ls -l /sys/bus/dsa/devices/iax3 | awk -F '/' '{print $(NF - 1)}'`
@@ -149,10 +160,10 @@ test_op()
            if [ "$extra_flag" != "" ]
            then
                "$IAATEST" -w "$wq_mode_code" -l "$xfer_size" -o "$opcode" \
-                   -f "$flag" -1 "$extra_flag" -t 5000 -v

This is part of a patch from lore.kernel.org. It would be cool if delta could both render the diff part at the bottom and highlight the fields (like Date: , Message-Id: , [PATCH v1 1/2] , etc) at the frontmatter (before the ---)

nahharris avatar Sep 19 '24 17:09 nahharris

I am working on something that may address your issue, hopefully in something approaching a timely fashion. Can you answer some questions about the format? I am particularly interested in that first line:

From git@z Thu Jan  1 00:00:00 1970
  • Is the timestamp always Jan 1 1970?
  • And is the "email" always "something@z"? Also at lore.kernel.org, I see this commit is from mboxrd@z.

I am familiar with the format noted by Git's format-patch documentation, but not one with an email address in place of the commit hash. It could just be that while I use git-format-patch, I don't really do git-send-email (which doesn't have a sample in its documentation).

michaelblyons avatar Dec 07 '24 19:12 michaelblyons

From what i knew, the email was always git@z and the date always 1 Jan 1970 when using git send-email. I found a reference about mboxrd@z at the git-mailsplit manpage

        --mboxrd
           Input is of the "mboxrd" format and "^>+From " line escaping is reversed.

From the content of the patch you showed me i think this was sent via gmail instead of git send-email and that's why it uses a different "email" on the mailer line

nahharris avatar Dec 07 '24 21:12 nahharris

For any parties interested in the frontmatter highlighting: https://github.com/sublimehq/Packages/pull/4111

Here's the original commit, as highlighted by the PR above. Note that this is upstream, as rendered by Sublime Text. I don't know if there's a feature therein that Syntect (the engine for Delta and Bat) doesn't support.

git-diff-sample

michaelblyons avatar Dec 07 '24 22:12 michaelblyons

Now that I think about it, maybe what I was doing is not at all what @OJarrisonn wanted. Do you want front matter displayed before the Delta output? :blush: Yeah, this is nothing like that. Sorry.

michaelblyons avatar Dec 07 '24 23:12 michaelblyons

I don't want to spoil your guys' party, but syntect only supports default Sublime packages from the st3 branch as referenced here:

Current blockers:

  • trishume/syntect#271
  • trishume/syntect#323

So whatever Michael is doing, won't trickle down unless syntect sees a few major updates.

jrappen avatar Feb 11 '25 16:02 jrappen