Print help output when no command is given
[topgit/fonseca.git] / tg-summary.sh
blob3c90a6b5952e526bac9da80e84386d6abf6246a8
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 if [ -n "$graphviz" ]; then
28 cat <<EOT
29 # GraphViz output; pipe to:
30 # | dot -Tpng -o <ouput>
31 # or
32 # | dot -Txlib
34 digraph G {
36 graph [
37 rankdir = "TB"
38 label="TopGit Layout\n\n\n"
39 fontsize = 14
40 labelloc=top
41 pad = "0.5,0.5"
44 EOT
48 ## List branches
50 git for-each-ref refs/top-bases |
51 while read rev type ref; do
52 name="${ref#refs/top-bases/}"
53 if [ -n "$terse" ]; then
54 echo "$name"
55 continue
57 if [ -n "$graphviz" ]; then
58 git cat-file blob "$name:.topdeps" | while read dep; do
59 echo "\"$name\" -> \"$dep\";"
60 done
61 continue
64 missing_deps=
66 current=' '
67 [ "$name" != "$curname" ] || current='>'
68 nonempty=' '
69 ! branch_empty "$name" || nonempty='0'
70 remote=' '
71 [ -z "$base_remote" ] || remote='l'
72 ! has_remote "$name" || remote='r'
73 rem_update=' '
74 [ "$remote" != 'r' ] || ! ref_exists "refs/remotes/$base_remote/top-bases/$name" || {
75 branch_contains "refs/top-bases/$name" "refs/remotes/$base_remote/top-bases/$name" &&
76 branch_contains "$name" "refs/remotes/$base_remote/$name"
77 } || rem_update='R'
78 [ "$rem_update" = 'R' ] || branch_contains "refs/remotes/$base_remote/$name" "$name" 2>/dev/null ||
79 rem_update='L'
80 deps_update=' '
81 needs_update "$name" >/dev/null || deps_update='D'
82 deps_missing=' '
83 [ -z "$missing_deps" ] || deps_missing='!'
84 base_update=' '
85 branch_contains "$name" "refs/top-bases/$name" || base_update='B'
87 if [ "$(git rev-parse "$name")" != "$rev" ]; then
88 subject="$(git cat-file blob "$name:.topmsg" | sed -n 's/^Subject: //p')"
89 else
90 # No commits yet
91 subject="(No commits)"
94 printf '%s\t%-31s\t%s\n' "$current$nonempty$remote$rem_update$deps_update$deps_missing$base_update" \
95 "$name" "$subject"
96 done
98 if [ -n "$graphviz" ]; then
99 echo '}'