die() { printf "E: $@\n" >&2 exit 1 } tg_ds_resolve_commit() { git rev-parse --verify $1 2>/dev/null } . ${0%/*}/tg-datastore-pcommits.inc tg_ds_get_value() { local name; name="${1:-}" local commit; commit="${2:-HEAD}" [ -z "$1" ] && die 'tg_ds_get_value: missing first argument (name)' tg_ds_resolve_commit $commit >/dev/null || die "tg_ds_get_value: invalid commit: $commit" local data; data=$(tg_ds_list_data "$commit") || return 1 printf "$data\n" | sed -rne "s,^${name}: *,,p" } tg_ds_find_value() { local name; name="${1:-}" local commit; commit="${2:-HEAD}" [ -z "$1" ] && die 'tg_ds_find_value: missing first argument (name)' ref=$(tg_ds_resolve_commit $commit) || die "tg_ds_find_value: invalid commit: $commit" while :; do if [ "$name" = commitref ]; then tg_ds_list_data "$commit" >/dev/null && printf "$ref\n" && return 0 else tg_ds_get_value "$name" $commit && return 0 fi commit="${commit}^" ref=$(tg_ds_resolve_commit "${commit}") || break done return 1 }