Martin Roth - Personal has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/61726 )
Change subject: util/scripts/update_submodules: Fix formatting ......................................................................
util/scripts/update_submodules: Fix formatting
Signed-off-by: Martin Roth gaumless@gmail.com Change-Id: I4390086f4aeabf5c4e03cf350bb520df89c5884c --- M util/scripts/update_submodules 1 file changed, 102 insertions(+), 103 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/26/61726/1
diff --git a/util/scripts/update_submodules b/util/scripts/update_submodules index aa5b511..a7f3284 100755 --- a/util/scripts/update_submodules +++ b/util/scripts/update_submodules @@ -25,119 +25,118 @@ max_commits_to_list=65
show_version() { - echo "${PROGNAME} version ${VERSION}" - echo + echo "${PROGNAME} version ${VERSION}" + echo }
usage() { - echo "Usage: ${PROGNAME} [options]" - echo - echo "Options:" - echo " -c | --changes <#> Specify the minimum number of changes to update a repo" - echo " -h | --help Print usage and exit" - echo " -R | --repo <dir> Specify a single repo directory to update" - echo " -s | --skipsync Assume that repos are already synced" - echo " -V | --version Print the version and exit" - echo + echo "Usage: ${PROGNAME} [options]" + echo + echo "Options:" + echo " -c | --changes <#> Specify the minimum number of changes to update a repo" + echo " -h | --help Print usage and exit" + echo " -R | --repo <dir> Specify a single repo directory to update" + echo " -s | --skipsync Assume that repos are already synced" + echo " -V | --version Print the version and exit" + echo }
get_args() { - args=$(getopt -l changes:,help,repo:,skipsync,version -o c:hR:sV -- "$@") - getopt_ret=$? - eval set -- "${args}" + args=$(getopt -l changes:,help,repo:,skipsync,version -o c:hR:sV -- "$@") + getopt_ret=$? + eval set -- "${args}"
- if [ ${getopt_ret} != 0 ]; then - usage - exit 1 - fi + if [ ${getopt_ret} != 0 ]; then + usage + exit 1 + fi
- while true; do - local opt - opt="$1" - shift - case "${opt}" in - -c | --changes) - min_commits="${1}" - shift - ;; - -h | --help) - usage - exit 0 - ;; - -R | --repo) - submodule_dirs=("$(readlink -f "${1}")") - shift - if [[ ! -d "${submodule_dirs[0]}" ]]; then - echo "Error: ${submodule_dirs[0]} is not valid." - usage - exit 1 - fi - ;; - -s | --skipsync) - skip_sync=1 - ;; - -V | --version) - exit 0 - ;; - *) - break - ;; - esac - done + while true; do + local opt + opt="$1" + shift + case "${opt}" in + -c | --changes) + min_commits="${1}" + shift + ;; + -h | --help) + usage + exit 0 + ;; + -R | --repo) + submodule_dirs=("$(readlink -f "${1}")") + shift + if [[ ! -d ${submodule_dirs[0]} ]]; then + echo "Error: ${submodule_dirs[0]} is not valid." + usage + exit 1 + fi + ;; + -s | --skipsync) + skip_sync=1 + ;; + -V | --version) + exit 0 + ;; + *) + break + ;; + esac + done }
- main() { - show_version - get_args "$@" + show_version + get_args "$@"
- if (( ${#submodule_dirs[@]} == 0 )); then - readarray -t submodule_dirs < <(git submodule foreach pwd | grep -v "Entering") - fi + if ((${#submodule_dirs[@]} == 0)); then + readarray -t submodule_dirs < <(git submodule foreach pwd | grep -v "Entering") + fi
- for submodule in "${submodule_dirs[@]}"; do - echo "Checking submodule ${submodule}" - if ! cd "$submodule"; then - echo "Error: could not cd to $submodule" - exit 1 - fi + for submodule in "${submodule_dirs[@]}"; do + echo "Checking submodule ${submodule}" + if ! cd "$submodule"; then + echo "Error: could not cd to $submodule" + exit 1 + fi
- initial_commit_id="$(git log --pretty='%h' -n 1)" - initial_commit_description="$(git log --pretty='%ci - (%s)' -n 1)" - if [[ ${skip_sync} != "1" ]]; then - git fetch 2>/dev/null - fi + initial_commit_id="$(git log --pretty='%h' -n 1)" + initial_commit_description="$(git log --pretty='%ci - (%s)' -n 1)" + if [[ ${skip_sync} != "1" ]]; then + git fetch 2>/dev/null + fi
- if git branch -a | grep -q "origin/main"; then - branch_name="origin/main" - else - branch_name="origin/master" - fi + if git branch -a | grep -q "origin/main"; then + branch_name="origin/main" + else + branch_name="origin/master" + fi
- updated_commit_id="$(git log --pretty='%h' -n 1 "${branch_name}" -- )" - updated_commit_description="$(git log --pretty='%ci - (%s)' -n 1 "${updated_commit_id}")" - if [ "${initial_commit_id}" = "${updated_commit_id}" ]; then - echo "No updates for ${submodule}" - continue - fi - SUBMODULES_WITH_UPDATES+=1 - update_log="$(git log --oneline "${initial_commit_id}..${updated_commit_id}")" - update_count="$(echo "${update_log}" | wc -l)" - if [[ "${update_count}" -gt "${max_commits_to_list}" ]]; then - update_log="" - new_commit_terminator="." - else - new_commit_terminator=":" - fi - echo "${update_count} new commits for ${submodule}" - if [ "${update_count}" -ge "${min_commits}" ]; then - echo "Creating commit to update ${submodule##*/} submodule" - git checkout "${updated_commit_id}" > /dev/null 2>&1 - cd "${TOP}" || exit 1 - sleep 1 - git add "${submodule}" > /dev/null 2>&1 || exit 1 - sleep 1 - git commit -s -F- > /dev/null 2>&1 <<-EOF + updated_commit_id="$(git log --pretty='%h' -n 1 "${branch_name}" --)" + updated_commit_description="$(git log --pretty='%ci - (%s)' -n 1 "${updated_commit_id}")" + if [ "${initial_commit_id}" = "${updated_commit_id}" ]; then + echo "No updates for ${submodule}" + continue + fi + SUBMODULES_WITH_UPDATES+=1 + update_log="$(git log --oneline "${initial_commit_id}..${updated_commit_id}")" + update_count="$(echo "${update_log}" | wc -l)" + if [[ ${update_count} -gt ${max_commits_to_list} ]]; then + update_log="" + new_commit_terminator="." + else + new_commit_terminator=":" + fi + echo "${update_count} new commits for ${submodule}" + if [ "${update_count}" -ge "${min_commits}" ]; then + echo "Creating commit to update ${submodule##*/} submodule" + git checkout "${updated_commit_id}" >/dev/null 2>&1 + cd "${TOP}" || exit 1 + sleep 1 + git add "${submodule}" >/dev/null 2>&1 || exit 1 + #sleep 1 + git commit -s -F- >/dev/null 2>&1 <<-EOF Update ${submodule##*/} submodule to upstream master
Updating from commit id ${initial_commit_id}: @@ -149,13 +148,13 @@ This brings in ${update_count} new commits${new_commit_terminator} ${update_log} EOF - sleep 1 - fi - done + sleep 1 + fi + done
- if [ "${SUBMODULES_WITH_UPDATES}" = "0" ]; then - echo "No submodules with any updates." - fi + if [ "${SUBMODULES_WITH_UPDATES}" = "0" ]; then + echo "No submodules with any updates." + fi }
main "$@"