Merge commit 'index-wt~2' of git://repo.or.cz/topgit/bertw
[topgit/bertw.git] / tg-summary.sh
blob1c99e2225c61a2a4c9a07ec6bd64ee82558ddda7
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=
10 head_from=
12 ## Parse options
14 while [ -n "$1" ]; do
15 arg="$1"; shift
16 case "$arg" in
17 -i|-w)
18 [ -z "$head_from" ] || die "-i and -w are mutually exclusive"
19 head_from="$arg";;
20 -t)
21 terse=1;;
22 --graphviz)
23 graphviz=1;;
24 --sort)
25 sort=1;;
26 --deps)
27 deps=1;;
29 echo "Usage: tg [...] summary [-t | --sort | --deps | --graphviz] [-i | -w]" >&2
30 exit 1;;
31 esac
32 done
34 curname="$(git symbolic-ref HEAD | sed 's#^refs/\(heads\|top-bases\)/##')"
36 [ "$terse$graphviz$sort$deps" = "" ] ||
37 [ "$terse$graphviz$sort$deps" = "1" ] ||
38 die "mutually exclusive options given"
40 if [ -n "$graphviz" ]; then
41 cat <<EOT
42 # GraphViz output; pipe to:
43 # | dot -Tpng -o <ouput>
44 # or
45 # | dot -Txlib
47 digraph G {
49 graph [
50 rankdir = "TB"
51 label="TopGit Layout\n\n\n"
52 fontsize = 14
53 labelloc=top
54 pad = "0.5,0.5"
57 EOT
60 if [ -n "$sort" ]; then
61 tsort_input="$(get_temp tg-summary-sort)"
62 exec 4>$tsort_input
63 exec 5<$tsort_input
66 ## List branches
68 process_branch()
70 missing_deps=
72 current=' '
73 [ "$name" != "$curname" ] || current='>'
74 from=$head_from
75 [ "$name" = "$curname" ] ||
76 from=
77 nonempty=' '
78 ! branch_empty "$name" $from || nonempty='0'
79 remote=' '
80 [ -z "$base_remote" ] || remote='l'
81 ! has_remote "$name" || remote='r'
82 rem_update=' '
83 [ "$remote" != 'r' ] || ! ref_exists "refs/remotes/$base_remote/top-bases/$name" || {
84 branch_contains "refs/top-bases/$name" "refs/remotes/$base_remote/top-bases/$name" &&
85 branch_contains "$name" "refs/remotes/$base_remote/$name"
86 } || rem_update='R'
87 [ "$rem_update" = 'R' ] || branch_contains "refs/remotes/$base_remote/$name" "$name" 2>/dev/null ||
88 rem_update='L'
89 deps_update=' '
90 needs_update "$name" >/dev/null || deps_update='D'
91 deps_missing=' '
92 [ -z "$missing_deps" ] || deps_missing='!'
93 base_update=' '
94 branch_contains "$name" "refs/top-bases/$name" || base_update='B'
96 if [ "$(git rev-parse "$name")" != "$rev" ]; then
97 subject="$(cat_file "$name:.topmsg" $from | sed -n 's/^Subject: //p')"
98 else
99 # No commits yet
100 subject="(No commits)"
103 printf '%s\t%-31s\t%s\n' "$current$nonempty$remote$rem_update$deps_update$deps_missing$base_update" \
104 "$name" "$subject"
107 if [ -n "$deps" ]; then
108 list_deps $head_from
109 exit 0
112 git for-each-ref refs/top-bases |
113 while read rev type ref; do
114 name="${ref#refs/top-bases/}"
115 if branch_annihilated "$name"; then
116 continue;
119 if [ -n "$terse" ]; then
120 echo "$name"
121 elif [ -n "$graphviz$sort" ]; then
122 from=$head_from
123 [ "$name" = "$curname" ] ||
124 from=
125 cat_file "$name:.topdeps" $from | while read dep; do
126 dep_is_tgish=true
127 ref_exists "refs/top-bases/$dep" ||
128 dep_is_tgish=false
129 if ! "$dep_is_tgish" || ! branch_annihilated $dep; then
130 if [ -n "$graphviz" ]; then
131 echo "\"$name\" -> \"$dep\";"
132 if [ "$name" = "$curname" ] || [ "$dep" = "$curname" ]; then
133 echo "\"$curname\" [style=filled,fillcolor=yellow];"
135 else
136 echo "$name $dep" >&4
139 done
140 else
141 process_branch
143 done
145 if [ -n "$graphviz" ]; then
146 echo '}'
149 if [ -n "$sort" ]; then
150 tsort <&5
154 # vim:noet