Debian Codegraph @

util/scripts/update_submodules

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2 #
3 # SPDX-License-Identifier: GPL-2.0-only
4
5 # Description:
6 # Check all submodules for updates. If there are more than a minimum
7 # number of changes, create a commit to update the submodule to the
8 # new version.
9
10 set -eu -o pipefail
11
12 VERSION="1.01"
13 PROGRAM=$0
14 PROGNAME="$(basenamescip-shell system . . basename. "${PROGRAM}")"
15
16 export LANG=C
17 export LC_ALL=C
18 export TZ=UTC0
19
20 min_commits=10
21 TOP=${PWD}
22 SUBMODULES_WITH_UPDATES=0
23 submodule_dirs=()
24 skip_sync=""
25 max_commits_to_list=65
26
27 show_versionscip-shell shell coreboot 25.09+dfsg-1 show_version().() {
28 echoscip-shell system . . echo. "${PROGNAME} version ${VERSION}"
29 echoscip-shell system . . echo.
30 }
31
32 usagescip-shell shell coreboot 25.09+dfsg-1 usage().() {
33 echoscip-shell system . . echo. "Usage: ${PROGNAME} [options]"
34 echoscip-shell system . . echo.
35 echoscip-shell system . . echo. "Options:"
36 echoscip-shell system . . echo. " -c | --changes <#> Specify the minimum number of changes to update a repo"
37 echoscip-shell system . . echo. " -h | --help Print usage and exit"
38 echoscip-shell system . . echo. " -R | --repo <dir> Specify a single repo directory to update"
39 echoscip-shell system . . echo. " -s | --skipsync Assume that repos are already synced"
40 echoscip-shell system . . echo. " -V | --version Print the version and exit"
41 echoscip-shell system . . echo.
42 }
43
44 get_argsscip-shell shell coreboot 25.09+dfsg-1 get_args().() {
45 args=$(getoptscip-shell system . . getopt. -l changes:,help,repo:,skipsync,version -o c:hR:sV -- "$@")
46 getopt_ret=$?
47 eval set -- "${args}"
48
49 if [scip-shell system . . `[`. ${getopt_ret} != 0 ]; then
50 usagescip-shell shell coreboot 25.09+dfsg-1 usage().
51 exit 1
52 fi
53
54 while truescip-shell system . . true.; do
55 local opt
56 opt="$1"
57 shift
58 case "${opt}" in
59 -c | --changes)
60 min_commits="${1}"
61 shift
62 ;;
63 -h | --help)
64 usagescip-shell shell coreboot 25.09+dfsg-1 usage().
65 exit 0
66 ;;
67 -R | --repo)
68 submodule_dirs="${1%/}"
69 shift
70 if [[ ! -d "${submodule_dirs[0]}" ]]; then
71 echoscip-shell system . . echo. "Error: ${submodule_dirs[0]} is not valid."
72 usagescip-shell shell coreboot 25.09+dfsg-1 usage().
73 exit 1
74 fi
75 ;;
76 -s | --skipsync)
77 skip_sync=1
78 ;;
79 -V | --version)
80 exit 0
81 ;;
82 *)
83 break
84 ;;
85 esac
86 done
87 }
88
89
90 mainscip-shell shell coreboot 25.09+dfsg-1 main().() {
91 show_versionscip-shell shell coreboot 25.09+dfsg-1 show_version().
92 get_argsscip-shell shell coreboot 25.09+dfsg-1 get_args(). "$@"
93
94 if (( ${#submodule_dirs[@]} == 0 )); then
95 readarray -t submodule_dirs < <(gitscip-shell system . . git. submodule foreach 'echo ${sm_path}'|grepscip-shell system . . grep. -v Entering)
96 fi
97
98 for submodule in "${submodule_dirs[@]}"; do
99 cd "${TOP}"
100
101 echoscip-shell system . . echo. ""
102 echoscip-shell system . . echo. "Checking submodule ${submodule}"
103
104 if ! cd "$submodule"; then
105 echoscip-shell system . . echo. "Error: could not cd to $submodule"
106 exit 1
107 fi
108
109 initial_commit_id="$(gitscip-shell system . . git. log --pretty='%h' -n 1 --abbrev=12)"
110 initial_commit_description="$(gitscip-shell system . . git. log --pretty='%ci - (%s)' -n 1)"
111 if [[ ${skip_sync} != "1" ]]; then
112 gitscip-shell system . . git. fetch 2>/dev/nullscip-shell filesystem . . `/dev/null`.
113 fi
114
115 branch_name="$(gitscip-shell system . . git. symbolic-ref refs/remotes/origin/HEAD --short)"
116
117 updated_commit_id="$(gitscip-shell system . . git. log --pretty='%h' -n 1 --abbrev=12 "${branch_name}" -- )"
118 updated_commit_description="$(gitscip-shell system . . git. log --pretty='%ci - (%s)' -n 1 "${updated_commit_id}")"
119 if [scip-shell system . . `[`. "${initial_commit_id}" = "${updated_commit_id}" ]; then
120 echoscip-shell system . . echo. "No updates for ${submodule}"
121 continue
122 fi
123 SUBMODULES_WITH_UPDATES+=1
124 update_log="$(gitscip-shell system . . git. log --oneline --abbrev=12 "${initial_commit_id}..${updated_commit_id}")"
125 update_count="$(echoscip-shell system . . echo. "${update_log}" | wcscip-shell system . . wc. -l)"
126 if [[ "${update_count}" -gt "${max_commits_to_list}" ]]; then
127 update_log=""
128 new_commit_terminator="."
129 else
130 new_commit_terminator=":"
131 fi
132 echoscip-shell system . . echo. "${update_count} new commits for ${submodule}"
133 if [scip-shell system . . `[`. "${update_count}" -ge "${min_commits}" ]; then
134 echoscip-shell system . . echo. "Creating commit to update ${submodule##*/} submodule"
135 gitscip-shell system . . git. checkout "${updated_commit_id}" > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
136 cd "${TOP}" || exit 1
137 gitscip-shell system . . git. add "${submodule}" > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || exit 1
138 gitscip-shell system . . git. commit -s -F- > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 <<-EOF
139 ${submodule}: Update to upstream ${branch_name##*/}
140
141 Updating from commit id ${initial_commit_id}:
142 $initial_commit_description
143
144 to commit id ${updated_commit_id}:
145 ${updated_commit_description}
146
147 This brings in ${update_count} new commits${new_commit_terminator}
148 ${update_log}
149 EOF
150 fi
151 done
152
153 if [scip-shell system . . `[`. "${SUBMODULES_WITH_UPDATES}" = "0" ]; then
154 echoscip-shell system . . echo. "No submodules with any updates."
155 fi
156 }
157
158 mainscip-shell shell coreboot 25.09+dfsg-1 main(). "$@"