Indicate the current branch in "tg summary --graphviz"
[topgit/greenrd.git] / tg-summary.sh
blobaf16888c1797db909dbcff7d2ff15c1cf0ec0b28
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # (c) Petr Baudis <pasky@suse.cz> 2008
4 # GPLv2
6 terse=
7 graphviz=
8 sort=
9 deps=
12 ## Parse options
14 while [ -n "$1" ]; do
15 arg="$1"; shift
16 case "$arg" in
17 -t)
18 terse=1;;
19 --graphviz)
20 graphviz=1;;
21 --sort)
22 sort=1;;
23 --deps)
24 deps=1;;
26 echo "Usage: tg [...] summary [-t | --sort | --deps | --graphviz]" >&2
27 exit 1;;
28 esac
29 done
31 curname="$(git symbolic-ref HEAD | sed 's#^refs/\(heads\|top-bases\)/##')"
33 [ "$terse$graphviz$sort$deps" = "" ] ||
34 [ "$terse$graphviz$sort$deps" = "1" ] ||
35 die "mutually exclusive options given"
37 if [ -n "$graphviz" ]; then
38 cat <<EOT
39 # GraphViz output; pipe to:
40 # | dot -Tpng -o <ouput>
41 # or
42 # | dot -Txlib
44 digraph G {
46 graph [
47 rankdir = "TB"
48 label="TopGit Layout\n\n\n"
49 fontsize = 14
50 labelloc=top
51 pad = "0.5,0.5"
54 EOT
57 if [ -n "$sort" ]; then
58 tsort_input=`mktemp`
59 exec 4>$tsort_input
60 exec 5<$tsort_input
61 rm $tsort_input
64 ## List branches
66 process_branch()
68 missing_deps=
70 current=' '
71 [ "$name" != "$curname" ] || current='>'
72 nonempty=' '
73 ! branch_empty "$name" || nonempty='0'
74 remote=' '
75 [ -z "$base_remote" ] || remote='l'
76 ! has_remote "$name" || remote='r'
77 rem_update=' '
78 [ "$remote" != 'r' ] || ! ref_exists "refs/remotes/$base_remote/top-bases/$name" || {
79 branch_contains "refs/top-bases/$name" "refs/remotes/$base_remote/top-bases/$name" &&
80 branch_contains "$name" "refs/remotes/$base_remote/$name"
81 } || rem_update='R'
82 [ "$rem_update" = 'R' ] || branch_contains "refs/remotes/$base_remote/$name" "$name" 2>/dev/null ||
83 rem_update='L'
84 deps_update=' '
85 needs_update "$name" >/dev/null || deps_update='D'
86 deps_missing=' '
87 [ -z "$missing_deps" ] || deps_missing='!'
88 base_update=' '
89 branch_contains "$name" "refs/top-bases/$name" || base_update='B'
91 if [ "$(git rev-parse "$name")" != "$rev" ]; then
92 subject="$(git cat-file blob "$name:.topmsg" | sed -n 's/^Subject: //p')"
93 else
94 # No commits yet
95 subject="(No commits)"
98 printf '%s\t%-31s\t%s\n' "$current$nonempty$remote$rem_update$deps_update$deps_missing$base_update" \
99 "$name" "$subject"
102 if [ -n "$deps" ]; then
103 list_deps
104 exit 0
107 git for-each-ref refs/top-bases |
108 while read rev type ref; do
109 name="${ref#refs/top-bases/}"
110 if branch_annihilated "$name"; then
111 continue;
114 if [ -n "$terse" ]; then
115 echo "$name"
116 elif [ -n "$graphviz$sort" ]; then
117 git cat-file blob "$name:.topdeps" | while read dep; do
118 dep_is_tgish=true
119 ref_exists "refs/top-bases/$dep" ||
120 dep_is_tgish=false
121 if ! "$dep_is_tgish" || ! branch_annihilated $dep; then
122 if [ -n "$graphviz" ]; then
123 echo "\"$name\" -> \"$dep\";"
124 if [ "$name" = "$curname" ] || [ "$dep" = "$curname" ]; then
125 echo "\"$curname\" [style=filled,fillcolor=yellow];"
127 else
128 echo "$name $dep" >&4
131 done
132 else
133 process_branch
135 done
137 if [ -n "$graphviz" ]; then
138 echo '}'
141 if [ -n "$sort" ]; then
142 tsort <&5
146 # vim:noet