carbon-core-system

Integration repository for versioned configuration and software on Carbon
git clone https://ccx.te2000.cz/git/carbon-core-system
Log | Files | Refs | Submodules

commit 3b43c7b697c370dd54a5d2f77ae6e3cfa2683aae
parent cb3b26538a6aec3c9533501fdb1e10a69b938694
Author: ccx <root@dorje.wpr.cz>
Date:   Fri, 18 Feb 2022 17:38:53 +0100

Preliminary support for bzr repositories.

Diffstat:
Abzr/revisions | 0
Abzr/sources | 5+++++
Aupdate-bzr | 158+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 163 insertions(+), 0 deletions(-)

diff --git a/bzr/revisions b/bzr/revisions diff --git a/bzr/sources b/bzr/sources @@ -0,0 +1,5 @@ +confz /home/ccx/bzr/confz +containers /home/ccx/bzr/containers +fileset /home/ccx/bzr/fileset +logincaps /home/ccx/bzr/logincaps +snaprep /home/ccx/bzr/snaprep diff --git a/update-bzr b/update-bzr @@ -0,0 +1,158 @@ +#!/bin/zsh +setopt no_unset warn_create_global extended_glob +zmodload -F zsh/stat b:zstat || exit $? +zmodload -m -F zsh/files b:zf_\* || exit $? +zmodload zsh/zutil || exit $? + +die_ret() { + local ret + ret=$1 + shift + echo >&2 "$@" + exit $ret +} +die() { + die_ret 1 "$@" +} +cd $0:h || exit $? + +pretend() { + : "$@" +} +typeset -ft pretend + +load_sources() { + unset repo_sources + typeset -gA repo_sources + unset repos + typeset -ga repos + + local name url + <./bzr/sources while IFS=$'\t' read name url; do + [[ -n "$name" && -n "$url" ]] || die "Malformed sources file" + (( $+repo_sources[$name] )) && die "Duplicate repo name: ${(qqq)name}" + repo_sources[$name]=$url + repos+=( $name ) + done +} + +make_revisions_new() { + unset revisions_new + typeset -gA revisions_new + + local name url + local -a info + for name in $repos; do + info=( $(brz version-info $repo_sources[$name]) ) || + die_ret $? brz version-info failed + [[ $info[1] == "revision-id:" ]] || + die malformed brz version-info output + revisions_new[$name]=$info[2] + printf '%s\t%s\n' $name $info[2] || exit $? + done +} + +load_old_revisions() { + unset revisions_old + typeset -gA revisions_old + + local name revid + <./bzr/revisions while IFS=$'\t' read name revid; do + [[ -n "$name" && -n "$revid" ]] || die "Malformed revisions file" + (( $+revisions_old[$name] )) && die "Duplicate repo name: ${(qqq)name}" + revisions_old[$name]=$revid + done +} + +compare_revisions() { + unset repo_status + typeset -gA repo_status + typeset -ga repos_modified repos_added repos_deleted repos_same + + local name old_revid + for name in $repos; do + if ! (($+revisions_old[$name])); then + repo_status[$name]=A + repos_added+=( $name ) + elif [[ $revisions_new[$name] != $revisions_old[$name] ]]; then; + repo_status[$name]=M + repos_modified+=( $name ) + else + repos_same+=( $name ) + fi + done + for name in "${(@k)revisions_old}"; do + if ! (($+revisions_new[$name])); then + repo_status[$name]=D + repos_deleted+=( $name ) + fi + done +} + +bzrlog() { + # first argument needs to be revision range + brz log --show-diff --long --forward -r "$@" +} + +show_diffs() { + local name + for name in $repos_modified; do + printf "== showing differences for %s == %s -> %s ==\n" $name $revisions_old[$name] $revisions_new[$name] + bzrlog "revid:$revisions_old[$name]..revid:$revisions_new[$name]" $repo_sources[$name] + done + for name in $repos_added; do + printf "== showing differences for %s == %s -> %s ==\n" $name start $revisions_new[$name] + bzrlog "..revid:$revisions_new[$name]" $repo_sources[$name] + done + echo --- + printf '%d repositories modified' $#repos_modified + (( $#repos_modified )) && printf ': %s' "$repos_modified" + print + + printf '%d repositories added' $#repos_added + (( $#repos_added )) && printf ': %s' "$repos_added" + print + + printf '%d repositories deleted' $#repos_deleted + (( $#repos_deleted )) && printf ': %s' "$repos_deleted" + print + + printf '%d repositories same' $#repos_same + (( $#repos_same )) && printf ': %s' "$repos_same" + print +} + +prompt_commit() { + local REPLY + local -a msg + diff -u ./bzr/revisions ./bzr/revisions.new + echo -n "Apply and commit changes? " + read -q || exit 0 + echo + msg=( + "Update bzr repositories." + "Added: "$^repos_added + "Changed: "$^repos_modified + "Deleted: "$^repos_deleted + ) + pretend mv -v ./bzr/revisions.new ./bzr/revisions || exit $? + pretend git add ./bzr/revisions || exit $? + pretend git commit -m "${(F)msg}" ./bzr/revisions || exit $? +} + +main() { + load_sources + make_revisions_new >bzr/revisions.new + + load_old_revisions + compare_revisions + #printf "%s\t%s\n" "${(@vk)repo_status}" + show_diffs | less --quit-if-one-screen + if ! (( $#repos_added + $#repos_modified + $#repos_deleted )); then + echo "Nothing to do" + exit 0 + fi + prompt_commit +} +#typeset -ft main +main