A tiny script to display the entire contents of a medium sized git repository. It will display tags, branches and commits with different shapes and colours and the commits messages in a dimmed colour.
It relies on graphviz to do the plotting. Use it like so
ruby plotrepo.rb /path/to/repository | dot -Tpng | display -antialias
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 | #!/usr/bin/env ruby
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 "}"
|
This is useful to show the entire repo with all the branches and everything especially when training students on how various operations alter the repo. I find it much more understandable than that of gitk.
This doesn't work for huge repositories.