]> git.madduck.net Git - code/topgit-ng.git/blobdiff - tg-datastore

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

import first prototype
[code/topgit-ng.git] / tg-datastore
diff --git a/tg-datastore b/tg-datastore
new file mode 100755 (executable)
index 0000000..e9ce139
--- /dev/null
@@ -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