tg.sh: speed up recurse_deps_internal
[topgit/pro.git] / tg-summary.sh
blobba8afe962fb4f9ec48355e401a9ebf0d6c961604
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=
15 ## Parse options
17 usage()
19 echo "Usage: ${tgname:-tg} [...] summary [-t | --sort | --deps | --rdeps | --graphviz] [-i | -w] [branch]" >&2
20 exit 1
23 while [ -n "$1" ]; do
24 arg="$1"
25 case "$arg" in
26 -i|-w)
27 [ -z "$head_from" ] || die "-i and -w are mutually exclusive"
28 head_from="$arg";;
29 -t)
30 terse=1;;
31 --graphviz)
32 graphviz=1;;
33 --sort)
34 sort=1;;
35 --deps)
36 deps=1;;
37 --rdeps)
38 rdeps=1;;
39 -*)
40 usage;;
42 break;;
43 esac
44 shift
45 done
46 [ $# -le 1 ] || usage
48 if [ $# -eq 1 ]; then
49 branch="$(verify_topgit_branch "$1")"
52 [ "$terse$graphviz$sort$deps" = "" ] ||
53 [ "$terse$graphviz$sort$deps$rdeps" = "1" ] ||
54 die "mutually exclusive options given"
56 get_branch_list()
58 if [ -n "$branch" ]; then
59 echo "$branch"
60 else
61 non_annihilated_branches
65 curname="$(strip_ref "$(git symbolic-ref HEAD 2>/dev/null)")"
67 show_rdeps()
69 printf '%s %s\n' "$(echo "$_depchain" | sed -e 's/[^ ][^ ]*/ /g')" "$_dep"
72 if [ -n "$rdeps" ]; then
73 no_remotes=1
74 showbreak=
75 get_branch_list |
76 while read b; do
77 [ -z "$showbreak" ] || echo
78 showbreak=1
79 ref_exists "refs/heads/$b" || continue
80 echo "$b"
81 recurse_preorder=1
82 recurse_deps show_rdeps "$b"
83 done
84 exit 0
87 if [ -n "$graphviz" ]; then
88 cat <<EOT
89 # GraphViz output; pipe to:
90 # | dot -Tpng -o <output>
91 # or
92 # | dot -Txlib
94 digraph G {
96 graph [
97 rankdir = "TB"
98 label="TopGit Layout\n\n\n"
99 fontsize = 14
100 labelloc=top
101 pad = "0.5,0.5"
107 if [ -n "$sort" ]; then
108 tsort_input="$(get_temp tg-summary-sort)"
109 exec 4>$tsort_input
110 exec 5<$tsort_input
113 ## List branches
115 process_branch()
117 missing_deps=
119 current=' '
120 [ "$name" != "$curname" ] || current='>'
121 from=$head_from
122 [ "$name" = "$curname" ] ||
123 from=
124 nonempty=' '
125 ! branch_empty "$name" $from || nonempty='0'
126 remote=' '
127 [ -z "$base_remote" ] || remote='l'
128 ! has_remote "$name" || remote='r'
129 rem_update=' '
130 [ "$remote" != 'r' ] || ! ref_exists "refs/remotes/$base_remote/top-bases/$name" || {
131 branch_contains "refs/top-bases/$name" "refs/remotes/$base_remote/top-bases/$name" &&
132 branch_contains "$name" "refs/remotes/$base_remote/$name"
133 } || rem_update='R'
134 [ "$rem_update" = 'R' ] || branch_contains "refs/remotes/$base_remote/$name" "$name" 2>/dev/null ||
135 rem_update='L'
136 deps_update=' '
137 needs_update "$name" >/dev/null || deps_update='D'
138 deps_missing=' '
139 [ -z "$missing_deps" ] || deps_missing='!'
140 base_update=' '
141 branch_contains "$name" "refs/top-bases/$name" || base_update='B'
143 if [ "$(git rev-parse "$name")" != "$rev" ]; then
144 subject="$(cat_file "$name:.topmsg" $from | sed -n 's/^Subject: //p')"
145 else
146 # No commits yet
147 subject="(No commits)"
150 printf '%s\t%-31s\t%s\n' "$current$nonempty$remote$rem_update$deps_update$deps_missing$base_update" \
151 "$name" "$subject"
154 if [ -n "$deps" ]; then
155 list_deps $head_from
156 exit 0
159 get_branch_list |
160 while read name; do
161 if [ -n "$terse" ]; then
162 echo "$name"
163 elif [ -n "$graphviz$sort" ]; then
164 from=$head_from
165 [ "$name" = "$curname" ] ||
166 from=
167 cat_file "$name:.topdeps" $from | while read dep; do
168 dep_is_tgish=true
169 ref_exists "refs/top-bases/$dep" ||
170 dep_is_tgish=false
171 if ! "$dep_is_tgish" || ! branch_annihilated $dep; then
172 if [ -n "$graphviz" ]; then
173 echo "\"$name\" -> \"$dep\";"
174 if [ "$name" = "$curname" ] || [ "$dep" = "$curname" ]; then
175 echo "\"$curname\" [style=filled,fillcolor=yellow];"
177 else
178 echo "$name $dep" >&4
181 done
182 else
183 process_branch
185 done
187 if [ -n "$graphviz" ]; then
188 echo '}'
191 if [ -n "$sort" ]; then
192 tsort <&5
196 # vim:noet