Skip to content

Commit ee27016

Browse files
Alami-Aminehasty
authored andcommitted
adding parallel execution to restyle-diff (project-chip#34663)
* adding parallel execution to restyle-diff * using xargs to call restyle-paths * fixing Copyright year * restyle the restyler
1 parent 08cb38b commit ee27016

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

scripts/helpers/restyle-diff.sh

+34-32
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
#
4-
# Copyright (c) 2020 Project CHIP Authors
4+
# Copyright (c) 2020-2024 Project CHIP Authors
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -21,57 +21,54 @@
2121
# you've written is kosher to CI
2222
#
2323
# Usage:
24-
# restyle-diff.sh [-d] [ref]
24+
# restyle-diff.sh [-d] [-p] [ref]
2525
#
2626
# if unspecified, ref defaults to upstream/master (or master)
2727
# -d sets container's log level to DEBUG, if unspecified the default log level will remain (info level)
28+
# -p pulls the Docker image before running the restyle paths
2829
#
2930

3031
here=${0%/*}
3132

3233
set -e
3334

35+
MAX_ARGS=256
36+
pull_image=0
37+
3438
CHIP_ROOT=$(cd "$here/../.." && pwd)
3539
cd "$CHIP_ROOT"
3640

37-
docker_run() {
38-
if [ -t 0 ]; then
39-
exec docker run --tty "$@"
40-
41-
else
42-
exec docker run "$@"
43-
44-
fi
45-
}
46-
4741
restyle-paths() {
48-
4942
image=restyled/restyler:edge
5043

51-
for path in "$@"; do
52-
(
53-
docker_run --tty --interactive --rm \
54-
--env LOG_LEVEL \
55-
--env LOG_DESTINATION \
56-
--env LOG_FORMAT \
57-
--env LOG_COLOR \
58-
--env HOST_DIRECTORY="$PWD" \
59-
--env UNRESTRICTED=1 \
60-
--volume "$PWD":/code \
61-
--volume /tmp:/tmp \
62-
--volume /var/run/docker.sock:/var/run/docker.sock \
63-
--entrypoint restyle-path \
64-
"$image" "$path"
65-
)
66-
done
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+
6757
}
6858

59+
#This was added to be able to use xargs to call the function restyle-paths
60+
export -f restyle-paths
61+
6962
while [[ $# -gt 0 ]]; do
7063
case "$1" in
7164
-d)
7265
export LOG_LEVEL="DEBUG"
7366
shift
7467
;;
68+
-p)
69+
pull_image=1
70+
shift
71+
;;
7572
*)
7673
ref="$1"
7774
shift
@@ -81,8 +78,13 @@ done
8178

8279
if [[ -z "$ref" ]]; then
8380
ref="master"
84-
git remote | grep -qxF upstream && ref="upstream/master"
81+
git remote | grep -qxF upstream && ref="upstream/master" && git fetch upstream
8582
fi
8683

87-
mapfile -t paths < <(git diff --ignore-submodules --name-only --merge-base "$ref")
88-
restyle-paths "${paths[@]}"
84+
if [[ $pull_image -eq 1 ]]; then
85+
docker pull restyled/restyler:edge
86+
fi
87+
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)