doc: git doesn't use git-foo invocations.
[guilt.git] / guilt-graph
blob0857e0da2a23f9304b62c0f3d65f8911bdb46201
1 #!/bin/sh
3 # Copyright (c) Josef "Jeff" Sipek, 2007-2013
6 USAGE="[<patchname>]"
7 if [ -z "$GUILT_VERSION" ]; then
8 echo "Invoking `basename "$0"` directly is no longer supported." >&2
9 exit 1
12 _main() {
14 if [ $# -gt 1 ]; then
15 usage
18 patchname="$1"
20 bottompatch=$(head_n 1 < "$applied")
21 if [ -z "$bottompatch" ]; then
22 echo "No patch applied." >&2
23 exit 1
26 base=`git rev-parse "refs/patches/${branch}/${bottompatch}^"`
28 if [ -z "$patchname" ]; then
29 top=`git rev-parse HEAD`
30 else
31 top=`grep "^$patchname$" "$applied"`
32 if [ -z "$top" ]; then
33 die "Cannot find patch '$patchname'. Is it applied?"
37 getfiles()
39 git diff-tree -r "$1^" "$1" | tr '\t' ' ' | cut -d' ' -f6
42 cache="$GUILT_DIR/$branch/.graphcache.$$"
43 mkdir "$cache"
44 trap "rm -rf \"$cache\"" 0
46 disp "digraph G {"
48 current="$top"
50 safebranch=`echo "$branch"|sed 's%/%\\\\/%g'`
51 while [ "$current" != "$base" ]; do
52 pname=`git show-ref | sed -n -e "
53 /^$current refs\/patches\/$safebranch/ {
54 s:^$current refs/patches/$branch/::
57 }"`
58 [ -z "$pname" ] && pname="?"
60 pname="`printf \"%s\" \"$pname\" | sed 's/\"/\\\\\"/g'`"
62 disp "# checking rev $current"
63 disp " \"$current\" [label=\"$pname\"]"
65 # new "hash table"
66 rm -f "$cache/dep"
67 touch "$cache/dep"
69 getfiles $current | while read f; do
70 # hash the filename
71 fh=`echo "$f" | sha1 | cut -d' ' -f1`
72 if [ -e "$cache/$fh" ]; then
73 # ok, something already touched this file before us
74 cat "$cache/$fh" >> "$cache/dep"
76 echo "$current" > "$cache/$fh"
77 done
79 sort -u "$cache/dep" | while read h; do
80 disp " \"$h\" -> \"$current\"; // ?"
81 done
83 current=`git rev-parse $current^`
84 done
86 disp "}"