tg.sh: next version is 0.17.1
[topgit/pro.git] / tg-summary.sh
blob2db2f2476571d52264556c123c55eb01d28ea506
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # (C) Petr Baudis <pasky@suse.cz> 2008
4 # (C) Kyle J. McKay <mackyle@gmail.com> 2015
5 # GPLv2
7 terse=
8 graphviz=
9 sort=
10 deps=
11 rdeps=
12 head_from=
13 branch=
14 head=
15 exclude=
17 ## Parse options
19 usage()
21 echo "Usage: ${tgname:-tg} [...] summary [-t | --sort | --deps | --rdeps | --graphviz] [-i | -w] [--exclude branch]... [--all | branch]" >&2
22 exit 1
25 while [ -n "$1" ]; do
26 arg="$1"
27 case "$arg" in
28 -i|-w)
29 [ -z "$head_from" ] || die "-i and -w are mutually exclusive"
30 head_from="$arg";;
31 -t)
32 terse=1;;
33 --graphviz)
34 graphviz=1;;
35 --sort)
36 sort=1;;
37 --deps)
38 deps=1;;
39 --rdeps)
40 head=HEAD
41 rdeps=1;;
42 --all)
43 break;;
44 --exclude=*)
45 [ -n "${1#--exclude=}" ] || die "--exclude= requires a branch name"
46 exclude="$exclude ${1#--exclude=}";;
47 --exclude)
48 shift
49 [ -n "$1" -a "$1" != "--all" ] || die "--exclude requires a branch name"
50 exclude="$exclude $1";;
51 -*)
52 usage;;
54 break;;
55 esac
56 shift
57 done
58 [ -z "$exclude" ] || exclude="$exclude "
59 [ $# -le 1 ] || usage
60 [ $# -ne 1 -o "$1" != "--all" ] || { shift; head=; }
61 [ $# -ne 0 -o -z "$head" ] || set -- "$head"
63 if [ $# -eq 1 ]; then
64 branch="$(verify_topgit_branch "$1")"
67 [ "$terse$graphviz$sort$deps" = "" ] ||
68 [ "$terse$graphviz$sort$deps$rdeps" = "1" ] ||
69 die "mutually exclusive options given"
71 get_branch_list()
73 if [ -n "$branch" ]; then
74 echo "$branch"
75 else
76 non_annihilated_branches
80 curname="$(strip_ref "$(git symbolic-ref HEAD 2>/dev/null)")"
82 show_rdeps()
84 case "$exclude" in *" $_dep "*) return; esac
85 printf '%s %s\n' "$(echo "$_depchain" | sed -e 's/[^ ][^ ]*/ /g')" "$_dep"
88 if [ -n "$rdeps" ]; then
89 no_remotes=1
90 showbreak=
91 get_branch_list |
92 while read b; do
93 case "$exclude" in *" $branch "*) continue; esac
94 [ -z "$showbreak" ] || echo
95 showbreak=1
96 ref_exists "refs/heads/$b" || continue
97 echo "$b"
98 recurse_preorder=1
99 recurse_deps show_rdeps "$b"
100 done
101 exit 0
104 if [ -n "$graphviz" ]; then
105 cat <<EOT
106 # GraphViz output; pipe to:
107 # | dot -Tpng -o <output>
108 # or
109 # | dot -Txlib
111 digraph G {
113 graph [
114 rankdir = "TB"
115 label="TopGit Layout\n\n\n"
116 fontsize = 14
117 labelloc=top
118 pad = "0.5,0.5"
124 if [ -n "$sort" ]; then
125 tsort_input="$(get_temp tg-summary-sort)"
126 exec 4>$tsort_input
127 exec 5<$tsort_input
130 ## List branches
132 process_branch()
134 missing_deps=
136 current=' '
137 [ "$name" != "$curname" ] || current='>'
138 from=$head_from
139 [ "$name" = "$curname" ] ||
140 from=
141 nonempty=' '
142 ! branch_empty "$name" $from || nonempty='0'
143 remote=' '
144 [ -z "$base_remote" ] || remote='l'
145 ! has_remote "$name" || remote='r'
146 rem_update=' '
147 [ "$remote" != 'r' ] || ! ref_exists "refs/remotes/$base_remote/top-bases/$name" || {
148 branch_contains "refs/top-bases/$name" "refs/remotes/$base_remote/top-bases/$name" &&
149 branch_contains "$name" "refs/remotes/$base_remote/$name"
150 } || rem_update='R'
151 [ "$rem_update" = 'R' ] || branch_contains "refs/remotes/$base_remote/$name" "$name" 2>/dev/null ||
152 rem_update='L'
153 deps_update=' '
154 needs_update "$name" >/dev/null || deps_update='D'
155 deps_missing=' '
156 [ -z "$missing_deps" ] || deps_missing='!'
157 base_update=' '
158 branch_contains "$name" "refs/top-bases/$name" || base_update='B'
160 if [ "$(git rev-parse "$name")" != "$rev" ]; then
161 subject="$(cat_file "$name:.topmsg" $from | sed -n 's/^Subject: //p')"
162 else
163 # No commits yet
164 subject="(No commits)"
167 printf '%s\t%-31s\t%s\n' "$current$nonempty$remote$rem_update$deps_update$deps_missing$base_update" \
168 "$name" "$subject"
171 if [ -n "$deps" ]; then
172 case "$exclude" in *" ${branch:-..all..} "*) exit 0; esac
173 list_deps $head_from $branch |
174 while read name dep; do
175 case "$exclude" in *" $dep "*) continue; esac
176 echo "$name $dep"
177 done
178 exit 0
181 get_branch_list |
182 while read name; do
183 case "$exclude" in *" $name "*) continue; esac
184 if [ -n "$terse" ]; then
185 echo "$name"
186 elif [ -n "$graphviz$sort" ]; then
187 from=$head_from
188 [ "$name" = "$curname" ] ||
189 from=
190 cat_file "$name:.topdeps" $from | while read dep; do
191 dep_is_tgish=true
192 ref_exists "refs/top-bases/$dep" ||
193 dep_is_tgish=false
194 if ! "$dep_is_tgish" || ! branch_annihilated $dep; then
195 if [ -n "$graphviz" ]; then
196 echo "\"$name\" -> \"$dep\";"
197 if [ "$name" = "$curname" ] || [ "$dep" = "$curname" ]; then
198 echo "\"$curname\" [style=filled,fillcolor=yellow];"
200 else
201 echo "$name $dep" >&4
204 done
205 else
206 process_branch
208 done
210 if [ -n "$graphviz" ]; then
211 echo '}'
214 if [ -n "$sort" ]; then
215 tsort <&5
219 # vim:noet