deal with single quotes in from/to headers
[topgit/lukasnellen.git] / tg-summary.sh
blob50ee8832090c6646c9bd114d6f5926657dcc07db
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # (c) Petr Baudis <pasky@suse.cz> 2008
4 # GPLv2
6 terse=
7 graphviz=
10 ## Parse options
12 while [ -n "$1" ]; do
13 arg="$1"; shift
14 case "$arg" in
15 -t)
16 terse=1;;
17 --graphviz)
18 graphviz=1;;
20 echo "Usage: tg [...] summary [-t | --graphviz]" >&2
21 exit 1;;
22 esac
23 done
25 curname="$(git symbolic-ref HEAD | sed 's#^refs/\(heads\|top-bases\)/##')"
27 ! [ -n "$terse" -a -n "$graphviz" ] ||
28 die "-t and --graphviz options are mutual exclusive"
30 if [ -n "$graphviz" ]; then
31 cat <<EOT
32 # GraphViz output; pipe to:
33 # | dot -Tpng -o <ouput>
34 # or
35 # | dot -Txlib
37 digraph G {
39 graph [
40 rankdir = "TB"
41 label="TopGit Layout\n\n\n"
42 fontsize = 14
43 labelloc=top
44 pad = "0.5,0.5"
47 EOT
51 ## List branches
53 git for-each-ref refs/top-bases |
54 while read rev type ref; do
55 name="${ref#refs/top-bases/}"
56 if branch_annihilated "$name"; then
57 continue;
58 fi;
60 if [ -n "$terse" ]; then
61 echo "$name"
62 continue
64 if [ -n "$graphviz" ]; then
65 git cat-file blob "$name:.topdeps" | while read dep; do
66 dep_is_tgish=true
67 ref_exists "refs/top-bases/$dep" ||
68 dep_is_tgish=false
69 if ! "$dep_is_tgish" || ! branch_annihilated $dep; then
70 echo "\"$name\" -> \"$dep\";"
72 done
73 continue
76 missing_deps=
78 current=' '
79 [ "$name" != "$curname" ] || current='>'
80 nonempty=' '
81 ! branch_empty "$name" || nonempty='0'
82 remote=' '
83 [ -z "$base_remote" ] || remote='l'
84 ! has_remote "$name" || remote='r'
85 rem_update=' '
86 [ "$remote" != 'r' ] || ! ref_exists "refs/remotes/$base_remote/top-bases/$name" || {
87 branch_contains "refs/top-bases/$name" "refs/remotes/$base_remote/top-bases/$name" &&
88 branch_contains "$name" "refs/remotes/$base_remote/$name"
89 } || rem_update='R'
90 [ "$rem_update" = 'R' ] || branch_contains "refs/remotes/$base_remote/$name" "$name" 2>/dev/null ||
91 rem_update='L'
92 deps_update=' '
93 needs_update "$name" >/dev/null || deps_update='D'
94 deps_missing=' '
95 [ -z "$missing_deps" ] || deps_missing='!'
96 base_update=' '
97 branch_contains "$name" "refs/top-bases/$name" || base_update='B'
99 if [ "$(git rev-parse "$name")" != "$rev" ]; then
100 subject="$(git cat-file blob "$name:.topmsg" | sed -n 's/^Subject: //p')"
101 else
102 # No commits yet
103 subject="(No commits)"
106 printf '%s\t%-31s\t%s\n' "$current$nonempty$remote$rem_update$deps_update$deps_missing$base_update" \
107 "$name" "$subject"
108 done
110 if [ -n "$graphviz" ]; then
111 echo '}'
114 # vim:noet