1
1
#! /usr/bin/env bash
2
2
3
3
#
4
- # Copyright (c) 2020 Project CHIP Authors
4
+ # Copyright (c) 2024 Project CHIP Authors
5
5
#
6
6
# Licensed under the Apache License, Version 2.0 (the "License");
7
7
# you may not use this file except in compliance with the License.
21
21
# you've written is kosher to CI
22
22
#
23
23
# Usage:
24
- # restyle-diff.sh [-d] [ref]
24
+ # restyle-diff.sh [-d] [-p] [ ref]
25
25
#
26
26
# if unspecified, ref defaults to upstream/master (or master)
27
27
# -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
28
29
#
29
30
30
31
here=${0%/* }
@@ -45,43 +46,81 @@ docker_run() {
45
46
}
46
47
47
48
restyle-paths () {
48
-
49
49
image=restyled/restyler:edge
50
+ batch_size=4
51
+ batch=()
50
52
51
53
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
- )
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
66
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
67
96
}
68
97
98
+ pull_image=0
99
+
69
100
while [[ $# -gt 0 ]]; do
70
101
case " $1 " in
71
- -d)
72
- export LOG_LEVEL=" DEBUG"
73
- shift
74
- ;;
75
- * )
76
- ref=" $1 "
77
- shift
78
- ;;
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
+ ;;
79
114
esac
80
115
done
81
116
82
117
if [[ -z " $ref " ]]; then
83
118
ref=" master"
84
- git remote | grep -qxF upstream && ref=" upstream/master"
119
+ git remote | grep -qxF upstream && ref=" upstream/master" && git fetch upstream
120
+ fi
121
+
122
+ if [[ $pull_image -eq 1 ]]; then
123
+ docker pull restyled/restyler:edge
85
124
fi
86
125
87
126
mapfile -t paths < <( git diff --ignore-submodules --name-only --merge-base " $ref " )
0 commit comments