git clang-format (was Re: [PATCH for comments] configure: install...)

Uri Simchoni uri at
Wed Apr 11 01:11:53 UTC 2018

On 04/11/2018 03:08 AM, Douglas Bagnall wrote:
> On 10/04/18 21:39, Uri Simchoni wrote:
>> On 04/10/2018 12:03 PM, Douglas Bagnall via samba-technical wrote:
>>> When I am reviewing or working on python files, I quite often run flake8 to see
>>> what it says. I don't always agree. It would be nice to have a similar thing for C.
>>> It is sometimes more interesting for a tool to be opinionated than authoritative.
>> IMHO the one-stop-shop for an opinionated formatting tool for C is
>> clang-format.
>> - The samba-conformant configuration is in README.Coding
>> - It does whitespace (end-of-line, tab), alignment, 80-column, space
>> between variables and operators, you name it. Being based on a compiler,
>> it probably does a better job than any hand-crafted script.
>> - Combined with the git-clang-format git add-on, doing "git
>> clang-format" will only re-format the changed lines.
>> - I mostly take its edits as-is. Only place where I consistently
>> disagree is in initialized arrays of popt options - it's not necessarily
>> incorrect but the new option has to be consistent with other options.
>> This is an example of where the automatic formatting doesn't work though.
>> So my workflow for a single commit is:
>> - add all changes - everything is in the index
>> - run "git clang-format" - clang-format reformats the patches that are
>> in the index
>> - run "git add -i" to accept or reject git-clang-format edits.
> Thanks Uri,
> I wasn't aware of git clang-format. I have got as far as this:
> git config "{BasedOnStyle: LLVM, IndentWidth: 8, UseTab: true, BreakBeforeBraces: Linux, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, BinPackParameters: false, BinPackArguments: false}"
> which leaves me wanting to patch some C.
> Douglas
That might work. My setup is:

...and then I have a .clang-format file in my homedir with:
BasedOnStyle: LLVM
IndentWidth: 8
UseTab: true
BreakBeforeBraces: Linux
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false
BinPackParameters: false
BinPackArguments: false


More information about the samba-technical mailing list