X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=topgit.git;a=blobdiff_plain;f=tg-summary.sh;h=1c99e2225c61a2a4c9a07ec6bd64ee82558ddda7;hp=c608a18fae93d41352d65937cd5dc938846df9ae;hb=120b1ea119b87b3ea292f0c2e2416540e790fcd1;hpb=308892d0c071135031994606170c8be6653e7197 diff --git a/tg-summary.sh b/tg-summary.sh index c608a18..1c99e22 100644 --- a/tg-summary.sh +++ b/tg-summary.sh @@ -3,36 +3,152 @@ # (c) Petr Baudis 2008 # GPLv2 +terse= +graphviz= +sort= +deps= +head_from= ## Parse options -if [ -n "$1" ]; then - echo "Usage: tg summary" >&2 - exit 1 +while [ -n "$1" ]; do + arg="$1"; shift + case "$arg" in + -i|-w) + [ -z "$head_from" ] || die "-i and -w are mutually exclusive" + head_from="$arg";; + -t) + terse=1;; + --graphviz) + graphviz=1;; + --sort) + sort=1;; + --deps) + deps=1;; + *) + echo "Usage: tg [...] summary [-t | --sort | --deps | --graphviz] [-i | -w]" >&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 < +# 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="$(get_temp tg-summary-sort)" + exec 4>$tsort_input + exec 5<$tsort_input +fi ## List branches -git for-each-ref | cut -f 2 | - while read ref; do - name="${ref#refs/heads/}" - [ "$name" != "$ref" ] || - continue # eew, not a branch - git rev-parse --verify "refs/top-bases/$name" >/dev/null 2>&1 || - continue # not a TopGit branch - - deps_update=' ' - [ -z "$(needs_update "$name")" ] || deps_update='D' - base_update=' ' - branch_contains "$name" "refs/top-bases/$name" || base_update='B' - - if [ "$(git rev-parse "$name")" != "$(git rev-parse "refs/top-bases/$name")" ]; then - subject="$(git cat-file blob "$name:.topmsg" | sed -n 's/^Subject: //p')" - else - # No commits yet - subject="(No commits)" +process_branch() +{ + missing_deps= + + current=' ' + [ "$name" != "$curname" ] || current='>' + from=$head_from + [ "$name" = "$curname" ] || + from= + nonempty=' ' + ! branch_empty "$name" $from || nonempty='0' + remote=' ' + [ -z "$base_remote" ] || remote='l' + ! has_remote "$name" || remote='r' + rem_update=' ' + [ "$remote" != 'r' ] || ! ref_exists "refs/remotes/$base_remote/top-bases/$name" || { + branch_contains "refs/top-bases/$name" "refs/remotes/$base_remote/top-bases/$name" && + branch_contains "$name" "refs/remotes/$base_remote/$name" + } || rem_update='R' + [ "$rem_update" = 'R' ] || branch_contains "refs/remotes/$base_remote/$name" "$name" 2>/dev/null || + rem_update='L' + deps_update=' ' + needs_update "$name" >/dev/null || deps_update='D' + deps_missing=' ' + [ -z "$missing_deps" ] || deps_missing='!' + base_update=' ' + branch_contains "$name" "refs/top-bases/$name" || base_update='B' + + if [ "$(git rev-parse "$name")" != "$rev" ]; then + subject="$(cat_file "$name:.topmsg" $from | sed -n 's/^Subject: //p')" + else + # No commits yet + subject="(No commits)" + fi + + printf '%s\t%-31s\t%s\n' "$current$nonempty$remote$rem_update$deps_update$deps_missing$base_update" \ + "$name" "$subject" +} + +if [ -n "$deps" ]; then + list_deps $head_from + exit 0 +fi + +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 - printf '%s%s\t%-31s\t%s\n' "$deps_update" "$base_update" "$name" "$subject" + if [ -n "$terse" ]; then + echo "$name" + elif [ -n "$graphviz$sort" ]; then + from=$head_from + [ "$name" = "$curname" ] || + from= + cat_file "$name:.topdeps" $from | 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\";" + if [ "$name" = "$curname" ] || [ "$dep" = "$curname" ]; then + echo "\"$curname\" [style=filled,fillcolor=yellow];" + fi + else + echo "$name $dep" >&4 + fi + fi + done + else + process_branch + fi done + +if [ -n "$graphviz" ]; then + echo '}' +fi + +if [ -n "$sort" ]; then + tsort <&5 +fi + + +# vim:noet