tg-migrate-bases.sh: migrate top-bases to new location
[topgit/pro.git] / tg-summary.sh
blobe50b1471c71eb24432e21b796c1460ee31e78a7a
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # Copyright (C) Petr Baudis <pasky@suse.cz> 2008
4 # Copyright (C) Kyle J. McKay <mackyle@gmail.com> 2015
5 # All rights reserved.
6 # GPLv2
8 terse=
9 graphviz=
10 sort=
11 deps=
12 depsonly=
13 rdeps=
14 head_from=
15 branches=
16 head=
17 heads=
18 exclude=
19 tgish=
20 withdeps=
22 ## Parse options
24 usage()
26 echo "Usage: ${tgname:-tg} [...] summary [-t | --list | --heads | --sort | --deps | --deps-only | --rdeps | --graphviz] [-i | -w] [--tgish-only] [--with[out]-deps] [--exclude branch]... [--all | branch...]" >&2
27 exit 1
30 while [ -n "$1" ]; do
31 arg="$1"
32 case "$arg" in
33 -i|-w)
34 [ -z "$head_from" ] || die "-i and -w are mutually exclusive"
35 head_from="$arg";;
36 -t|--list|-l)
37 terse=1;;
38 --heads)
39 heads=1;;
40 --with-deps)
41 head=HEAD
42 withdeps=1;;
43 --without-deps)
44 head=HEAD
45 withdeps=0;;
46 --graphviz)
47 graphviz=1;;
48 --sort)
49 sort=1;;
50 --deps)
51 deps=1;;
52 --tgish-only)
53 tgish=1;;
54 --deps-only)
55 head=HEAD
56 depsonly=1;;
57 --rdeps)
58 head=HEAD
59 rdeps=1;;
60 --all)
61 break;;
62 --exclude=*)
63 [ -n "${1#--exclude=}" ] || die "--exclude= requires a branch name"
64 exclude="$exclude ${1#--exclude=}";;
65 --exclude)
66 shift
67 [ -n "$1" -a "$1" != "--all" ] || die "--exclude requires a branch name"
68 exclude="$exclude $1";;
69 -*)
70 usage;;
72 break;;
73 esac
74 shift
75 done
76 [ $# -eq 0 ] || defwithdeps=1
77 [ -z "$exclude" ] || exclude="$exclude "
78 if [ "$1" = "--all" ]; then
79 [ -z "$withdeps" ] || die "mutually exclusive options given"
80 [ $# -eq 1 ] || usage
81 shift
82 head=
83 defwithdeps=
85 [ "$heads$rdeps" != "11" ] || head=
86 [ $# -ne 0 -o -z "$head" ] || set -- "$head"
88 [ "$terse$heads$graphviz$sort$deps$depsonly" = "" ] ||
89 [ "$terse$heads$graphviz$sort$deps$depsonly$rdeps" = "1" ] ||
90 [ "$terse$heads$graphviz$sort$deps$depsonly$rdeps" = "11" -a "$heads$rdeps" = "11" ] ||
91 die "mutually exclusive options given"
92 [ -z "$withdeps" -o -z "$rdeps$depsonly$heads" ] ||
93 die "mutually exclusive options given"
95 for b; do
96 [ "$b" != "--all" ] || usage
97 branches="$branches $(verify_topgit_branch "$b")"
98 done
100 get_branch_list()
102 if [ -n "$branches" ]; then
103 printf '%s\n' $branches
104 else
105 non_annihilated_branches
109 show_heads()
111 topics="$(get_temp topics)"
112 get_branch_list | sed -e 's,^\(.*\)$,refs/heads/\1 \1,' |
113 git cat-file --batch-check='%(objectname) %(rest)' |
114 sort -u -b -k1,1 >"$topics"
115 git merge-base --independent $(cut -d ' ' -f 1 <"$topics") |
116 sort -u -b -k1,1 | join - "$topics" | sort -u -b -k2,2 |
117 while read rev name; do
118 case "$exclude" in *" $name "*) continue; esac
119 printf '%s\n' "$name"
120 done
123 if [ -n "$heads" -a -z "$rdeps" ]; then
124 show_heads
125 exit 0
128 skip_ann=
129 show_dep() {
130 case "$exclude" in *" $_dep "*) return; esac
131 case " $seen_deps " in *" $_dep "*) return 0; esac
132 seen_deps="${seen_deps:+$seen_deps }$_dep"
133 [ -z "$tgish" -o -n "$_dep_is_tgish" ] || return 0
134 [ -z "$skip_ann" ] || ! branch_annihilated "$_dep" && printf '%s\n' "$_dep"
135 return 0
138 show_deps()
140 no_remotes=1
141 recurse_deps_exclude=
142 get_branch_list | while read _b; do
143 case "$exclude" in *" $_b "*) continue; esac
144 case " $recurse_deps_exclude " in *" $_b "*) continue; esac
145 seen_deps=
146 save_skip="$skip_ann"
147 _dep="$_b"; _dep_is_tgish=1; skip_ann=; show_dep; skip_ann="$save_skip"
148 recurse_deps show_dep "$_b"
149 recurse_deps_exclude="$recurse_deps_exclude $seen_deps"
150 done
153 if [ -n "$depsonly" ]; then
154 show_deps | LC_ALL=C sort -u -b -k1,1
155 exit 0
158 show_rdeps()
160 case "$exclude" in *" $_dep "*) return; esac
161 [ -z "$tgish" -o -n "$_dep_is_tgish" ] || return 0
162 printf '%s %s\n' "$_depchain" "$_dep"
165 if [ -n "$rdeps" ]; then
166 no_remotes=1
167 showbreak=
169 if [ -n "$heads" ]; then
170 show_heads
171 else
172 get_branch_list
174 } | while read b; do
175 case "$exclude" in *" $b "*) continue; esac
176 [ -z "$showbreak" ] || echo
177 showbreak=1
178 ref_exists "refs/heads/$b" || continue
180 echol "$b"
181 recurse_preorder=1
182 recurse_deps show_rdeps "$b"
183 } | sed -e 's/[^ ][^ ]*[ ]/ /g'
184 done
185 exit 0
188 [ -n "$withdeps" ] || withdeps="$defwithdeps"
189 [ "$withdeps" != "0" ] || withdeps=
190 if [ -n "$withdeps" ]; then
191 savetgish="$tgish"
192 tgish=1
193 branches="$(skip_ann=1; show_deps | LC_ALL=C sort -u -b -k1,1)"
194 tgish="$savetgish"
197 curname="$(strip_ref "$(git symbolic-ref -q HEAD)")" || :
199 if [ -n "$graphviz" ]; then
200 cat <<EOT
201 # GraphViz output; pipe to:
202 # | dot -Tpng -o <output>
203 # or
204 # | dot -Txlib
206 digraph G {
208 graph [
209 rankdir = "TB"
210 label="TopGit Layout\n\n\n"
211 fontsize = 14
212 labelloc=top
213 pad = "0.5,0.5"
219 if [ -n "$sort" ]; then
220 tsort_input="$(get_temp tg-summary-sort)"
221 exec 4>$tsort_input
222 exec 5<$tsort_input
225 ## List branches
227 process_branch()
229 missing_deps=
231 current=' '
232 [ "$name" != "$curname" ] || current='>'
233 from=$head_from
234 [ "$name" = "$curname" ] ||
235 from=
236 nonempty=' '
237 ! branch_empty "$name" $from || nonempty='0'
238 remote=' '
239 [ -z "$base_remote" ] || remote='l'
240 ! has_remote "$name" || remote='r'
241 rem_update=' '
242 [ "$remote" != 'r' ] || ! ref_exists "refs/remotes/$base_remote/${topbases#heads/}/$name" || {
243 branch_contains "refs/$topbases/$name" "refs/remotes/$base_remote/${topbases#heads/}/$name" &&
244 branch_contains "refs/heads/$name" "refs/remotes/$base_remote/$name"
245 } || rem_update='R'
246 [ "$remote" != 'r' -o "$rem_update" = 'R' ] || {
247 branch_contains "refs/remotes/$base_remote/$name" "refs/heads/$name" 2>/dev/null
248 } || rem_update='L'
249 deps_update=' '
250 needs_update "$name" >/dev/null || deps_update='D'
251 deps_missing=' '
252 [ -z "$missing_deps" ] || deps_missing='!'
253 base_update=' '
254 branch_contains "refs/heads/$name" "refs/$topbases/$name" || base_update='B'
256 if [ "$(ref_exists_rev "refs/heads/$name")" != "$(ref_exists_rev "refs/$topbases/$name")" ]; then
257 subject="$(cat_file "refs/heads/$name:.topmsg" $from | sed -n 's/^Subject: //p')"
258 else
259 # No commits yet
260 subject="(No commits)"
263 printf '%s\t%-31s\t%s\n' "$current$nonempty$remote$rem_update$deps_update$deps_missing$base_update" \
264 "$name" "$subject"
267 if [ -n "$deps" ]; then
268 if [ -n "$branches" ]; then
269 get_branch_list |
270 while read b; do
271 case "$exclude" in *" $b "*) continue; esac
272 list_deps $head_from $b |
273 while read name dep; do
274 case "$exclude" in *" $dep "*) continue; esac
275 [ -z "$tgish" ] || ref_exists "refs/$topbases/$dep" || continue
276 echo "$name $dep"
277 done
278 done
279 else
280 list_deps $head_from |
281 while read name dep; do
282 case "$exclude" in *" $dep "*) continue; esac
283 [ -z "$tgish" ] || ref_exists "refs/$topbases/$dep" || continue
284 echo "$name $dep"
285 done
287 exit 0
290 get_branch_list |
291 while read name; do
292 case "$exclude" in *" $name "*) continue; esac
293 if [ -n "$terse" ]; then
294 echol "$name"
295 elif [ -n "$graphviz$sort" ]; then
296 from=$head_from
297 [ "$name" = "$curname" ] ||
298 from=
299 cat_file "refs/heads/$name:.topdeps" $from | while read dep; do
300 dep_is_tgish=true
301 ref_exists "refs/$topbases/$dep" ||
302 dep_is_tgish=false
303 [ -z "$tgish" ] || [ "$dep_is_tgish" = "true" ] || continue
304 if ! "$dep_is_tgish" || ! branch_annihilated $dep; then
305 if [ -n "$graphviz" ]; then
306 echo "\"$name\" -> \"$dep\";"
307 if [ "$name" = "$curname" ] || [ "$dep" = "$curname" ]; then
308 echo "\"$curname\" [style=filled,fillcolor=yellow];"
310 else
311 echo "$name $dep" >&4
314 done
315 else
316 process_branch
318 done
320 if [ -n "$graphviz" ]; then
321 echo '}'
324 if [ -n "$sort" ]; then
325 tsort <&5
329 # vim:noet