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

Lukas Bulwahn lukas.bulwahn at gmail.com
Fri Dec 11 06:17:23 UTC 2020


On Sun, Dec 6, 2020 at 11:49 AM Aditya <yashsri421 at gmail.com> wrote:
>
> On 5/12/20 9:24 pm, Dwaipayan Ray wrote:
> > 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
> > system?
> >
> >> - 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
> > "HEAD".
> >
> >> 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.
> >
> Hi Dwaipayan,
> I have modified your script with clang-format-diff here:
> https://gist.github.com/AdityaSrivast/0fc57fbd49db8c05c7b1154d4289174a
>
> As we wanted, it generates a modified patch which is clang formatted,
> with suffix ".clang-format.EXPERIMENTAL". It also modifies the files
> with clang-format in test-branch, which was desired with our
> "--clang-format" flag to this script.
>
> I think the code probably will need to be refactored once we are sure
> that we are on the right track and the script does the desired job.
>
> Lukas, what do you think?
>

Aditya, Dwaipayan, can you set up a git repository that you use
together to work on this script?

And provide a short description of how to use the script with an
example in that repository?

Then, I am happy to try it out... and provide you more feedback.

Lukas


More information about the Linux-kernel-mentees mailing list