Skip to content

Commit 195843d

Browse files
committed
using xargs to call restyle-paths
1 parent d796550 commit 195843d

File tree

1 file changed

+34
-71
lines changed

1 file changed

+34
-71
lines changed

scripts/helpers/restyle-diff.sh

+34-71
Original file line numberDiff line numberDiff line change
@@ -32,85 +32,47 @@ here=${0%/*}
3232

3333
set -e
3434

35+
MAX_ARGS=256
36+
pull_image=0
37+
3538
CHIP_ROOT=$(cd "$here/../.." && pwd)
3639
cd "$CHIP_ROOT"
3740

38-
docker_run() {
39-
if [ -t 0 ]; then
40-
exec docker run --tty "$@"
41-
42-
else
43-
exec docker run "$@"
44-
45-
fi
46-
}
47-
4841
restyle-paths() {
4942
image=restyled/restyler:edge
50-
batch_size=4
51-
batch=()
52-
53-
for path in "$@"; do
54-
batch+=("$path")
55-
if [[ ${#batch[@]} -eq $batch_size ]]; then
56-
for p in "${batch[@]}"; do
57-
(
58-
docker_run \
59-
--env LOG_LEVEL \
60-
--env LOG_DESTINATION \
61-
--env LOG_FORMAT \
62-
--env LOG_COLOR \
63-
--env HOST_DIRECTORY="$PWD" \
64-
--env UNRESTRICTED=1 \
65-
--volume "$PWD":/code \
66-
--volume /tmp:/tmp \
67-
--volume /var/run/docker.sock:/var/run/docker.sock \
68-
--entrypoint restyle-path \
69-
"$image" "$p"
70-
) &
71-
done
72-
wait
73-
batch=()
74-
fi
75-
done
76-
77-
if [[ ${#batch[@]} -gt 0 ]]; then
78-
for p in "${batch[@]}"; do
79-
(
80-
docker_run \
81-
--env LOG_LEVEL \
82-
--env LOG_DESTINATION \
83-
--env LOG_FORMAT \
84-
--env LOG_COLOR \
85-
--env HOST_DIRECTORY="$PWD" \
86-
--env UNRESTRICTED=1 \
87-
--volume "$PWD":/code \
88-
--volume /tmp:/tmp \
89-
--volume /var/run/docker.sock:/var/run/docker.sock \
90-
--entrypoint restyle-path \
91-
"$image" "$p"
92-
) &
93-
done
94-
wait
95-
fi
43+
(
44+
docker run \
45+
--env LOG_LEVEL \
46+
--env LOG_DESTINATION \
47+
--env LOG_FORMAT \
48+
--env LOG_COLOR \
49+
--env HOST_DIRECTORY="$PWD" \
50+
--env UNRESTRICTED=1 \
51+
--volume "$PWD":/code \
52+
--volume /tmp:/tmp \
53+
--volume /var/run/docker.sock:/var/run/docker.sock \
54+
--entrypoint restyle-path \
55+
"$image" "$@"
56+
)
9657
}
9758

98-
pull_image=0
59+
#This was added to be able to use xargs to call the function restyle-paths
60+
export -f restyle-paths
9961

10062
while [[ $# -gt 0 ]]; do
10163
case "$1" in
102-
-d)
103-
export LOG_LEVEL="DEBUG"
104-
shift
105-
;;
106-
-p)
107-
pull_image=1
108-
shift
109-
;;
110-
*)
111-
ref="$1"
112-
shift
113-
;;
64+
-d)
65+
export LOG_LEVEL="DEBUG"
66+
shift
67+
;;
68+
-p)
69+
pull_image=1
70+
shift
71+
;;
72+
*)
73+
ref="$1"
74+
shift
75+
;;
11476
esac
11577
done
11678

@@ -123,5 +85,6 @@ if [[ $pull_image -eq 1 ]]; then
12385
docker pull restyled/restyler:edge
12486
fi
12587

126-
mapfile -t paths < <(git diff --ignore-submodules --name-only --merge-base "$ref")
127-
restyle-paths "${paths[@]}"
88+
paths=$(git diff --ignore-submodules --name-only --merge-base "$ref")
89+
90+
echo "$paths" | xargs -n $MAX_ARGS bash -c 'restyle-paths "$@"'

0 commit comments

Comments
 (0)