diff --git a/updatemodules b/updatemodules index 2a1ee0e..200e424 100755 --- a/updatemodules +++ b/updatemodules @@ -3,18 +3,21 @@ set -e # config options declare -A keep -remote="origin" -branch="main" -package_base_url= -package_relative_url="../../rpm" +REMOTE="origin" +BASE_BRANCH="main" +PACKAGE_BASE_URL= +PACKAGE_RELATIVE_URL="../../rpm" # https://api.opensuse.org/public/source/openSUSE:Factory:Rings:0-Bootstrap -ring0api= -date="$(date "+%s %z")" +RING0API= +DATE="$(date "+%s %z")" keep["dummy-release"]=1 # command line only single= verbose=0 +cfg_file= + +################### # constant needed to aid quoting nl=$'\n' @@ -87,11 +90,11 @@ while true ; do -v|--verbose) verbose=$((++verbose)); shift ;; -c|--config) cfg_file="$2"; shift 2 ;; --single) single=1; shift ;; - --remote) remote="$2"; shift 2 ;; - --branch) branch="$2"; shift 2 ;; + --remote) REMOTE="$2"; shift 2 ;; + --branch) BASE_BRANCH="$2"; shift 2 ;; --status) show_status; exit 0 ;; --clear) clear_queue; exit 0 ;; - --date) date="$2"; shift 2 ;; + --date) DATE="$2"; shift 2 ;; --) shift ; break ;; *) echo "Internal error!" ; exit 1 ;; esac @@ -99,21 +102,22 @@ done modules=("$@") -if [ "${date:0:1}" = '@' ]; then - date="$(stat -c %Y "${date:1}") +0100" -fi - -package_base_url="$(git config --get remote."$remote".url)" -export GIT_AUTHOR_NAME="Auto" -export GIT_AUTHOR_EMAIL="auto@suse.de" -export GIT_AUTHOR_DATE="$date" -export GIT_COMMITTER_NAME="Auto" -export GIT_COMMITTER_EMAIL="auto@suse.de" -export GIT_COMMITTER_DATE="$date" +PACKAGE_BASE_URL="$(git config --get remote."$REMOTE".url)" # shellcheck disable=SC1090 . "${cfg_file:-.settings}" +if [ "${DATE:0:1}" = '@' ]; then + DATE="$(stat -c %Y "${DATE:1}") +0100" +fi + +export GIT_AUTHOR_NAME="Auto" +export GIT_AUTHOR_EMAIL="auto@suse.de" +export GIT_AUTHOR_DATE="$DATE" +export GIT_COMMITTER_NAME="Auto" +export GIT_COMMITTER_EMAIL="auto@suse.de" +export GIT_COMMITTER_DATE="$DATE" + tmpfile=$(mktemp updatemodules.XXXXXX) tmpfile2=$(mktemp updatemodules.XXXXXX) cleanup() @@ -129,13 +133,13 @@ while read -r m t cid p; do fi [ "$t" = "commit" ] || continue revs["$p"]="$cid" -done < <(git cat-file -p "$remote/$branch^{tree}") +done < <(git cat-file -p "$REMOTE/$BASE_BRANCH^{tree}") -if [ -n "$ring0api" ]; then +if [ -n "$RING0API" ]; then while read -r p; do ring0["$p"]=1 [ -n "${revs[$p]}" ] || new["$p"]=1 - done < <(curl -s -f "$ring0api"|sed -ne 's/.*entry name="\([^":]*\).*\/>/\1/p'|sort -u | grep -v AGGR) + done < <(curl -s -f "$RING0API"|sed -ne 's/.*entry name="\([^":]*\).*\/>/\1/p'|sort -u | grep -v AGGR) for m in "${!revs[@]}"; do [ -n "${ring0[$m]}" -o -n "${keep[$m]}" ] || drop["$m"]=1 @@ -151,13 +155,13 @@ fi # check remotes for updates declare -A commits -treetext=$(git cat-file -p "$remote/$branch^{tree}") -git cat-file -p "$remote/$branch":.gitmodules > "$tmpfile" +treetext=$(git cat-file -p "$REMOTE/$BASE_BRANCH^{tree}") +git cat-file -p "$REMOTE/$BASE_BRANCH":.gitmodules > "$tmpfile" cat "$tmpfile" > "$tmpfile2" for m in "${modules[@]}"; do if isnew "$m"; then path="$m" - url="$package_relative_url/$m" + url="$PACKAGE_RELATIVE_URL/$m" smbranch= git config -f "$tmpfile" --add "submodule.$m.path" "$path" git config -f "$tmpfile" --add "submodule.$m.url" "$url" @@ -171,16 +175,18 @@ for m in "${modules[@]}"; do continue fi if [ "${url:0:3}" = '../' ]; then - url="$package_base_url/$url" + url="$PACKAGE_BASE_URL/$url" fi cid= if ! todrop "$m"; then + set -x read -r cid _d < <(git ls-remote "$url" "${smbranch:-HEAD}") if [ -z "$cid" ]; then echo "$path not in pool" >&2 continue fi + set +x fi # create a new commit for this package @@ -209,7 +215,7 @@ for m in "${modules[@]}"; do msg="Update $m" isnew "$m" && msg="Add $m" todrop "$m" && msg="Remove $m" - newcid="$(git commit-tree -p "$remote/$branch" -m "$msg" "$newtree")" + newcid="$(git commit-tree -p "$REMOTE/$BASE_BRANCH" -m "$msg" "$newtree")" commits["$m"]="$newcid" cat "$tmpfile2" > "$tmpfile" fi @@ -218,10 +224,11 @@ done if [ "$single" = 1 ]; then newtree="$(echo "$treetext" | git mktree)" - newcid="$(git commit-tree -p "$remote/$branch" -m "Update all" "$newtree")" + newcid="$(git commit-tree -p "$REMOTE/$BASE_BRANCH" -m "Update all" "$newtree")" commits["all"]="$newcid" fi +# push queue declare -A pq makedict pq git for-each-ref 'refs/pq/*' --format '%(refname)'