|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 |
|
3 | 3 | #
|
4 |
| -# Copyright (c) 2020 Project CHIP Authors |
| 4 | +# Copyright (c) 2020-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%/*}
|
31 | 32 |
|
32 | 33 | set -e
|
33 | 34 |
|
| 35 | +MAX_ARGS=256 |
| 36 | +pull_image=0 |
| 37 | + |
34 | 38 | CHIP_ROOT=$(cd "$here/../.." && pwd)
|
35 | 39 | cd "$CHIP_ROOT"
|
36 | 40 |
|
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 |
| - |
47 | 41 | restyle-paths() {
|
48 |
| - |
49 | 42 | image=restyled/restyler:edge
|
50 | 43 |
|
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 | + |
67 | 57 | }
|
68 | 58 |
|
| 59 | +#This was added to be able to use xargs to call the function restyle-paths |
| 60 | +export -f restyle-paths |
| 61 | + |
69 | 62 | while [[ $# -gt 0 ]]; do
|
70 | 63 | case "$1" in
|
71 | 64 | -d)
|
72 | 65 | export LOG_LEVEL="DEBUG"
|
73 | 66 | shift
|
74 | 67 | ;;
|
| 68 | + -p) |
| 69 | + pull_image=1 |
| 70 | + shift |
| 71 | + ;; |
75 | 72 | *)
|
76 | 73 | ref="$1"
|
77 | 74 | shift
|
|
81 | 78 |
|
82 | 79 | if [[ -z "$ref" ]]; then
|
83 | 80 | ref="master"
|
84 |
| - git remote | grep -qxF upstream && ref="upstream/master" |
| 81 | + git remote | grep -qxF upstream && ref="upstream/master" && git fetch upstream |
85 | 82 | fi
|
86 | 83 |
|
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