~ecs/tm

ref: 95cb618f450695312ff6849e7c6e86709e985ae9 tm/tm-read-commit -rwxr-xr-x 1.0 KiB
95cb618fEmber Sawady init: use commit instead of commit-tree 1 year, 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/sh

. "$(dirname -- "$0")/lib.sh"
mode=t
while getopts tpacdsb opt; do
	case "$opt" in
	\?)
		abort "usage: tm read-commit [-t|-p|-a|-c|-d|-s|-b] <ref>"
		;;
	*)
		mode="$opt"
		;;
	esac
done

shift "$((OPTIND - 1))"

[ $# -eq 1 ] || abort "usage: tm read-commit [-t|-p|-a|-c|-d|-s|-b] <ref>"
script=
case "$mode" in
t) script='/^tree / { sub(/^tree /, ""); print }';;
p) script='/^parent / { sub(/^parent /, ""); print } /^date/ { exit }';;
a) script='/^author / { sub(/^author /, ""); print; exit }';;
c) script='/^committer / { sub(/^committer /, ""); print; exit }';;
d) script='/^date / { sub(/^date /, ""); print; exit }';;
s) script='BEGIN { mode="wait" } { if (mode == "subject") { print; exit } } /^date / { mode="subject" }';;
b) script='BEGIN { mode="wait" } { if (mode == "subject") { mode="body" } else if (mode == "body") { print } } /^date / { mode="subject" }';;
*) abort "error: cosmic rays have corrupted the mode variable, try moving your computer into a neutrino detection center";;
esac
exec tm cat "$1" | awk -- "$script"