-
Notifications
You must be signed in to change notification settings - Fork 71
/
git-plotrepo.rb
executable file
·54 lines (43 loc) · 1.21 KB
/
git-plotrepo.rb
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
#!/usr/bin/env ruby
# Usage: ruby plotrepo.rb /path/to/repository | dot -Tpng | display -antialias
require 'grit'
$commits = {}
def commit_node_label(commit)
return "#{commit.id.slice 0,5}\\n(#{commit.message.split("\n")[0]})"
end
def plot_tree (commit)
if $commits.has_key? commit.id
return
else
$commits[commit.id] = 1
commit.parents.each do |c|
puts "\"#{commit_node_label commit}\" -> \"#{commit_node_label c}\";"
plot_tree(c)
end
end
end
def plot_tags(repo)
repo.tags.each do |tag|
puts "\"#{tag.name}\" -> \"#{commit_node_label tag.commit}\";"
puts "\"#{tag.name}\" [shape=box, style=filled, color = yellow];"
end
end
def draw_head(repo)
head = repo.head.name;
puts "\"HEAD\" [shape=box, style=filled, color = green];"
puts "\"HEAD\" -> \"#{head}\";"
end
def draw_branch_heads(repo)
repo.branches.each do |b|
puts "\"#{b.name}\" -> \"#{commit_node_label b.commit}\";"
puts "\"#{b.name}\" [shape=polygon, sides=6, style=filled, color = red];"
plot_tree(b.commit)
end
end
puts "Digraph F {"
puts 'ranksep=0.5; size = "17.5,7.5"; rankdir=RL;'
repo = Grit::Repo.new(ARGV[0]);
draw_branch_heads(repo)
plot_tags(repo)
draw_head(repo)
puts "}"