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

Dwaipayan Ray dwaipayanray1 at gmail.com
Sat Dec 5 15:54:56 UTC 2020

Hey Aditya,

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

True, we need to track that version and terminate the script. Although I
am curious why it didn't work in your case. Is that file non existent on your

> - 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"?

Yes, that version compatibility might be a problem.
The other option is nice, but again it causes a certain conflict when the
HEAD itself is detached.

In a detached HEAD state, "git rev-parse --abbrev-ref HEAD" just returns

> 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?

Currently it should only output the diff. The --clang-format flag is to be used
though. Maybe the diff could be written into a clang-format-fixes.patch file and
apply it later on.
That way the user has more control over what gets changed.

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

Yep sure enough. The problem was somehow I didn't have it on
my system. So I couldn't use that. But it should be easy to swap
in git-clang-format for clang-format-diff.

But anyways thanks for testing it out!
A lot more to be done but let's see where it goes :)

Thank you,

More information about the Linux-kernel-mentees mailing list