]> git.madduck.net Git - code/topgit-ng.git/blob - 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
1 #!/bin/sh
2 set -eu
3
4 . ${0%/*}/tg-datastore.inc
5
6 info() { printf "I: $@\n" >&2; }
7
8 case "$1" in
9   add)
10     # tg-datastore add var=val var2=val2 ...
11     # only add to HEAD
12     shift
13     info "returns non-zero if there is already a datastore on HEAD."
14     info "adding the following data to the datastore of HEAD:"
15     for pair in "$@"; do
16       info "  ${pair%%=*}: ${pair#*=}\n"
17       printf "${pair%%=*}: ${pair#*=}\n"
18     done | tg_ds_add_data || die "E: HEAD already has a datastore"
19     ;;
20   remove)
21     # removes from HEAD
22     info "always returns zero, even if there was nothing to remove."
23     tg_ds_remove_data
24     ;;
25   list)
26     # $2 is the commit
27     info "returns non-zero if no datastore found at given commit."
28     info "prints contents of datastore otherwise."
29     tg_ds_list_data "${2:-HEAD}"
30     ;;
31   get)
32     # get parameter $2 from $3 (default HEAD)
33     info "prints the value of the parameter stored in the given commit."
34     info "prints nothing if the commit has a datastore but without the parameter."
35     info "returns non-zero if there is no datastore."
36     tg_ds_get_value "$2" ${3:-HEAD}
37     ;;
38   find)
39     # search for parameter $2 by backtracking from $3 (default HEAD)
40     info "prints the value of the parameter, or empty if parameter is not found."
41     info "returns non-zero if no datastore was found."
42     tg_ds_find_value "$2" ${3:-HEAD}
43     ;;
44   *)
45     echo "Usage: ${0##*/} [ add var=val... | remove | list | get var [commit] | find var [commit] ]"
46     ;;
47 esac