Set version to 0.13.1
[topgit/pro.git] / tg-summary.sh
blob25951604de809aee9ac2d3302255149194925527
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: 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 git rev-parse --short --verify "refs/heads/$1" >/dev/null 2>&1 || die "no such branch"
50 git rev-parse --short --verify "refs/top-bases/$1" >/dev/null 2>&1 ||
51 die "not a TopGit-controlled branch"
52 branch="${1#refs/heads/}"
55 [ "$terse$graphviz$sort$deps" = "" ] ||
56 [ "$terse$graphviz$sort$deps$rdeps" = "1" ] ||
57 die "mutually exclusive options given"
59 get_branch_list()
61 if [ -n "$branch" ]; then
62 echo "$branch"
63 else
64 non_annihilated_branches
68 curname="$(strip_ref "$(git symbolic-ref HEAD 2>/dev/null)")"
70 show_rdeps()
72 printf '%s %s\n' "$(echo "$_depchain" | sed -e 's/[^ ][^ ]*/ /g')" "$_dep"
75 if [ -n "$rdeps" ]; then
76 no_remotes=1
77 showbreak=
78 get_branch_list |
79 while read b; do
80 [ -z "$showbreak" ] || echo
81 showbreak=1
82 ref_exists "refs/heads/$b" || continue
83 echo "$b"
84 recurse_deps show_rdeps "$b" |
85 awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--]}'
86 done
87 exit 0
90 if [ -n "$graphviz" ]; then
91 cat <<EOT
92 # GraphViz output; pipe to:
93 # | dot -Tpng -o <ouput>
94 # or
95 # | dot -Txlib
97 digraph G {
99 graph [
100 rankdir = "TB"
101 label="TopGit Layout\n\n\n"
102 fontsize = 14
103 labelloc=top
104 pad = "0.5,0.5"
110 if [ -n "$sort" ]; then
111 tsort_input="$(get_temp tg-summary-sort)"
112 exec 4>$tsort_input
113 exec 5<$tsort_input
116 ## List branches
118 process_branch()
120 missing_deps=
122 current=' '
123 [ "$name" != "$curname" ] || current='>'
124 from=$head_from
125 [ "$name" = "$curname" ] ||
126 from=
127 nonempty=' '
128 ! branch_empty "$name" $from || nonempty='0'
129 remote=' '
130 [ -z "$base_remote" ] || remote='l'
131 ! has_remote "$name" || remote='r'
132 rem_update=' '
133 [ "$remote" != 'r' ] || ! ref_exists "refs/remotes/$base_remote/top-bases/$name" || {
134 branch_contains "refs/top-bases/$name" "refs/remotes/$base_remote/top-bases/$name" &&
135 branch_contains "$name" "refs/remotes/$base_remote/$name"
136 } || rem_update='R'
137 [ "$rem_update" = 'R' ] || branch_contains "refs/remotes/$base_remote/$name" "$name" 2>/dev/null ||
138 rem_update='L'
139 deps_update=' '
140 needs_update "$name" >/dev/null || deps_update='D'
141 deps_missing=' '
142 [ -z "$missing_deps" ] || deps_missing='!'
143 base_update=' '
144 branch_contains "$name" "refs/top-bases/$name" || base_update='B'
146 if [ "$(git rev-parse "$name")" != "$rev" ]; then
147 subject="$(cat_file "$name:.topmsg" $from | sed -n 's/^Subject: //p')"
148 else
149 # No commits yet
150 subject="(No commits)"
153 printf '%s\t%-31s\t%s\n' "$current$nonempty$remote$rem_update$deps_update$deps_missing$base_update" \
154 "$name" "$subject"
157 if [ -n "$deps" ]; then
158 list_deps $head_from
159 exit 0
162 get_branch_list |
163 while read name; do
164 if [ -n "$terse" ]; then
165 echo "$name"
166 elif [ -n "$graphviz$sort" ]; then
167 from=$head_from
168 [ "$name" = "$curname" ] ||
169 from=
170 cat_file "$name:.topdeps" $from | while read dep; do
171 dep_is_tgish=true
172 ref_exists "refs/top-bases/$dep" ||
173 dep_is_tgish=false
174 if ! "$dep_is_tgish" || ! branch_annihilated $dep; then
175 if [ -n "$graphviz" ]; then
176 echo "\"$name\" -> \"$dep\";"
177 if [ "$name" = "$curname" ] || [ "$dep" = "$curname" ]; then
178 echo "\"$curname\" [style=filled,fillcolor=yellow];"
180 else
181 echo "$name $dep" >&4
184 done
185 else
186 process_branch
188 done
190 if [ -n "$graphviz" ]; then
191 echo '}'
194 if [ -n "$sort" ]; then
195 tsort <&5
199 # vim:noet