Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚀 Syntax highlight for git patches frontmatter #1863

Open
OJarrisonn opened this issue Sep 19, 2024 · 6 comments
Open

🚀 Syntax highlight for git patches frontmatter #1863

OJarrisonn opened this issue Sep 19, 2024 · 6 comments

Comments

@OJarrisonn
Copy link

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 <me@mymail.com>

Example

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

image

@dandavison
Copy link
Owner

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

@OJarrisonn
Copy link
Author

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 <rex.zhang@intel.com>
Date: Wed, 25 Oct 2023 16:52:58 +0800
Message-Id: <20231025085259.2958695-1-rex.zhang@intel.com>
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 <rex.zhang@intel.com>
---
 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 ---)

@michaelblyons
Copy link

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).

@OJarrisonn
Copy link
Author

OJarrisonn commented Dec 7, 2024

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

@michaelblyons
Copy link

michaelblyons commented Dec 7, 2024

For any parties interested in the frontmatter highlighting: sublimehq/Packages#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
Copy link

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? 😊 Yeah, this is nothing like that. Sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants