[Users] Reformatting Carpet's source code

Roland Haas rhaas at aei.mpg.de
Tue Jul 7 13:16:46 CDT 2015


Hello all,

> I just press TAB in emacs to make sure the indentation is correct;
> it's not something I ever really think about.  
Well, one has to define "correct". In Carpet one should do more than
just pick whatever one likes, I believe. Ideally one should read a
document with the desired coding style (see eg
AHFinderDirect/src/CODESTYLE or
http://einsteintoolkit.org/documentation/MaintGuide/MaintGuidech2.html#x4-3000A2)
or at least look around a bit to try and learn what the original author
uses (in Carpet's case eg the use of "and" and "or" instead of "&&" and
"||", indentation for blocks, whether to use braces for single
statements in if/else constructs).

Erik's change basically tries to avoid having to do so manually. Given
that our code is somewhat non-standard (due to eg the BEGIN_GLOBAL_MODE
type macros and the CCTK_LOOP type macros) we'd need to craft a specific
configuration file for clang-format to get nice results I think.

> After reading Roland's
> email, I'm more and more concerned that a large-scale reformatting of
> an existing codebase with several branches owned by different people
> is going to cause a fair amount of pain.  
I thought about it a bit, I think git's filter-branch command can
simplify this:

git filter-branch --tree-filter 'find . -name \*.hh -or -name \*.cc
-print0 | xargs --null clang-format --style llvm -i' BRANCH-NAME

seems to do the trick (though it's slow, runtime on the order of 1.5
hours per branch on my workstation). It is still disruptive to diff
though so I like the idea of only applying clang-format to new commits
better. Erik's choice though.

Yours,
Roland


More information about the Users mailing list