-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitvis.sh
executable file
·68 lines (61 loc) · 2.06 KB
/
gitvis.sh
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
#!/bin/bash
# gitvis.sh
#
# Create PlantUML code to visualize the graph of a git repository
# This script is experimental. Purely educational purpose.
#
# Copyright 2019 Martin Michel
#
# This file is part of git2pic.
#
# git2pic is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# git2pic is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with git2pic. If not, see <http://www.gnu.org/licenses/>.
echo "@startuml"
echo "!pragma ratio 0.99"
echo "scale 0.9"
echo "left to right direction"
for obj in $(find .git/objects -type f \
| sed -e 's/^.git\/objects\///' -e 's/\///' \
| cut -c-5)
do
if [[ $(git cat-file -t "$obj") == "commit" ]]
then
echo "[$obj] <<commit>>"
git cat-file commit "$obj" \
| grep tree \
| awk -v o="$obj" \
'{printf "[%s] <<tree>>\n[%s] --> %s\n", \
substr($2,1,5), o, substr($2,1,5)}'
elif [[ $(git cat-file -t "$obj") == "tree" ]]
then
for item in $(git ls-tree "$obj" | awk '{print $2}')
do
if [[ $item == "tree" ]]
then
git ls-tree "$obj" \
| grep tree \
| awk -v o="$obj" \
'{printf "[%s] <<tree>>\n\
[%s] --> %s : <color:Blue><size:14><&folder>%s/\n", \
substr($3,1,5), o, substr($3,1,5), $4}'
elif [[ $item == "blob" ]]
then
git ls-tree "$obj" \
| grep blob \
| awk -v o="$obj" \
'{printf "[%s] <<blob>>\n\
[%s] --> %s : <color:Green><size:14><&file>%s\n", \
substr($3,1,5), o, substr($3,1,5), $4}'
fi
done
fi
done | sort -k 3 | uniq
echo "@enduml"