Permalink
Browse files

Updated the graph-dag script to differentiate unreachable commits

  • Loading branch information...
1 parent a272415 commit 627118c043bc7f277be18e48b7434c9bc713fa14 @whiteinge committed Jul 31, 2012
Showing with 55 additions and 24 deletions.
  1. +55 −0 cars_2012-04-27_git/git-graph-dag
  2. +0 −24 cars_2012-04-27_git/graph-dag.sh
@@ -0,0 +1,55 @@
+#!/bin/bash
+# Draw a graphviz diagram of the Git DAG
+#
+# Labels consist of the short SHA1 and any refs.
+# Unreachable commits (ignoring the reflog) will be marked with an asterisk and
+# drawn with dashed lines.
+#
+# Largely stolen from https://git.wiki.kernel.org/index.php/ExampleScripts
+#
+# Usage:
+# git graph-dag HEAD~10.. | dot -Tpng | display -antialias
+#
+# Accepts any range or arguments that git rev-list accepts.
+
+set -e
+
+if [[ -z $@ ]] ; then
+ echo -e "Usage: git graph-dag HEAD~10.. | dot -Tpng | display -antialias"
+ exit 1
+fi
+
+echo "digraph lattice {"
+
+# Draw the DAG and connect parents
+git rev-list --parents "$@" |
+ while read commit parents
+ do
+ for p in $parents
+ do
+ echo "n$commit -> n$p"
+ done
+ done
+
+# Make pretty labels with the short sha1 and any refs
+git rev-list --pretty=format:"%H %h %d" "$@" | awk '
+BEGIN {
+ command = "git fsck --unreachable --no-reflogs | cut -d\" \" -f3"
+ while (command | getline unr) unreachable[unr] = 1
+ close(command)
+}
+
+!/^commit/ {
+ refs = ""
+ for (i=3; i<=NF; i++) refs = refs " " $i
+
+ unreachable[$1] == 1 ? isunr = 1 : isunr = 0
+
+ printf "n%s [shape=Mrecord, style=%s, label=\"{%s%s}\"]\n", \
+ $1, \
+ isunr == 1 ? "dashed" : "filled", \
+ isunr == 1 ? "*" $2 : $2, \
+ refs == "" ? "" : refs
+}'
+
+echo "}"
@@ -1,24 +0,0 @@
-#!/bin/sh
-
-set -e
-
-echo "digraph lattice {"
-
-git rev-list --pretty=format:"%H %h %d" "$@" | awk '
-!/^commit/ {
- refs = ""
- for (i=3; i<=NF; i++) refs = refs " " $i
- print "n" $1, "[shape=Mrecord, style=filled, label=\"{" $2 refs "}\"]"
-}
-'
-
-git rev-list --parents "$@" |
- while read commit parents
- do
- for p in $parents
- do
- echo "n$commit -> n$p"
- done
- done
-
-echo "}"

0 comments on commit 627118c

Please sign in to comment.