commit: don't lose commits
[guilt.git] / guilt-graph
blobeaf3309a6bb4519eebe88d019e0c6dc4fd691e9a
1 #!/bin/sh
3 # Copyright (c) Josef "Jeff" Sipek, 2007-2011
6 USAGE="[<patchname>]"
7 if [ -z "$GUILT_VERSION" ]; then
8 echo "Invoking $GUILT directly is no longer supported." >&2
9 exit 1
12 _main() {
14 if [ $# -gt 1 ]; then
15 usage
18 patchname="$1"
20 bottom=`git rev-parse refs/patches/$branch/$(head_n 1 < "$applied")`
21 base=`git rev-parse $bottom^`
23 if [ -z "$patchname" ]; then
24 top=`git rev-parse HEAD`
25 else
26 top=`grep "^$patchname$" "$applied"`
27 if [ -z "$top" ]; then
28 die "Cannot find patch '$patchname'. Is it applied?"
32 getfiles()
34 git diff-tree -r "$1^" "$1" | tr '\t' ' ' | cut -d' ' -f6
37 cache="$GUILT_DIR/$branch/.graphcache.$$"
38 mkdir "$cache"
39 trap "rm -rf \"$cache\"" 0
41 disp "digraph G {"
43 current="$top"
45 safebranch=`echo "$branch"|sed 's%/%\\\\/%g'`
46 while [ "$current" != "$base" ]; do
47 pname=`git show-ref | sed -n -e "
48 /^$current refs\/patches\/$safebranch/ {
49 s,^$current refs/patches/$branch/,,
52 }"`
53 [ -z "$pname" ] && pname="?"
55 disp "# checking rev $current"
56 disp " \"$current\" [label=\"$pname\"]"
58 # new "hash table"
59 rm -f "$cache/dep"
60 touch "$cache/dep"
62 getfiles $current | while read f; do
63 # hash the filename
64 fh=`echo "$f" | sha1 | cut -d' ' -f1`
65 if [ -e "$cache/$fh" ]; then
66 # ok, something already touched this file before us
67 cat "$cache/$fh" >> "$cache/dep"
69 echo "$current" > "$cache/$fh"
70 done
72 sort -u "$cache/dep" | while read h; do
73 disp " \"$h\" -> \"$current\"; // ?"
74 done
76 current=`git rev-parse $current^`
77 done
79 disp "}"