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>
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
terse=1;;
--graphviz)
graphviz=1;;
terse=1;;
--graphviz)
graphviz=1;;
- echo "Usage: tg [...] summary [-t | --graphviz]" >&2
+ echo "Usage: tg [...] summary [-t | --sort | --graphviz]" >&2
! [ -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:
+if [ -n "$sort" ]; then
+ tsort_input=`mktemp`
+ exec 4>$tsort_input
+ exec 5<$tsort_input
+ rm $tsort_input
+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
+if [ -n "$sort" ]; then
+ tsort <&5
+fi
+
+