Ignore Emacs auto-save files
[topgit/greenrd.git] / tg-summary.sh
bloba92480ff38f0f13444909c5d3895ae2543b7765e
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=
12 ## Parse options
14 while [ -n "$1" ]; do
15 arg="$1"; shift
16 case "$arg" in
17 -t)
18 terse=1;;
19 --graphviz)
20 graphviz=1;;
21 --sort)
22 sort=1;;
23 --deps)
24 deps=1;;
26 echo "Usage: tg [...] summary [-t | --sort | --deps | --graphviz]" >&2
27 exit 1;;
28 esac
29 done
31 curname="$(git symbolic-ref HEAD | sed 's#^refs/\(heads\|top-bases\)/##')"
33 [ "$terse$graphviz$sort$deps" = "" ] ||
34 [ "$terse$graphviz$sort$deps" = "1" ] ||
35 die "mutually exclusive options given"
37 if [ -n "$graphviz" ]; then
38 cat <<EOT
39 # GraphViz output; pipe to:
40 # | dot -Tpng -o <ouput>
41 # or
42 # | dot -Txlib
44 digraph G {
46 graph [
47 rankdir = "TB"
48 label="TopGit Layout\n\n\n"
49 fontsize = 14
50 labelloc=top
51 pad = "0.5,0.5"
54 EOT
57 if [ -n "$sort" ]; then
58 tsort_input=`mktemp`
59 exec 4>$tsort_input
60 exec 5<$tsort_input
61 rm $tsort_input
64 ## List branches
66 git for-each-ref refs/top-bases |
67 while read rev type ref; do
68 name="${ref#refs/top-bases/}"
69 if branch_annihilated "$name"; then
70 continue;
71 fi;
73 if [ -n "$terse" ]; then
74 echo "$name"
75 continue
77 if [ -n "$graphviz$sort$deps" ]; then
78 git cat-file blob "$name:.topdeps" | while read dep; do
79 dep_is_tgish=true
80 ref_exists "refs/top-bases/$dep" ||
81 dep_is_tgish=false
82 if ! "$dep_is_tgish" || ! branch_annihilated $dep; then
83 if [ -n "$graphviz" ]; then
84 echo "\"$name\" -> \"$dep\";"
85 elif [ -n "$deps" ]; then
86 echo "$name $dep"
87 else
88 echo "$name $dep" >&4
91 done
92 continue
95 missing_deps=
97 current=' '
98 [ "$name" != "$curname" ] || current='>'
99 nonempty=' '
100 ! branch_empty "$name" || nonempty='0'
101 remote=' '
102 [ -z "$base_remote" ] || remote='l'
103 ! has_remote "$name" || remote='r'
104 rem_update=' '
105 [ "$remote" != 'r' ] || ! ref_exists "refs/remotes/$base_remote/top-bases/$name" || {
106 branch_contains "refs/top-bases/$name" "refs/remotes/$base_remote/top-bases/$name" &&
107 branch_contains "$name" "refs/remotes/$base_remote/$name"
108 } || rem_update='R'
109 [ "$rem_update" = 'R' ] || branch_contains "refs/remotes/$base_remote/$name" "$name" 2>/dev/null ||
110 rem_update='L'
111 deps_update=' '
112 needs_update "$name" >/dev/null || deps_update='D'
113 deps_missing=' '
114 [ -z "$missing_deps" ] || deps_missing='!'
115 base_update=' '
116 branch_contains "$name" "refs/top-bases/$name" || base_update='B'
118 if [ "$(git rev-parse "$name")" != "$rev" ]; then
119 subject="$(git cat-file blob "$name:.topmsg" | sed -n 's/^Subject: //p')"
120 else
121 # No commits yet
122 subject="(No commits)"
125 printf '%s\t%-31s\t%s\n' "$current$nonempty$remote$rem_update$deps_update$deps_missing$base_update" \
126 "$name" "$subject"
127 done
129 if [ -n "$graphviz" ]; then
130 echo '}'
133 if [ -n "$sort" ]; then
134 tsort <&5
138 # vim:noet