Bug #91930 Exact clang-format version(s) must be documented
Submitted: 8 Aug 2018 7:25 Modified: 25 Feb 2022 9:25
Reporter: Laurynas Biveinis (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any
Tags: clang-format, git

[8 Aug 2018 7:25] Laurynas Biveinis
Description:
Invoking clang-format on a clean git repo should not result in any diff. If git clean/smudge filter for MySQL repo is enabled, such invocations are automatic and they must work with no surprises. But some experimenting shows that this is the case only with clang-format version 5. Attempting to use version 4 will result in 

Error reading /home/laurynas/mysql-server/.clang-format: Invalid argument
YAML:61:23: error: unknown key 'SplitEmptyFunction'
  SplitEmptyFunction: true
                      ^~~~

Attempting to use version 6 will result in re-formatting: reindentation of some block comments, adding of "// namespace foo" comments on closing braces, reordering of using directives etc. I will upload an example. Attempting to use version 7 will result in even more reformatting.

And .clang-format has a comment "We lock the style so that any newer version of clang-format will give the same result;" - which is wrong and misleading here

How to repeat:
Point clang-format binary to a specific version
In a git repo,
$ git config --local include.path ../.gitconfig
$ rm -rf *
$ git checkout -- .
$ git status
will error out on v4, will be empty on v5, will show diff on v6

Suggested fix:
1) Try, if possible, to adjust .clang-format so that more versions are supported
2) Document supported versions in .clang-format, even doxygenize it so that it goes to the internals manual too
[8 Aug 2018 7:29] Laurynas Biveinis
clang-format 6.0 result on MySQL 8.0.12

Attachment: mysql-8.0.12-clang-format-6.0.0.diff (application/octet-stream, text), 32.47 KiB.

[10 Aug 2018 5:37] MySQL Verification Team
Hello Laurynas,

Thank you for the report and feedback!

regards,
Umesh
[30 Oct 2018 14:59] Laurynas Biveinis
Further annoyance - not fully in the scope of this bug, but should be good enough for SEO - is that Ubuntu 18.10 (Cosmic Cuttlefish) does not ship LLVM/clang-format version 5 nor I was able to find any PPA carrying it. The workaround seems to be in that 18.04 (Bionic Beaver) packages seem to work in 18.10 too: libllvm5.0_5.0.1-4_amd64.deb, clang-format-5.0_5.0.1-4_amd64.deb
[25 Feb 2022 9:03] Terje Røsten
Posted by developer:
 
This was resolved by:

 https://github.com/mysql/mysql-server/commit/cb6638f253563b450f65a60bce4d23614bb4e395
[25 Feb 2022 9:12] Laurynas Biveinis
Thank you

A nitpick is that the comment "(...) any newer version of clang-format will give the same result" is incorrect and still present.
[25 Feb 2022 9:18] Terje Røsten
True, I will try to remember to remove that sentence on next version bump, ok?
[25 Feb 2022 9:25] Laurynas Biveinis
Sure, thank you :)