tg-revert.sh: convert any top-bases in TOPGIT REFS
[topgit/pro.git] / tg-summary.sh
bloba1dc1d0289cfe3ad1081b3e82b671b968fe2e1fd
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-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 --graphviz)
44 graphviz=1;;
45 --sort)
46 sort=1;;
47 --deps)
48 deps=1;;
49 --tgish-only)
50 tgish=1;;
51 --deps-only)
52 head=HEAD
53 depsonly=1;;
54 --rdeps)
55 head=HEAD
56 rdeps=1;;
57 --all)
58 break;;
59 --exclude=*)
60 [ -n "${1#--exclude=}" ] || die "--exclude= requires a branch name"
61 exclude="$exclude ${1#--exclude=}";;
62 --exclude)
63 shift
64 [ -n "$1" -a "$1" != "--all" ] || die "--exclude requires a branch name"
65 exclude="$exclude $1";;
66 -*)
67 usage;;
69 break;;
70 esac
71 shift
72 done
73 [ -z "$exclude" ] || exclude="$exclude "
74 if [ "$1" = "--all" ]; then
75 [ -z "$withdeps" ] || die "mutually exclusive options given"
76 [ $# -eq 1 ] || usage
77 shift
78 head=
80 [ "$heads$rdeps" != "11" ] || head=
81 [ $# -ne 0 -o -z "$head" ] || set -- "$head"
83 [ "$terse$heads$graphviz$sort$deps$depsonly" = "" ] ||
84 [ "$terse$heads$graphviz$sort$deps$depsonly$rdeps" = "1" ] ||
85 [ "$terse$heads$graphviz$sort$deps$depsonly$rdeps" = "11" -a "$heads$rdeps" = "11" ] ||
86 die "mutually exclusive options given"
87 [ -z "$withdeps" -o -z "$rdeps$depsonly$heads" ] ||
88 die "mutually exclusive options given"
90 for b; do
91 [ "$b" != "--all" ] || usage
92 branches="$branches $(verify_topgit_branch "$b")"
93 done
95 get_branch_list()
97 if [ -n "$branches" ]; then
98 printf '%s\n' $branches
99 else
100 non_annihilated_branches
104 show_heads()
106 topics="$(get_temp topics)"
107 get_branch_list | sed -e 's,^\(.*\)$,refs/heads/\1 \1,' |
108 git cat-file --batch-check='%(objectname) %(rest)' |
109 sort -u -b -k1,1 >"$topics"
110 git merge-base --independent $(cut -d ' ' -f 1 <"$topics") |
111 sort -u -b -k1,1 | join - "$topics" | sort -u -b -k2,2 |
112 while read rev name; do
113 case "$exclude" in *" $name "*) continue; esac
114 printf '%s\n' "$name"
115 done
118 if [ -n "$heads" -a -z "$rdeps" ]; then
119 show_heads
120 exit 0
123 show_dep() {
124 case "$exclude" in *" $_dep "*) return; esac
125 case " $seen_deps " in *" $_dep "*) return 0; esac
126 seen_deps="${seen_deps:+$seen_deps }$_dep"
127 [ -z "$tgish" -o -n "$_dep_is_tgish" ] || return 0
128 printf '%s\n' "$_dep"
131 show_deps()
133 no_remotes=1
134 recurse_deps_exclude=
135 get_branch_list | while read _b; do
136 case "$exclude" in *" $_b "*) continue; esac
137 case " $recurse_deps_exclude " in *" $_b "*) continue; esac
138 seen_deps=
139 _dep="$_b"; _dep_is_tgish=1; show_dep
140 recurse_deps show_dep "$_b"
141 recurse_deps_exclude="$recurse_deps_exclude $seen_deps"
142 done
145 if [ -n "$depsonly" ]; then
146 show_deps | LC_ALL=C sort -u -b -k1,1
147 exit 0
150 show_rdeps()
152 case "$exclude" in *" $_dep "*) return; esac
153 [ -z "$tgish" -o -n "$_dep_is_tgish" ] || return 0
154 printf '%s %s\n' "$_depchain" "$_dep"
157 if [ -n "$rdeps" ]; then
158 no_remotes=1
159 showbreak=
161 if [ -n "$heads" ]; then
162 show_heads
163 else
164 get_branch_list
166 } | while read b; do
167 case "$exclude" in *" $b "*) continue; esac
168 [ -z "$showbreak" ] || echo
169 showbreak=1
170 ref_exists "refs/heads/$b" || continue
172 echol "$b"
173 recurse_preorder=1
174 recurse_deps show_rdeps "$b"
175 } | sed -e 's/[^ ][^ ]*[ ]/ /g'
176 done
177 exit 0
180 if [ -n "$withdeps" ]; then
181 savetgish="$tgish"
182 tgish=1
183 branches="$(show_deps | LC_ALL=C sort -u -b -k1,1)"
184 tgish="$savetgish"
187 curname="$(strip_ref "$(git symbolic-ref -q HEAD || :)")"
189 if [ -n "$graphviz" ]; then
190 cat <<EOT
191 # GraphViz output; pipe to:
192 # | dot -Tpng -o <output>
193 # or
194 # | dot -Txlib
196 digraph G {
198 graph [
199 rankdir = "TB"
200 label="TopGit Layout\n\n\n"
201 fontsize = 14
202 labelloc=top
203 pad = "0.5,0.5"
209 if [ -n "$sort" ]; then
210 tsort_input="$(get_temp tg-summary-sort)"
211 exec 4>$tsort_input
212 exec 5<$tsort_input
215 ## List branches
217 process_branch()
219 missing_deps=
221 current=' '
222 [ "$name" != "$curname" ] || current='>'
223 from=$head_from
224 [ "$name" = "$curname" ] ||
225 from=
226 nonempty=' '
227 ! branch_empty "$name" $from || nonempty='0'
228 remote=' '
229 [ -z "$base_remote" ] || remote='l'
230 ! has_remote "$name" || remote='r'
231 rem_update=' '
232 [ "$remote" != 'r' ] || ! ref_exists "refs/remotes/$base_remote/$topbases/$name" || {
233 branch_contains "refs/$topbases/$name" "refs/remotes/$base_remote/$topbases/$name" &&
234 branch_contains "refs/heads/$name" "refs/remotes/$base_remote/$name"
235 } || rem_update='R'
236 [ "$remote" != 'r' -o "$rem_update" = 'R' ] || {
237 branch_contains "refs/remotes/$base_remote/$name" "refs/heads/$name" 2>/dev/null
238 } || rem_update='L'
239 deps_update=' '
240 needs_update "$name" >/dev/null || deps_update='D'
241 deps_missing=' '
242 [ -z "$missing_deps" ] || deps_missing='!'
243 base_update=' '
244 branch_contains "refs/heads/$name" "refs/$topbases/$name" || base_update='B'
246 if [ "$(ref_exists_rev "refs/heads/$name")" != "$(ref_exists_rev "refs/$topbases/$name")" ]; then
247 subject="$(cat_file "refs/heads/$name:.topmsg" $from | sed -n 's/^Subject: //p')"
248 else
249 # No commits yet
250 subject="(No commits)"
253 printf '%s\t%-31s\t%s\n' "$current$nonempty$remote$rem_update$deps_update$deps_missing$base_update" \
254 "$name" "$subject"
257 if [ -n "$deps" ]; then
258 if [ -n "$branches" ]; then
259 get_branch_list |
260 while read b; do
261 case "$exclude" in *" $b "*) continue; esac
262 list_deps $head_from $b |
263 while read name dep; do
264 case "$exclude" in *" $dep "*) continue; esac
265 [ -z "$tgish" ] || ref_exists "refs/$topbases/$dep" || continue
266 echo "$name $dep"
267 done
268 done
269 else
270 list_deps $head_from |
271 while read name dep; do
272 case "$exclude" in *" $dep "*) continue; esac
273 [ -z "$tgish" ] || ref_exists "refs/$topbases/$dep" || continue
274 echo "$name $dep"
275 done
277 exit 0
280 get_branch_list |
281 while read name; do
282 case "$exclude" in *" $name "*) continue; esac
283 if [ -n "$terse" ]; then
284 echol "$name"
285 elif [ -n "$graphviz$sort" ]; then
286 from=$head_from
287 [ "$name" = "$curname" ] ||
288 from=
289 cat_file "refs/heads/$name:.topdeps" $from | while read dep; do
290 dep_is_tgish=true
291 ref_exists "refs/$topbases/$dep" ||
292 dep_is_tgish=false
293 [ -z "$tgish" ] || [ "$dep_is_tgish" = "true" ] || continue
294 if ! "$dep_is_tgish" || ! branch_annihilated $dep; then
295 if [ -n "$graphviz" ]; then
296 echo "\"$name\" -> \"$dep\";"
297 if [ "$name" = "$curname" ] || [ "$dep" = "$curname" ]; then
298 echo "\"$curname\" [style=filled,fillcolor=yellow];"
300 else
301 echo "$name $dep" >&4
304 done
305 else
306 process_branch
308 done
310 if [ -n "$graphviz" ]; then
311 echo '}'
314 if [ -n "$sort" ]; then
315 tsort <&5
319 # vim:noet