diff options
| author | tv <tv@krebsco.de> | 2026-11-29 14:14:05 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-29 14:14:05 +0000 |
| commit | 244d2a5a635811b309caf3d99013bcb3f2e6a69f (patch) | |
| tree | de05ff69b626e96bfd5de08e736660afb30ce79f /pkgs/shell | |
| parent | 3d8a0d85fef0c467de1eccd37cd1ded989a1ec1d (diff) | |
Moves the entries of sources.json that follow a branch to its head, or
the named ones. It refuses entries pinned by hand, and ones with a hash,
which it can't compute.
Diffstat (limited to 'pkgs/shell')
| -rwxr-xr-x | pkgs/shell/update-sources | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/pkgs/shell/update-sources b/pkgs/shell/update-sources new file mode 100755 index 00000000..a50a1ed2 --- /dev/null +++ b/pkgs/shell/update-sources @@ -0,0 +1,55 @@ +#! /bin/sh +#!buildShellBin path=coreutils:git:jq +# usage: update-sources [NAME...] +# +# Moves each named entry of sources.json, or each one with a branch, to +# the head of its branch. + +set -efu + +cd "$HOME/sync/src/hrm" + +if test $# = 0; then + set -- $(jq -r 'to_entries[] | select(.value.branch) | .key' sources.json) +fi + +tmpdir=$(mktemp -d --tmpdir update-sources.XXXXXXXX) +trap 'rm -fR "$tmpdir"' EXIT + +new=$(cat sources.json) + +for name; do + if ! entry=$(jq -ce --arg name "$name" '.[$name]' sources.json); then + echo "update-sources: $name: no such source" >&2 + exit 1 + fi + url=$(echo "$entry" | jq -r .url) + branch=$(echo "$entry" | jq -r '.branch // empty') + if test -z "$branch"; then + echo "update-sources: $name: pinned by hand" >&2 + exit 1 + fi + if echo "$entry" | jq -e 'has("hash")' >/dev/null; then + echo "update-sources: $name: can't compute the hash of a source that follows a branch" >&2 + exit 1 + fi + + repo=$tmpdir/$(echo "$name" | tr / _) + git init -q --bare "$repo" + git -C "$repo" fetch -q --depth 1 --filter=tree:0 "$url" "refs/heads/$branch" + rev=$(git -C "$repo" rev-parse FETCH_HEAD) + date=$(TZ=UTC git -C "$repo" log -1 --format=%ad --date=format-local:%Y-%m-%dT%H:%M:%SZ FETCH_HEAD) + + old_rev=$(echo "$entry" | jq -r .rev) + if test "$rev" = "$old_rev"; then + echo "$name: $(echo "$rev" | cut -c-7) (no change since $date)" + else + echo "$name: $(echo "$old_rev" | cut -c-7) -> $(echo "$rev" | cut -c-7) (last change $date)" + new=$(echo "$new" | jq -S --arg name "$name" --arg rev "$rev" --arg date "$date" ' + .[$name] += { rev: $rev, date: $date } + ') + fi +done + +cp sources.json sources.json~ +echo "$new" | jq -S . > sources.json |
