chiark / gitweb /
Added the --deps option to "tg summary".
[topgit.git] / tg-summary.sh
index 50ee8832090c6646c9bd114d6f5926657dcc07db..a92480ff38f0f13444909c5d3895ae2543b7765e 100644 (file)
@@ -5,6 +5,8 @@
 
 terse=
 graphviz=
+sort=
+deps=
 
 
 ## Parse options
@@ -16,16 +18,21 @@ while [ -n "$1" ]; do
                terse=1;;
        --graphviz)
                graphviz=1;;
+       --sort)
+               sort=1;;
+       --deps)
+               deps=1;;
        *)
-               echo "Usage: tg [...] summary [-t | --graphviz]" >&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\)/##')"
 
-! [ -n "$terse" -a -n "$graphviz" ] ||
-       die "-t and --graphviz options are mutual exclusive"
+[ "$terse$graphviz$sort$deps" = "" ] ||
+       [ "$terse$graphviz$sort$deps" = "1" ] ||
+       die "mutually exclusive options given"
 
 if [ -n "$graphviz" ]; then
        cat <<EOT
@@ -47,6 +54,12 @@ graph [
 EOT
 fi
 
+if [ -n "$sort" ]; then
+       tsort_input=`mktemp`
+       exec 4>$tsort_input
+       exec 5<$tsort_input
+       rm $tsort_input
+fi
 
 ## List branches
 
@@ -61,13 +74,19 @@ git for-each-ref refs/top-bases |
                        echo "$name"
                        continue
                fi
-               if [ -n "$graphviz" ]; then
+               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
-                                       echo "\"$name\" -> \"$dep\";"
+                                       if [ -n "$graphviz" ]; then
+                                               echo "\"$name\" -> \"$dep\";"
+                                       elif [ -n "$deps" ]; then
+                                               echo "$name $dep"
+                                       else
+                                               echo "$name $dep" >&4
+                                       fi
                                fi
                        done
                        continue
@@ -111,4 +130,9 @@ if [ -n "$graphviz" ]; then
        echo '}'
 fi
 
+if [ -n "$sort" ]; then
+       tsort <&5
+fi
+
+
 # vim:noet