[Linux-kernel-mentees] POC script to apply patches into a test-branch and run clang-format

Aditya yashsri421 at gmail.com
Sat Dec 5 15:27:47 UTC 2020


On 5/12/20 4:40 pm, Dwaipayan Ray wrote:
> Hi,
> In continuation to our previous discussion about ways to make checkpatch
> apply patches into a test brach, and probably run clang-format to generate
> a diff, I wrote a small script which does the same.
> 
> It can be found here:
> https://gist.github.com/raydwaipayan/6b8d10470a163f7ae501c703bc27a83f
> 
> The script is still in it's infancy and more configuration options and support
> for patch series is pending.
> 
> Lukas, it would be great to have your review on this.
> 
> Thank you,
> Dwaipayan.
> 

Hi Dwaipayan
Nice work!
I was able to run the script, with few changes to the script. I'd add
my suggestions about it:

- The check with: "(! -e $git_clang_format_file)" doesn't work
correctly for me. Although the command runs properly, after I comment
out this if-section. Probably if we just check for a certain version
of git which added "git clang-format" for the first time, in users
system, it might do the trick.

- Also "git branch --show-current" is compatible only with Git 2.22 or
above (For eg, mine is 2.17.1). Maybe replace it with "git rev-parse
--abbrev-ref HEAD"?

Also, I created a patch for testing the script. Here it is:

>From 842e18ecc9500fbd2e5d08c4a2b3e7e3c275b6bc Mon Sep 17 00:00:00 2001
From: Aditya Srivastava <yashsri421 at gmail.com>
Date: Sat, 5 Dec 2020 19:38:03 +0530
Subject: [PATCH] temp

---
 block/sed-opal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/sed-opal.c b/block/sed-opal.c
index daafadbb88ca..f7929eb67f37 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -2322,7 +2322,7 @@ static int opal_add_user_to_lr(struct opal_dev *dev,
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
 	ret = execute_steps(dev, steps, ARRAY_SIZE(steps));
-	mutex_unlock(&dev->dev_lock);
+mutex_unlock(&dev->dev_lock);

 	return ret;
 }
-- 
2.17.1


Now this patch gets applied to a new "test-xyz" branch, but it is not
formatted, ie the added line remains un-indented. Is this expected
behaviour from the script?

I have also tried out something similar (using clang-format-diff
though). I'll try to add it in your script and send.

Thanks
Aditya


More information about the Linux-kernel-mentees mailing list