Skip to content
Snippets Groups Projects
Commit 7e9f7b7b authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Merge topic 'clang-format-attrs'


d22c2743 clang-format.bash: Use Git attributes to mark files for formatting
6365886c Define a custom Git attribute to mark sources using our C style
0af48083 Drop custom Git whitespace check attribute

Acked-by: default avatarKitware Robot <kwrobot@kitware.com>
Acked-by: default avatarBen Boeckel <ben.boeckel@kitware.com>
Merge-request: !18
parents 81a821b6 d22c2743
No related branches found
No related tags found
No related merge requests found
...@@ -2,18 +2,22 @@ ...@@ -2,18 +2,22 @@
.gitattributes -export-ignore .gitattributes -export-ignore
.hooks* export-ignore .hooks* export-ignore
# Custom attribute to mark sources as using our C code style.
[attr]our-c-style whitespace=tab-in-indent format.clang-format
/GitSetup export-ignore /GitSetup export-ignore
/*.sh export-ignore eol=lf /*.sh export-ignore eol=lf
/*.bash export-ignore eol=lf /*.bash export-ignore eol=lf
/.clang-format export-ignore /.clang-format export-ignore
*.c whitespace=tab-in-indent,no-lf-at-eof *.c our-c-style
*.h whitespace=tab-in-indent,no-lf-at-eof *.c.in our-c-style
*.h.in whitespace=tab-in-indent,no-lf-at-eof *.cxx our-c-style
*.cxx whitespace=tab-in-indent,no-lf-at-eof *.h our-c-style
*.hxx whitespace=tab-in-indent,no-lf-at-eof *.h.in our-c-style
*.hxx.in whitespace=tab-in-indent,no-lf-at-eof *.hxx our-c-style
*.txt whitespace=tab-in-indent,no-lf-at-eof *.hxx.in our-c-style
*.cmake whitespace=tab-in-indent,no-lf-at-eof
*.cmake whitespace=tab-in-indent
*.rst whitespace=tab-in-indent conflict-marker-size=79 *.rst whitespace=tab-in-indent conflict-marker-size=79
*.txt whitespace=tab-in-indent
#!/usr/bin/env bash #!/usr/bin/env bash
#============================================================================= #=============================================================================
# Copyright 2015-2016 Kitware, Inc. # Copyright 2015-2017 Kitware, Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -106,17 +106,18 @@ case "$mode" in ...@@ -106,17 +106,18 @@ case "$mode" in
*) die "invalid mode: $mode" ;; *) die "invalid mode: $mode" ;;
esac esac
# Filter sources to which our style should apply. # List files as selected above.
list_cfg_files() { list_files() {
$git_ls -z -- '*.c.in' '*.h.in' '*.hxx.in' $git_ls |
}
list_all_files() { # Select sources with our attribute.
$git_ls -z -- '*.c' '*.c.in' '*.cxx' '*.h' '*.h.in' '*.hxx' '*.hxx.in' git check-attr --stdin format.clang-format |
sed -n '/: format\.clang-format: set$/ {s/:[^:]*:[^:]*$//p}'
} }
# Transform configured sources to protect @SYMBOLS@. # Transform configured sources to protect @SYMBOLS@.
list_cfg_files | xargs -0 -r sed -i 's/@\(KWSYS_[A-Z0-9_]\+\)@/x\1x/g' list_files | xargs -d '\n' sed -i 's/@\(KWSYS_[A-Z0-9_]\+\)@/x\1x/g'
# Update sources in-place. # Update sources in-place.
list_all_files | xargs -0 "$clang_format" -i list_files | xargs -d '\n' "$clang_format" -i
# Transform configured sources to restore @SYMBOLS@. # Transform configured sources to restore @SYMBOLS@.
list_cfg_files | xargs -0 -r sed -i 's/x\(KWSYS_[A-Z0-9_]\+\)x/@\1@/g' list_files | xargs -d '\n' sed -i 's/x\(KWSYS_[A-Z0-9_]\+\)x/@\1@/g'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment