Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
CMake
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Golden
CMake
Commits
16b42d84
Commit
16b42d84
authored
8 years ago
by
Brad King
Committed by
Kitware Robot
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge topic 'clang-format-script'
2f2117e7
clang-format.bash: Limit formatting to files selected by options
parents
2c13f1b7
2f2117e7
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Utilities/Scripts/clang-format.bash
+45
-2
45 additions, 2 deletions
Utilities/Scripts/clang-format.bash
with
45 additions
and
2 deletions
Utilities/Scripts/clang-format.bash
+
45
−
2
View file @
16b42d84
...
...
@@ -17,7 +17,34 @@
usage
=
'usage: clang-format.bash [<options>] [--]
--clang-format <tool> Use given clang-format tool.
--help Print usage plus more detailed help.
--clang-format <tool> Use given clang-format tool.
--amend Filter files changed by HEAD.
--cached Filter files locally staged for commit.
--modified Filter files locally modified from HEAD.
--tracked Filter files tracked by Git.
'
help
=
"
$usage
"
'
Example to format locally modified files:
Utilities/Scripts/clang-format.bash --modified
Example to format locally modified files staged for commit:
Utilities/Scripts/clang-format.bash --cached
Example to format the current topic:
git filter-branch \
--tree-filter "Utilities/Scripts/clang-format.bash --amend" \
master..
Example to format all files:
Utilities/Scripts/clang-format.bash --tracked
'
die
()
{
...
...
@@ -28,9 +55,15 @@ die() {
# Parse command-line arguments.
clang_format
=
''
mode
=
''
while
test
"$#"
!=
0
;
do
case
"
$1
"
in
--amend
)
mode
=
"amend"
;;
--cached
)
mode
=
"cached"
;;
--clang-format
)
shift
;
clang_format
=
"
$1
"
;;
--help
)
echo
"
$help
"
;
exit
0
;;
--modified
)
mode
=
"modified"
;;
--tracked
)
mode
=
"tracked"
;;
--
)
shift
;
break
;;
-
*
)
die
"
$usage
"
;;
*
)
break
;;
...
...
@@ -59,8 +92,18 @@ if ! type -p "$clang_format" >/dev/null; then
exit
1
fi
# Select listing mode.
case
"
$mode
"
in
''
)
echo
"
$usage
"
;
exit
0
;;
amend
)
git_ls
=
'git diff-tree --diff-filter=AM --name-only HEAD -r --no-commit-id'
;;
cached
)
git_ls
=
'git diff-index --diff-filter=AM --name-only HEAD --cached'
;;
modified
)
git_ls
=
'git diff-index --diff-filter=AM --name-only HEAD'
;;
tracked
)
git_ls
=
'git ls-files'
;;
*
)
die
"invalid mode:
$mode
"
;;
esac
# Filter sources to which our style should apply.
git
ls-file
s
-z
--
'*.c'
'*.cc'
'*.cpp'
'*.cxx'
'*.h'
'*.hh'
'*.hpp'
'*.hxx'
|
$
git
_l
s
-z
--
'*.c'
'*.cc'
'*.cpp'
'*.cxx'
'*.h'
'*.hh'
'*.hpp'
'*.hxx'
|
# Exclude lexer/parser generator input and output.
egrep
-z
-v
'^Source/cmCommandArgumentLexer\.'
|
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment