chiark / gitweb /
Added the --deps option to "tg summary".
[topgit.git] / tg-summary.sh
index 3905bdce7dc1d934a7862c025c4fb772c52660d6..a92480ff38f0f13444909c5d3895ae2543b7765e 100644 (file)
@@ -4,6 +4,9 @@
 # GPLv2
 
 terse=
+graphviz=
+sort=
+deps=
 
 
 ## Parse options
@@ -13,24 +16,81 @@ while [ -n "$1" ]; do
        case "$arg" in
        -t)
                terse=1;;
+       --graphviz)
+               graphviz=1;;
+       --sort)
+               sort=1;;
+       --deps)
+               deps=1;;
        *)
-               echo "Usage: tg [...] summary [-t]" >&2
+               echo "Usage: tg [...] summary [-t | --sort | --deps | --graphviz]" >&2
                exit 1;;
        esac
 done
 
 curname="$(git symbolic-ref HEAD | sed 's#^refs/\(heads\|top-bases\)/##')"
 
+[ "$terse$graphviz$sort$deps" = "" ] ||
+       [ "$terse$graphviz$sort$deps" = "1" ] ||
+       die "mutually exclusive options given"
+
+if [ -n "$graphviz" ]; then
+       cat <<EOT
+# GraphViz output; pipe to:
+#   | dot -Tpng -o <ouput>
+# or
+#   | dot -Txlib
+
+digraph G {
+
+graph [
+  rankdir = "TB"
+  label="TopGit Layout\n\n\n"
+  fontsize = 14
+  labelloc=top
+  pad = "0.5,0.5"
+];
+
+EOT
+fi
+
+if [ -n "$sort" ]; then
+       tsort_input=`mktemp`
+       exec 4>$tsort_input
+       exec 5<$tsort_input
+       rm $tsort_input
+fi
 
 ## List branches
 
 git for-each-ref refs/top-bases |
        while read rev type ref; do
                name="${ref#refs/top-bases/}"
+               if branch_annihilated "$name"; then
+                       continue;
+               fi;
+
                if [ -n "$terse" ]; then
                        echo "$name"
                        continue
                fi
+               if [ -n "$graphviz$sort$deps" ]; then
+                       git cat-file blob "$name:.topdeps" | while read dep; do
+                               dep_is_tgish=true
+                               ref_exists "refs/top-bases/$dep"  ||
+                                       dep_is_tgish=false
+                               if ! "$dep_is_tgish" || ! branch_annihilated $dep; then
+                                       if [ -n "$graphviz" ]; then
+                                               echo "\"$name\" -> \"$dep\";"
+                                       elif [ -n "$deps" ]; then
+                                               echo "$name $dep"
+                                       else
+                                               echo "$name $dep" >&4
+                                       fi
+                               fi
+                       done
+                       continue
+               fi
 
                missing_deps=
 
@@ -65,3 +125,14 @@ git for-each-ref refs/top-bases |
                printf '%s\t%-31s\t%s\n' "$current$nonempty$remote$rem_update$deps_update$deps_missing$base_update" \
                        "$name" "$subject"
        done
+
+if [ -n "$graphviz" ]; then
+       echo '}'
+fi
+
+if [ -n "$sort" ]; then
+       tsort <&5
+fi
+
+
+# vim:noet