public
Fork of cv/git-utils
Description: Utilities for Git users
Homepage:
Clone URL: git://github.com/spraints/git-utils.git
git-utils / git-graph-objects
100755 91 lines (78 sloc) 1.365 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/sh
 
. git-sh-setup
 
indent=' '
 
make_node()
{
  sha=$1
  type=$2
  shape=$3
  color=$4
  short_sha=$(echo $sha | cut -c 1-10)
  echo "$indent" \"$sha\" [ label=\"$type $short_sha...\", shape=$shape, color=$color ] \;
}
 
make_edge()
{
  source=$1
  destination=$2
  label=$3
  if [ -n "$label" ] ; then label=label=\"$label\" ; fi
echo "$indent" \"$source\" '->' \"$destination\" [ $label ] \;
}
 
graph_blob()
{
  make_node $1 blob ellipse red
}
 
graph_commit_parts()
{
  commit=$1
  while read type sha
  do
if [ "$type" = 'parent' -o "$type" = 'tree' ]
    then
make_edge $commit $sha $type
    fi
done
}
 
graph_commit()
{
  sha=$1
  make_node $1 commit box3d green
  git cat-file commit $sha | graph_commit_parts $sha
}
 
graph_tree_parts()
{
  tree=$1
  while read mode type sha name
  do
make_edge $tree $sha $name
  done
}
 
graph_tree()
{
  sha=$1
  make_node $sha tree box blue
  git ls-tree $sha | graph_tree_parts $sha
}
 
graph_refs()
{
  while read sha name
  do
echo "$indent" \"$name\" [ shape=plaintext ] \;
    make_edge $name $sha
  done
}
 
make_edges()
{
  while read sha type
do
graph_$type $sha
  done
}
 
echo digraph
echo {
echo bgcolor = black ;
echo node [ color = white, fontcolor = white ] ;
echo edge [ color = white, fontcolor = white ] ;
git ls-objects | make_edges
git show-ref | graph_refs
echo }