Use an array to handle line ranges in format-commit
This commit is contained in:
parent
fa50c01a13
commit
c232870c16
1 changed files with 9 additions and 12 deletions
|
@ -131,8 +131,15 @@ list_changed_files () {
|
|||
|
||||
run_clang_format () {
|
||||
while read -r src_file ; do
|
||||
prepare_clang_params "$src_file" \
|
||||
| xargs --no-run-if-empty --verbose clang-format -i
|
||||
local ranges=()
|
||||
while IFS=$'\n' read -r range ; do
|
||||
ranges+=("$range")
|
||||
done < <(git_diff_to_clang_line_range "$src_file")
|
||||
|
||||
if (( "${#ranges[@]}" )); then
|
||||
echo "clang-format -i ${ranges[*]} \"$src_file\""
|
||||
clang-format -i "${ranges[@]}" "$src_file"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
@ -144,16 +151,6 @@ git_diff_to_clang_line_range () {
|
|||
| to_clang_line_range
|
||||
}
|
||||
|
||||
prepare_clang_params () {
|
||||
local -r file=$1
|
||||
local -r range=$(git_diff_to_clang_line_range "$file")
|
||||
# print file name only when there are any lines detected, otherwise
|
||||
# clang-format would process the whole file
|
||||
if [ -n "$range" ]; then
|
||||
echo "$range \"$file\""
|
||||
fi
|
||||
}
|
||||
|
||||
# expects line in diff format: "@@ -<line range> +<line range> @@ <context>"
|
||||
# where <line range> is either <line_number> or <line_number>,<offset>
|
||||
#
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue