X-Git-Url: https://git.madduck.net/code/topgit-ng.git/blobdiff_plain/34bbe7c33ac672f2fc80f639277f9ba750a3d957..dc58ec49df849ec1aef6929cd40c759a6018e056:/tg-datastore diff --git a/tg-datastore b/tg-datastore new file mode 100755 index 0000000..e9ce139 --- /dev/null +++ b/tg-datastore @@ -0,0 +1,47 @@ +#!/bin/sh +set -eu + +. ${0%/*}/tg-datastore.inc + +info() { printf "I: $@\n" >&2; } + +case "$1" in + add) + # tg-datastore add var=val var2=val2 ... + # only add to HEAD + shift + info "returns non-zero if there is already a datastore on HEAD." + info "adding the following data to the datastore of HEAD:" + for pair in "$@"; do + info " ${pair%%=*}: ${pair#*=}\n" + printf "${pair%%=*}: ${pair#*=}\n" + done | tg_ds_add_data || die "E: HEAD already has a datastore" + ;; + remove) + # removes from HEAD + info "always returns zero, even if there was nothing to remove." + tg_ds_remove_data + ;; + list) + # $2 is the commit + info "returns non-zero if no datastore found at given commit." + info "prints contents of datastore otherwise." + tg_ds_list_data "${2:-HEAD}" + ;; + get) + # get parameter $2 from $3 (default HEAD) + info "prints the value of the parameter stored in the given commit." + info "prints nothing if the commit has a datastore but without the parameter." + info "returns non-zero if there is no datastore." + tg_ds_get_value "$2" ${3:-HEAD} + ;; + find) + # search for parameter $2 by backtracking from $3 (default HEAD) + info "prints the value of the parameter, or empty if parameter is not found." + info "returns non-zero if no datastore was found." + tg_ds_find_value "$2" ${3:-HEAD} + ;; + *) + echo "Usage: ${0##*/} [ add var=val... | remove | list | get var [commit] | find var [commit] ]" + ;; +esac