[Insight-developers] uncrustify git hook

Matthew McCormick (thewtex) matt at mmmccormick.com
Thu Sep 9 17:10:05 EDT 2010


Hi Hans, Brad, Luis, et al.,

I drafted a git pre-commit hook to run uncrustify and KWStyle checks on
changes to the code.

uncrustify (uncrustify.sourceforge.net) is applied to changed files prior to
commit.

To enable this behavior, set
  git config hooks.uncrustify true

By default, the behavior of git-mergetool is used to review the changes
uncrustify makes before they are added to the commit.  For more information
on
this behavior, see
 git help mergetool
To disable review with mergetool
  git config hooks.uncrustify.mergetool false
All changes suggested by uncrustify will automatically be added to the
commit (dangerous?).

Hans, I took the uncrustify.conf from the wiki page here:
http://www.itk.org/Wiki/ITKv4_StyleChangeProposal

I made one modification:
--- .git/hooks/uncrustify.conf 2010-09-09 15:40:13.000000000 -0500
+++ /tmp/Uncrustify_itk.txt 2010-09-09 15:52:52.945218676 -0500
@@ -388,7 +388,7 @@
 sp_inside_fparens                        = remove   #
ignore/add/remove/force

 # Add or remove space inside function '(' and ')'
-sp_inside_fparen                         = add   # ignore/add/remove/force
+sp_inside_fparen                         = remove   #
ignore/add/remove/force

 # Add or remove space between ']' and '(' when part of a function call.
 sp_square_fparen                         = remove   #
ignore/add/remove/force
@@ -1197,3 +1197,4 @@
 #
 # You can assign any keyword to any type with the set option.
 # set func_call_user _ N_
+

I think this is more consistent with the codebase, increases readability,
and it is easier to work with an advanced editor like emacs/vim.


The KWStyle check on changed files is run by default.

KWStyle is run on the changed files and the commit is aborted if the files
do
not pass the test.  A file similar to the original is saved with a '*.kws'
extension so that line numbers referenced in the error message can be
examined.

The test is on by default.  To avoid running the KWStyle tests
  git config hooks.KWStyle false

The configuration file for KWStyle was taken from master at
Utilities/KWStyle/ITK.kws.xml.in.


There is one problem I have encountered that I was unable to find a good
solution too.  I use vimdiff as my mergetool, and it will complain about the
input not being a terminal, then the terminal will be corrupt after
completing the commit message.  As a workaround for now, 'reset' is called
after running the mergetool in the script.  Googling suggests this can
happen when running vim in a pipe, but I am not sure what is going on.  Any
pointers would be appreciated.

To give the hook a try,

cd ${ITK_SOURCE}/.git/hooks
git pull git://github.com/thewtex/ITK.git hooks_uncrustify
cd ../..
git config hooks.uncrustify true


Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20100909/28851cfb/attachment.htm>


More information about the Insight-developers mailing list