tg-summary: show annihilated with -v -v -l
[topgit/pro.git] / tg-summary.sh
blob277f2e9df8813f70642e77bc51806c813e59b747
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,2016,2017
5 # All rights reserved.
6 # GPLv2
8 terse=
9 graphviz=
10 sort=
11 deps=
12 depsonly=
13 rdeps=
14 rdepsonce=1
15 head_from=
16 branches=
17 head=
18 heads=
19 headsindep=
20 headsonly=
21 exclude=
22 tgish=
23 withdeps=
24 verbose=0
26 ## Parse options
28 usage()
30 echo "Usage: ${tgname:-tg} [...] summary [-t | --list | --heads[-only] | --sort | --deps[-only] | --rdeps | --graphviz] [-i | -w] [--tgish-only] [--with[out]-deps] [--exclude branch]... [--all | branch...]" >&2
31 exit 1
34 while [ -n "$1" ]; do
35 arg="$1"
36 case "$arg" in
37 -i|-w)
38 [ -z "$head_from" ] || die "-i and -w are mutually exclusive"
39 head_from="$arg";;
40 -t|--list|-l|--terse)
41 terse=1;;
42 -v|--verbose)
43 verbose=$(( $verbose + 1 ));;
44 --heads|--topgit-heads)
45 heads=1
46 headsindep=;;
47 --heads-independent)
48 heads=1
49 headsindep=1;;
50 --heads-only)
51 headsonly=1;;
52 --with-deps)
53 head=HEAD
54 withdeps=1;;
55 --without-deps|--no-with-deps)
56 head=HEAD
57 withdeps=0;;
58 --graphviz)
59 graphviz=1;;
60 --sort)
61 sort=1;;
62 --deps)
63 deps=1;;
64 --tgish-only)
65 tgish=1;;
66 --deps-only)
67 head=HEAD
68 depsonly=1;;
69 --rdeps)
70 head=HEAD
71 rdeps=1;;
72 --rdeps-full)
73 head=HEAD
74 rdeps=1 rdepsonce=;;
75 --rdeps-once)
76 head=HEAD
77 rdeps=1 rdepsonce=1;;
78 --all)
79 break;;
80 --exclude=*)
81 [ -n "${1#--exclude=}" ] || die "--exclude= requires a branch name"
82 exclude="$exclude ${1#--exclude=}";;
83 --exclude)
84 shift
85 [ -n "$1" -a "$1" != "--all" ] || die "--exclude requires a branch name"
86 exclude="$exclude $1";;
87 -*)
88 usage;;
90 break;;
91 esac
92 shift
93 done
94 [ $# -eq 0 ] || defwithdeps=1
95 [ -z "$exclude" ] || exclude="$exclude "
96 doingall=
97 [ $# -ne 0 ] || [ z"$head" != z"" ] || doingall=1
98 if [ "$1" = "--all" ]; then
99 [ -z "$withdeps" ] || die "mutually exclusive options given"
100 [ $# -eq 1 ] || usage
101 shift
102 head=
103 defwithdeps=
104 doingall=1
106 [ "$heads$rdeps" != "11" ] || head=
107 [ $# -ne 0 -o -z "$head" ] || set -- "$head"
109 [ "$terse$heads$headsonly$graphviz$sort$deps$depsonly" = "" ] ||
110 [ "$terse$heads$headsonly$graphviz$sort$deps$depsonly$rdeps" = "1" ] ||
111 [ "$terse$heads$headsonly$graphviz$sort$deps$depsonly$rdeps" = "11" -a "$heads$rdeps" = "11" ] ||
112 die "mutually exclusive options given"
113 [ -z "$withdeps" -o -z "$rdeps$depsonly$heads$headsonly" ] ||
114 die "mutually exclusive options given"
116 for b; do
117 [ "$b" != "--all" ] || usage
118 branches="$branches $(verify_topgit_branch "$b")"
119 done
121 get_branch_list()
123 if [ -n "$branches" ]; then
124 if [ -n "$1" ]; then
125 printf '%s\n' $branches | sort -u
126 else
127 printf '%s\n' $branches
129 else
130 non_annihilated_branches
134 show_heads_independent()
136 topics="$(get_temp topics)"
137 get_branch_list | sed -e 's,^\(.*\)$,refs/heads/\1 \1,' |
138 git cat-file --batch-check='%(objectname) %(rest)' |
139 sort -u -b -k1,1 >"$topics"
140 git merge-base --independent $(cut -d ' ' -f 1 <"$topics") |
141 sort -u -b -k1,1 | join - "$topics" | sort -u -b -k2,2 |
142 while read rev name; do
143 case "$exclude" in *" $name "*) continue; esac
144 printf '%s\n' "$name"
145 done
148 show_heads_topgit()
150 if [ -n "$branches" ]; then
151 navigate_deps -s=-1 -1 -- "$branches" | sort
152 else
153 navigate_deps -s=-1
154 fi |
155 while read -r name; do
156 case "$exclude" in *" $name "*) continue; esac
157 printf '%s\n' "$name"
158 done
161 show_heads()
163 if [ -n "$headsindep" ]; then
164 show_heads_independent "$@"
165 else
166 show_heads_topgit "$@"
170 if [ -n "$heads" -a -z "$rdeps" ]; then
171 show_heads
172 exit 0
175 skip_ann=
176 show_dep() {
177 case "$exclude" in *" $_dep "*) return; esac
178 case " $seen_deps " in *" $_dep "*) return 0; esac
179 seen_deps="${seen_deps:+$seen_deps }$_dep"
180 [ -z "$tgish" -o -n "$_dep_is_tgish" ] || return 0
181 [ -z "$skip_ann" ] || [ -z "$_dep_annihilated" ] && printf '%s\n' "$_dep"
182 return 0
185 show_deps()
187 no_remotes=1
188 recurse_deps_exclude=
189 get_branch_list | while read _b; do
190 case "$exclude" in *" $_b "*) continue; esac
191 case " $recurse_deps_exclude " in *" $_b "*) continue; esac
192 seen_deps=
193 save_skip="$skip_ann"
194 _dep="$_b"; _dep_is_tgish=1; skip_ann=; show_dep; skip_ann="$save_skip"
195 recurse_deps show_dep "$_b"
196 recurse_deps_exclude="$recurse_deps_exclude $seen_deps"
197 done
200 if [ -n "$depsonly" ]; then
201 show_deps | sort -u -b -k1,1
202 exit 0
205 show_rdeps()
207 case "$exclude" in *" $_dep "*) return; esac
208 [ -z "$tgish" -o -n "$_dep_is_tgish" ] || return 0
209 elided=
210 [ -z "$rdepsonce" ] || [ "$_dep_xvisits" = 0 ] || elided="^"
211 printf '%s %s\n' "$_depchain" "$_dep$elided"
214 if [ -n "$rdeps" ]; then
215 no_remotes=1
216 showbreak=
218 if [ -n "$heads" ]; then
219 show_heads
220 else
221 get_branch_list
223 } | while read b; do
224 case "$exclude" in *" $b "*) continue; esac
225 [ -z "$showbreak" ] || echo
226 showbreak=1
227 ref_exists "refs/heads/$b" || continue
229 echol "$b"
230 recurse_preorder=1
231 recurse_deps ${rdepsonce:+-o=-o=-1} show_rdeps "$b"
232 } | sed -e 's/[^ ][^ ]*[ ]/ /g'
233 done
234 exit 0
237 if [ -n "$deps" ]; then
238 if [ -n "$branches" ]; then
239 no_remotes=1
240 recurse_deps_exclude="$exclude"
241 recurse_deps_internal -n -t -m -e=2 -- $branches | sort -u
242 else
243 refslist=
244 [ -z "$tg_read_only" ] || [ -z "$tg_ref_cache" ] || ! [ -s "$tg_ref_cache" ] ||
245 refslist="-r=\"$tg_ref_cache\""
246 tdopt=
247 v_get_tdopt tdopt "$head_from"
248 eval run_awk_topgit_deps "$refslist" "$tdopt" '-n -t -x="$exclude" "refs/$topbases"'
250 exit 0
253 if [ -n "$headsonly" ]; then
254 defwithdeps=
255 branches="$(show_heads)"
258 [ -n "$withdeps" ] || withdeps="$defwithdeps"
259 if [ -z "$doingall$terse$graphviz$sort$withdeps$branches" ]; then
260 branches="$(tg info --heads 2>/dev/null | paste -d " " -s -)" || :
261 [ -z "$branches" ] || withdeps=1
263 [ "$withdeps" != "0" ] || withdeps=
264 if [ -n "$withdeps" ]; then
265 savetgish="$tgish"
266 tgish=1
267 origbranches="$branches"
268 branches="$(skip_ann=1; show_deps | sort -u -b -k1,1 | paste -d " " -s -)"
269 tgish="$savetgish"
272 curname="$(strip_ref "$(git symbolic-ref -q HEAD)")" || :
274 if [ -n "$graphviz" ]; then
275 cat <<EOT
276 # GraphViz output; pipe to:
277 # | dot -Tpng -o <output>
278 # or
279 # | dot -Txlib
281 digraph G {
283 graph [
284 rankdir = "TB"
285 label="TopGit Layout\n\n\n"
286 fontsize = 14
287 labelloc=top
288 pad = "0.5,0.5"
294 if [ -n "$sort" ]; then
295 tsort_input="$(get_temp tg-summary-sort)"
296 exec 4>$tsort_input
297 exec 5<$tsort_input
300 ## List branches
302 aheadlist=
303 processed=' '
304 needslist=' '
305 compute_ahead_list()
307 [ -z "$branches" ] || [ -n "$withdeps" ] || return 0
308 [ -n "$withdeps" ] || origbranches="$(tg summary --topgit-heads | paste -d ' ' -s -)"
309 aheadfile="$(get_temp aheadlist)"
310 savebr="$base_remote"
311 savenr="$no_remotes"
312 base_remote=
313 no_remotes=1
314 for onehead in $origbranches; do
315 case "$exclude" in *" $onehead "*) continue; esac
316 case "$processed" in *" $onehead "*) continue; esac
317 processed="${processed}$onehead "
318 needs_update "$onehead" || needslist="${needslist}$onehead "
319 done >"$aheadfile"
320 no_remotes="$savenr"
321 base_remote="$savebr"
322 aheadlist=" $(cut -d ' ' -f 1 <"$aheadfile" | sort -u | paste -d ' ' -s -) "
325 process_branch()
327 missing_deps=
329 current=' '
330 [ "$name" != "$curname" ] || current='>'
331 from=$head_from
332 [ "$name" = "$curname" ] ||
333 from=
334 nonempty=' '
335 ! branch_empty "$name" $from || nonempty='0'
336 remote=' '
337 [ -z "$base_remote" ] || remote='l'
338 ! has_remote "$name" || remote='r'
339 rem_update=' '
340 [ "$remote" != 'r' ] || ! ref_exists "refs/remotes/$base_remote/${topbases#heads/}/$name" || {
341 branch_contains "refs/$topbases/$name" "refs/remotes/$base_remote/${topbases#heads/}/$name" &&
342 branch_contains "refs/heads/$name" "refs/remotes/$base_remote/$name"
343 } || rem_update='R'
344 [ "$remote" != 'r' -o "$rem_update" = 'R' ] || {
345 branch_contains "refs/remotes/$base_remote/$name" "refs/heads/$name" 2>/dev/null
346 } || rem_update='L'
347 deps_update=' '
348 case "$processed" in
349 *" $name "*)
350 case "$needslist" in *" $name "*) deps_update='D'; esac;;
352 needs_update "$name" >/dev/null || deps_update='D';;
353 esac
354 deps_missing=' '
355 [ -z "$missing_deps" ] || deps_missing='!'
356 base_update=' '
357 branch_contains "refs/heads/$name" "refs/$topbases/$name" || base_update='B'
358 ahead=' '
359 case "$aheadlist" in *" $name "*) ahead='*'; esac
361 if [ "$(ref_exists_rev "refs/heads/$name")" != "$(ref_exists_rev "refs/$topbases/$name")" ]; then
362 subject="$(cat_file "refs/heads/$name:.topmsg" $from | sed -n 's/^Subject: //p')"
363 else
364 # No commits yet
365 subject="(No commits)"
368 printf '%-8s %-30s\t%s\n' "$current$nonempty$remote$rem_update$deps_update$deps_missing$base_update$ahead" \
369 "$name" "$subject"
372 if [ -n "$terse" ]; then
373 refslist=
374 [ -z "$tg_read_only" ] || [ -z "$tg_ref_cache" ] || ! [ -s "$tg_ref_cache" ] ||
375 refslist="-r=\"$tg_ref_cache\""
376 cmd="run_awk_topgit_msg --list"
377 [ $verbose -lt 2 ] || cmd="run_awk_topgit_msg -c -nokind"
378 [ $verbose -gt 0 ] || cmd="run_awk_topgit_branches -n"
379 eval "$cmd" "$refslist" '-i="$branches" -x="$exclude" "refs/$topbases"'
380 exit 0
383 [ -n "$graphviz$sort" ] || compute_ahead_list
384 get_branch_list |
385 while read name; do
386 case "$exclude" in *" $name "*) continue; esac
387 if [ -n "$graphviz$sort" ]; then
388 from=$head_from
389 [ "$name" = "$curname" ] ||
390 from=
391 cat_file "refs/heads/$name:.topdeps" $from | while read -r dep || [ -n "$dep" ]; do
392 dep_is_tgish=true
393 ref_exists "refs/$topbases/$dep" ||
394 dep_is_tgish=false
395 [ -z "$tgish" ] || [ "$dep_is_tgish" = "true" ] || continue
396 if ! "$dep_is_tgish" || ! branch_annihilated $dep; then
397 if [ -n "$graphviz" ]; then
398 echo "\"$name\" -> \"$dep\";"
399 if [ "$name" = "$curname" ] || [ "$dep" = "$curname" ]; then
400 echo "\"$curname\" [style=filled,fillcolor=yellow];"
402 else
403 echo "$name $dep" >&4
406 done
407 else
408 process_branch
410 done
412 if [ -n "$graphviz" ]; then
413 echo '}'
416 if [ -n "$sort" ]; then
417 tsort <&5