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

Dwaipayan Ray dwaipayanray1 at gmail.com
Mon Dec 21 19:47:03 UTC 2020

> Okay, I downloaded and tried it:
> perl ./scripts/applypatch.pl --clang-format test.patch
> --branch=test-clang-format-bfq-cgroup
> but it failed:
> git checkout test-clang-format-bfq-cgroup
> Already on 'test-clang-format-bfq-cgroup'
> git am $patchtest.patch
> fatal: could not open '.patch' for reading: No such file or directory
> Clang formatted patchfile generated at:
> test.patch.EXPERIMENTAL-clang_format-fixes
> git checkout test-clang-format-bfq-cgroup
> Already on 'test-clang-format-bfq-cgroup'
> How about setting up a minimal travis.ci check that runs this command
> on a small git repository with one file and one patch on top for
> testing purposes?
> The script does not have error handling yet, so the next steps are
> just executed blindly even if the one before failed and is really
> required for the next one to do the right thing.
> I generally like the script, let us work a bit on tuning it for proper
> error handling, add some basic tests and then discuss it with Miguel.
> Lukas

Hello Lukas,
Sorry for being late on this update. I have my college exams going on
right now, so that caused a bit of delay.

Nevertheless I have applied some changes along with some error handling fixes.
The script is available here:

The script has the following options now:
usage: $P [options] patchfile(s)
--branch=<branch-name> => test branch name
--format => Use clang format
--clang-format-diff=<s> => clang-format-diff path
--help => show this help information
--root=<root_dir> => root dir location

By default script searches for "clang-format-diff.py" in path. If it goes
by any other name that should be supplied using

I ran the script like this:
$ ./scripts/applypatch.pl
0001-scripts-mod-cleanup-a-few-checkpatch.pl-warnings.patch --format

Expected output:
git checkout -b test-master
Switched to a new branch 'test-master'
git am 0001-scripts-mod-cleanup-a-few-checkpatch.pl-warnings.patch
Patch applied successfully:
Running clang-format
Diff written to clang-format-fixes.diff
git checkout master
Switched to branch 'master

Lukas, could you check if this script works on your system as expected?

Also Aditya, I think the latest clang-format-diff goes by the name
'clang-format-diff-8' on debian based systems. While in my arch based one
it goes by 'clang-format-diff.py'. Can you verify whether the script works
directly or is the executable path flag needed?

Thank you,

More information about the Linux-kernel-mentees mailing list