Include directive sorter
[alexxy/gromacs.git] / admin / reformat_all.sh
index 23611ea70ad589fb787e00e1348aabebb4d4b2c5..caeede50faca9116a0eaee6118c3fe0a57b4b23d 100755 (executable)
 
 function usage() {
     echo "usage: reformat_all.sh [-f|--force]"
-    echo "           [--filter=(uncrustify|copyright)] [<action>]"
-    echo "<action>: (list-files|uncrustify*|copyright) (*=default)"
+    echo "           [--filter=(uncrustify|copyright|includesort)]"
+    echo "           [--pattern=<pattern>] [<action>] [-B=<build dir>]"
+    echo "<action>: (list-files|uncrustify*|copyright|includesort) (*=default)"
 }
 
 filter=default
 force=
+patterns=()
 action=uncrustify
 for arg in "$@" ; do
     if [[ "$arg" == "list-files" || "$arg" == "uncrustify" ||
-          "$arg" == "copyright" ]] ; then
+          "$arg" == "copyright" || "$arg" == "includesort" ]] ; then
         action=$arg
     elif [[ "$arg" == --filter=* ]] ; then
         filter=${arg#--filter=}
+    elif [[ "$arg" == --pattern=* ]] ; then
+        patterns[${#patterns[@]}]=${arg#--pattern=}
+    elif [[ "$arg" == -B=* ]] ; then
+        builddir=${arg#-B=}
     elif [[ "$arg" == "-f" || "$arg" == "--force" ]] ; then
         force=1
     else
@@ -86,6 +92,13 @@ case "$action" in
     copyright)
         command="xargs admin/copyright.py --check"
         ;;
+    includesort)
+        if [ -z "${builddir}" ] ; then
+            echo "Build directory must be set with -B for includesort."
+            exit 2
+        fi
+        command="docs/doxygen/includesorter.py -S . -B ${builddir} -F -"
+        ;;
     *)
         echo "Unknown action: $action"
         exit 2
@@ -96,11 +109,14 @@ if [[ "$filter" == "default" ]] ; then
 fi
 
 case "$filter" in
+    includesort)
+        filter_re="(uncrustify|includesort)"
+        ;;
     uncrustify)
         filter_re="(uncrustify|uncrustify_only)"
         ;;
     copyright)
-        filter_re="(uncrustify|copyright)"
+        filter_re="(uncrustify|copyright|includesort)"
         ;;
     *)
         echo "Unknown filter mode: $filter"
@@ -111,7 +127,7 @@ esac
 
 cd `git rev-parse --show-toplevel`
 
-if ! git ls-tree -r --name-only HEAD | git check-attr --stdin filter | \
+if ! git ls-files "${patterns[@]}" | git check-attr --stdin filter | \
     sed -nEe "/${filter_re}$/ {s/:.*//;p;}" | $command ; then
     echo "The reformatting command failed! Please check the output."
     exit 1