tg-summary.sh: speed up --rdeps a bit
[topgit/pro.git] / tg-summary.sh
blobebee20a28e3bab98de40fbdce15e324a19dfe785
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' "$_depchain" "$_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
98 echo "$b"
99 recurse_preorder=1
100 recurse_deps show_rdeps "$b"
101 } | sed -e 's/[^ ][^ ]*[ ]/ /g'
102 done
103 exit 0
106 if [ -n "$graphviz" ]; then
107 cat <<EOT
108 # GraphViz output; pipe to:
109 # | dot -Tpng -o <output>
110 # or
111 # | dot -Txlib
113 digraph G {
115 graph [
116 rankdir = "TB"
117 label="TopGit Layout\n\n\n"
118 fontsize = 14
119 labelloc=top
120 pad = "0.5,0.5"
126 if [ -n "$sort" ]; then
127 tsort_input="$(get_temp tg-summary-sort)"
128 exec 4>$tsort_input
129 exec 5<$tsort_input
132 ## List branches
134 process_branch()
136 missing_deps=
138 current=' '
139 [ "$name" != "$curname" ] || current='>'
140 from=$head_from
141 [ "$name" = "$curname" ] ||
142 from=
143 nonempty=' '
144 ! branch_empty "$name" $from || nonempty='0'
145 remote=' '
146 [ -z "$base_remote" ] || remote='l'
147 ! has_remote "$name" || remote='r'
148 rem_update=' '
149 [ "$remote" != 'r' ] || ! ref_exists "refs/remotes/$base_remote/top-bases/$name" || {
150 branch_contains "refs/top-bases/$name" "refs/remotes/$base_remote/top-bases/$name" &&
151 branch_contains "refs/heads/$name" "refs/remotes/$base_remote/$name"
152 } || rem_update='R'
153 [ "$rem_update" = 'R' ] || branch_contains "refs/remotes/$base_remote/$name" "refs/heads/$name" 2>/dev/null ||
154 rem_update='L'
155 deps_update=' '
156 needs_update "$name" >/dev/null || deps_update='D'
157 deps_missing=' '
158 [ -z "$missing_deps" ] || deps_missing='!'
159 base_update=' '
160 branch_contains "refs/heads/$name" "refs/top-bases/$name" || base_update='B'
162 if [ "$(git rev-parse "refs/heads/$name")" != "$rev" ]; then
163 subject="$(cat_file "refs/heads/$name:.topmsg" $from | sed -n 's/^Subject: //p')"
164 else
165 # No commits yet
166 subject="(No commits)"
169 printf '%s\t%-31s\t%s\n' "$current$nonempty$remote$rem_update$deps_update$deps_missing$base_update" \
170 "$name" "$subject"
173 if [ -n "$deps" ]; then
174 case "$exclude" in *" ${branch:-..all..} "*) exit 0; esac
175 list_deps $head_from $branch |
176 while read name dep; do
177 case "$exclude" in *" $dep "*) continue; esac
178 echo "$name $dep"
179 done
180 exit 0
183 get_branch_list |
184 while read name; do
185 case "$exclude" in *" $name "*) continue; esac
186 if [ -n "$terse" ]; then
187 echo "$name"
188 elif [ -n "$graphviz$sort" ]; then
189 from=$head_from
190 [ "$name" = "$curname" ] ||
191 from=
192 cat_file "refs/heads/$name:.topdeps" $from | while read dep; do
193 dep_is_tgish=true
194 ref_exists "refs/top-bases/$dep" ||
195 dep_is_tgish=false
196 if ! "$dep_is_tgish" || ! branch_annihilated $dep; then
197 if [ -n "$graphviz" ]; then
198 echo "\"$name\" -> \"$dep\";"
199 if [ "$name" = "$curname" ] || [ "$dep" = "$curname" ]; then
200 echo "\"$curname\" [style=filled,fillcolor=yellow];"
202 else
203 echo "$name $dep" >&4
206 done
207 else
208 process_branch
210 done
212 if [ -n "$graphviz" ]; then
213 echo '}'
216 if [ -n "$sort" ]; then
217 tsort <&5
221 # vim:noet