tg-export --collapse | --linearize to existing branch proceeds with --force
[topgit/pro.git] / tg-summary.sh
blobc149dddf8027a8297d4beb3be0f7ad0044e125e9
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # (c) Petr Baudis <pasky@suse.cz> 2008
4 # GPLv2
6 terse=
7 graphviz=
8 sort=
9 deps=
10 head_from=
12 ## Parse options
14 while [ -n "$1" ]; do
15 arg="$1"; shift
16 case "$arg" in
17 -i|-w)
18 [ -z "$head_from" ] || die "-i and -w are mutually exclusive"
19 head_from="$arg";;
20 -t)
21 terse=1;;
22 --graphviz)
23 graphviz=1;;
24 --sort)
25 sort=1;;
26 --deps)
27 deps=1;;
29 echo "Usage: tg [...] summary [-t | --sort | --deps | --graphviz] [-i | -w]" >&2
30 exit 1;;
31 esac
32 done
34 curname="$(strip_ref "$(git symbolic-ref HEAD 2>/dev/null)")"
36 [ "$terse$graphviz$sort$deps" = "" ] ||
37 [ "$terse$graphviz$sort$deps" = "1" ] ||
38 die "mutually exclusive options given"
40 if [ -n "$graphviz" ]; then
41 cat <<EOT
42 # GraphViz output; pipe to:
43 # | dot -Tpng -o <ouput>
44 # or
45 # | dot -Txlib
47 digraph G {
49 graph [
50 rankdir = "TB"
51 label="TopGit Layout\n\n\n"
52 fontsize = 14
53 labelloc=top
54 pad = "0.5,0.5"
57 EOT
60 if [ -n "$sort" ]; then
61 tsort_input="$(get_temp tg-summary-sort)"
62 exec 4>$tsort_input
63 exec 5<$tsort_input
66 ## List branches
68 process_branch()
70 missing_deps=
72 current=' '
73 [ "$name" != "$curname" ] || current='>'
74 from=$head_from
75 [ "$name" = "$curname" ] ||
76 from=
77 nonempty=' '
78 ! branch_empty "$name" $from || nonempty='0'
79 remote=' '
80 [ -z "$base_remote" ] || remote='l'
81 ! has_remote "$name" || remote='r'
82 rem_update=' '
83 [ "$remote" != 'r' ] || ! ref_exists "refs/remotes/$base_remote/top-bases/$name" || {
84 branch_contains "refs/top-bases/$name" "refs/remotes/$base_remote/top-bases/$name" &&
85 branch_contains "$name" "refs/remotes/$base_remote/$name"
86 } || rem_update='R'
87 [ "$rem_update" = 'R' ] || branch_contains "refs/remotes/$base_remote/$name" "$name" 2>/dev/null ||
88 rem_update='L'
89 deps_update=' '
90 needs_update "$name" >/dev/null || deps_update='D'
91 deps_missing=' '
92 [ -z "$missing_deps" ] || deps_missing='!'
93 base_update=' '
94 branch_contains "$name" "refs/top-bases/$name" || base_update='B'
96 if [ "$(git rev-parse "$name")" != "$rev" ]; then
97 subject="$(cat_file "$name:.topmsg" $from | sed -n 's/^Subject: //p')"
98 else
99 # No commits yet
100 subject="(No commits)"
103 printf '%s\t%-31s\t%s\n' "$current$nonempty$remote$rem_update$deps_update$deps_missing$base_update" \
104 "$name" "$subject"
107 if [ -n "$deps" ]; then
108 list_deps $head_from
109 exit 0
112 non_annihilated_branches |
113 while read name; do
114 if [ -n "$terse" ]; then
115 echo "$name"
116 elif [ -n "$graphviz$sort" ]; then
117 from=$head_from
118 [ "$name" = "$curname" ] ||
119 from=
120 cat_file "$name:.topdeps" $from | while read dep; do
121 dep_is_tgish=true
122 ref_exists "refs/top-bases/$dep" ||
123 dep_is_tgish=false
124 if ! "$dep_is_tgish" || ! branch_annihilated $dep; then
125 if [ -n "$graphviz" ]; then
126 echo "\"$name\" -> \"$dep\";"
127 if [ "$name" = "$curname" ] || [ "$dep" = "$curname" ]; then
128 echo "\"$curname\" [style=filled,fillcolor=yellow];"
130 else
131 echo "$name $dep" >&4
134 done
135 else
136 process_branch
138 done
140 if [ -n "$graphviz" ]; then
141 echo '}'
144 if [ -n "$sort" ]; then
145 tsort <&5
149 # vim:noet