import-commit: disallow <>(), in generated patch names
[guilt.git] / guilt-graph
bloba18fa488fe3454ce8d54a065dde7724bdab70610
1 #!/bin/sh
3 # Copyright (c) Josef "Jeff" Sipek, 2007-2013
6 USAGE="[-x exclude-pattern]... [<patchname>]"
7 if [ -z "$GUILT_VERSION" ]; then
8 echo "Invoking `basename "$0"` directly is no longer supported." >&2
9 exit 1
12 _main() {
14 cache="$GUILT_DIR/$branch/.graphcache.$$"
15 xclude="$GUILT_DIR/$branch/.graphexclude.$$"
16 trap "rm -rf \"$cache\" \"$xclude\"" 0
17 mkdir "$cache"
18 >"$xclude"
20 while [ $# -gt 0 ]; do
21 if [ "$1" = "-x" ] && [ $# -ge 2 ]; then
22 echo "$2" >> "$xclude"
23 shift
24 shift
25 else
26 break
28 done
30 if [ $# -gt 1 ]; then
31 usage
34 patchname="$1"
36 bottompatch=$(head_n 1 < "$applied")
37 if [ -z "$bottompatch" ]; then
38 echo "No patch applied." >&2
39 exit 1
42 base=`git rev-parse "refs/patches/${branch}/${bottompatch}^"`
44 if [ -z "$patchname" ]; then
45 top=`git rev-parse HEAD`
46 else
47 top=`grep "^$patchname$" "$applied"`
48 if [ -z "$top" ]; then
49 die "Cannot find patch '$patchname'. Is it applied?"
53 getfiles()
55 git diff-tree -r "$1^" "$1" | cut -f2
58 disp "digraph G {"
60 current="$top"
62 safebranch=`echo "$branch"|sed 's%/%\\\\/%g'`
63 while [ "$current" != "$base" ]; do
64 pname=`git show-ref | sed -n -e "
65 /^$current refs\/patches\/$safebranch/ {
66 s:^$current refs/patches/$branch/::
69 }"`
70 [ -z "$pname" ] && pname="?"
72 pname="`printf \"%s\" \"$pname\" | sed 's/\"/\\\\\"/g'`"
74 disp "# checking rev $current"
75 disp " \"$current\" [label=\"$pname\"]"
77 # new "hash table"
78 rm -f "$cache/dep"
79 touch "$cache/dep"
81 getfiles $current | grep -v -f "$xclude" | while read f; do
82 # hash the filename
83 fh=`echo "$f" | sha1 | cut -d' ' -f1`
84 if [ -e "$cache/$fh" ]; then
85 # ok, something already touched this file before us
86 cat "$cache/$fh" >> "$cache/dep"
88 echo "$current" > "$cache/$fh"
89 done
91 sort -u "$cache/dep" | while read h; do
92 disp " \"$h\" -> \"$current\"; // ?"
93 done
95 current=`git rev-parse $current^`
96 done
98 disp "}"