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

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.inc
1 die()
2 {
3   printf "E: $@\n" >&2
4   exit 1
5 }
6
7 tg_ds_resolve_commit()
8 {
9   git rev-parse --verify $1 2>/dev/null
10 }
11
12 . ${0%/*}/tg-datastore-pcommits.inc
13
14 tg_ds_get_value()
15 {
16   local name; name="${1:-}"
17   local commit; commit="${2:-HEAD}"
18
19   [ -z "$1" ] && die 'tg_ds_get_value: missing first argument (name)'
20   tg_ds_resolve_commit $commit >/dev/null || die "tg_ds_get_value: invalid commit: $commit"
21
22   local data; data=$(tg_ds_list_data "$commit") || return 1
23   printf "$data\n" | sed -rne "s,^${name}: *,,p"
24 }
25
26 tg_ds_find_value()
27 {
28   local name; name="${1:-}"
29   local commit; commit="${2:-HEAD}"
30
31   [ -z "$1" ] && die 'tg_ds_find_value: missing first argument (name)'
32   ref=$(tg_ds_resolve_commit $commit) || die "tg_ds_find_value: invalid commit: $commit"
33
34   while :; do
35     if [ "$name" = commitref ]; then
36       tg_ds_list_data "$commit" >/dev/null && printf "$ref\n" && return 0
37     else
38       tg_ds_get_value "$name" $commit && return 0
39     fi
40     commit="${commit}^"
41     ref=$(tg_ds_resolve_commit "${commit}") || break
42   done
43
44   return 1
45 }