[RFC] Formatting our .c and .h files with clang-format

Augie Fackler raf at durin42.com
Mon Sep 14 19:03:34 UTC 2015


http://clang.llvm.org/docs/ClangFormat.html is a handy tool for having
a machine format your (C/C++/etc) source code rather than having
error-prone humans perform the same tasks. Right now we've got a
handful of rules in check-code for this, but they're not actually
sufficient for all our code to be substantially similar style. I've
created a clang-format file that is *close* to what we already do
(http://hg.durin42.com/hg-wip/rev/aaeda7971cdb) and have wired up
tests etc that would let us keep files formatted. As a sample of the
result, I've reformatted:

* manifest.c: http://hg.durin42.com/hg-wip/rev/ca90a7cff2e1
    This is a nice comprehensive example, and includes working around the
     formatter in a couple spots where Python's macros fool the formatter.

base85.c: http://hg.durin42.com/hg-wip/rev/177e9d2e3cc5
    This is a nice example of a file that was in its own style that is trivially
    brought in line with the rest of the codebase.

Note that the resulting code tweaks check-code's "don't use spaces to
indent" check. My opinion there is that if we start using clang-format
we should just drop anything in check-code that conflicts with
clang-format, since the latter is trivial to apply.

Thoughts?


More information about the Mercurial-devel mailing list