From 7210a46fda8537d59aa7421cc1b2989dc8085590 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 30 Apr 2017 17:38:50 -0400 Subject: Add repo-mutate module --- repo-mutate.sh | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 repo-mutate.sh diff --git a/repo-mutate.sh b/repo-mutate.sh new file mode 100644 index 0000000..d88452e --- /dev/null +++ b/repo-mutate.sh @@ -0,0 +1,114 @@ +## +# systr_repo_create_commit [] +# +# Create a new commit directory within the repository. This function +# is polymorphic for both local and remote repositories. The new +# commit ID is printed to stdout. +## +function systr_repo_create_commit +{ + if [ $# -gt 0 ]; then + path="$1" + fi + + if [[ "$remote" == "" ]]; then + ( + cd "$path" + cd "revs/" + mktemp -d XXXXXXXX + ) + else + ssh "$remote" "systrunk create-commit \"$path\"" + fi +} + +## +# systr_repo_finish_commit [] +# +# Finish writing a commit by adding meta-data to the commit directory. +# The commit mesasge is taken from the file .mesg at the root +# of the repository directory. If is given, it is written to +# .merge.systr in the commit. This function is polymorphic for both +# local and remote repositories. +## +function systr_repo_finish_commit +{ + if [ $# -lt 4 ]; then + echo "Fatal: too few arguments to systr_repo_finish_commit" + exit 1 + fi + + commit="$1" + parent="$2" + author="$3" + email="$4" + + if [ $# -gt 4 ]; then + merge="$5" + else + merge="" + fi + + if [[ "$remote" == "" ]]; then + ( + cd "$path" + cd "revs/" + cd "$commit" + + echo "$parent" >.commit.systr + echo "$author" >.author.systr + echo "$email" >.email.systr + + mv "../$commit.mesg" ".mesg.systr" + + if [[ "$merge" != "" ]]; then + echo "$merge" >.merge.systr + fi + ) + else + ssh "$remote" "systrunk finish-commit \"$commit\" \"$parent\" \ + \"$author\" \"$email\" \"$merge\"" + fi +} + +## +# systr_repo_set_reference +# +# Update to point to . If doesn't exist, +# it is created. This function is polymorphic for both local and +# remote repositories. +## +function systr_repo_set_reference +{ + if [ $# -lt 2 ]; then + echo "Fatal: too few arguments to systr_repo_set_reference" + exit 1 + fi + + symref="$1" + commit="$2" + + if [[ "$symref" == "BASE" ]]; then + echo "Fatal: will not define BASE in the repository" + exit 1 + elif [[ "$symref" == "TRAC" ]]; then + echo "Fatal: will not define TRAC in the repository" + exit 1 + elif [[ "$symref" == "NULL" ]]; then + echo "Fatal: will not define NULL in the repository" + exit 1 + elif [[ "$symref" == "MERG" ]]; then + echo "Fatal: will not define MERG in the repository" + exit 1 + fi + + if [[ "$remote" == "" ]]; then + ( + cd "$path" + cd "refs/" + echo "$commit" >"$symref" + ) + else + ssh "$remote" "systrunk set-ref \"$symref\" \"$commit\"" + fi +} -- cgit v1.2.3