chiark / gitweb /
Implemented "tg summary --sort".
authorPer Cederqvist <ceder@lysator.liu.se>
Wed, 14 Jul 2010 16:21:02 +0000 (18:21 +0200)
committerUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Sun, 25 Jul 2010 18:51:04 +0000 (20:51 +0200)
This uses tsort to sort the branches based on their dependency graph.
Note: only a single sort order that fulfills the dependency graph is
printed.  There may be many other possible orderings.

A graphical text view would be much more useful, but this is till
a lot better than nothing.

Signed-off-by: Per Cederqvist <ceder@lysator.liu.se>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
README
tg-summary.sh

diff --git a/README b/README
index c418ff41a694b3920af6854d01f8b64f1ecc94d4..dcb7e805412d361def75c54e56f31f465bfbca58 100644 (file)
--- a/README
+++ b/README
@@ -351,6 +351,13 @@ tg summary
        pass '--graphviz' to get a dot-suitable output to draw a dependency
        graph between the topic branches.
 
        pass '--graphviz' to get a dot-suitable output to draw a dependency
        graph between the topic branches.
 
+       You can also use the --sort option to sort the branches using
+       a topological sort.  This is especially useful if each
+       TopGit-tracked topic branch depends on a single parent branch,
+       since it will then print the branches in the dependency
+       order.  In more complex scenarios, a text graph view would be
+       much more useful, but that is not yet implemented.
+
        TODO: Speed up by an order of magnitude
        TODO: Text graph view
 
        TODO: Speed up by an order of magnitude
        TODO: Text graph view
 
index 50ee8832090c6646c9bd114d6f5926657dcc07db..a2cb9862cec62195383c8d571604676a7b9a1971 100644 (file)
@@ -5,6 +5,7 @@
 
 terse=
 graphviz=
 
 terse=
 graphviz=
+sort=
 
 
 ## Parse options
 
 
 ## Parse options
@@ -16,8 +17,10 @@ while [ -n "$1" ]; do
                terse=1;;
        --graphviz)
                graphviz=1;;
                terse=1;;
        --graphviz)
                graphviz=1;;
+       --sort)
+               sort=1;;
        *)
        *)
-               echo "Usage: tg [...] summary [-t | --graphviz]" >&2
+               echo "Usage: tg [...] summary [-t | --sort | --graphviz]" >&2
                exit 1;;
        esac
 done
                exit 1;;
        esac
 done
@@ -27,6 +30,12 @@ curname="$(git symbolic-ref HEAD | sed 's#^refs/\(heads\|top-bases\)/##')"
 ! [ -n "$terse" -a -n "$graphviz" ] ||
        die "-t and --graphviz options are mutual exclusive"
 
 ! [ -n "$terse" -a -n "$graphviz" ] ||
        die "-t and --graphviz options are mutual exclusive"
 
+! [ -n "$sort" -a -n "$graphviz" ] ||
+       die "--sort and --graphviz options are mutual exclusive"
+
+! [ -n "$sort" -a -n "$terse" ] ||
+       die "-t and --sort options are mutual exclusive"
+
 if [ -n "$graphviz" ]; then
        cat <<EOT
 # GraphViz output; pipe to:
 if [ -n "$graphviz" ]; then
        cat <<EOT
 # GraphViz output; pipe to:
@@ -47,6 +56,12 @@ graph [
 EOT
 fi
 
 EOT
 fi
 
+if [ -n "$sort" ]; then
+       tsort_input=`mktemp`
+       exec 4>$tsort_input
+       exec 5<$tsort_input
+       rm $tsort_input
+fi
 
 ## List branches
 
 
 ## List branches
 
@@ -61,13 +76,17 @@ git for-each-ref refs/top-bases |
                        echo "$name"
                        continue
                fi
                        echo "$name"
                        continue
                fi
-               if [ -n "$graphviz" ]; then
+               if [ -n "$graphviz" ] || [ -n "$sort" ]; 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
                        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\";"
+                                       else
+                                               echo "$name $dep" >&4
+                                       fi
                                fi
                        done
                        continue
                                fi
                        done
                        continue
@@ -111,4 +130,9 @@ if [ -n "$graphviz" ]; then
        echo '}'
 fi
 
        echo '}'
 fi
 
+if [ -n "$sort" ]; then
+       tsort <&5
+fi
+
+
 # vim:noet
 # vim:noet