#!/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 "}"
Diff to Previous Revision
--- revision 1 2011-02-11 18:57:27
+++ revision 2 2012-07-05 17:01:53
@@ -4,15 +4,18 @@
$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.message}\" -> \"#{commit.id.slice 0,7}\" [arrowhead=dot, color= lightgray, arrowtail=vee];"
- puts "\"#{commit.message}\" [shape=box, fontname=courier, fontsize = 8, color=lightgray, fontcolor=lightgray];"
- puts "\"#{commit.id.slice 0,7}\" -> \"#{c.id.slice 0,7}\";"
+ puts "\"#{commit_node_label commit}\" -> \"#{commit_node_label c}\";"
plot_tree(c)
end
end
@@ -20,19 +23,30 @@
def plot_tags(repo)
repo.tags.each do |tag|
- puts "\"#{tag.name}\" -> \"#{tag.commit.id.slice 0,7}\";"
+ 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.2;'
+puts 'ranksep=0.5; size = "17.5,7.5"; rankdir=RL;'
repo = Grit::Repo.new(ARGV[0]);
-repo.branches.each do |b|
- puts "\"#{b.name}\" -> \"#{b.commit.id.slice 0,7}\";"
- puts "\"#{b.name}\" [shape=polygon, sides=6, style=filled, color = red];"
- plot_tree(b.commit)
-end
+draw_branch_heads(repo)
plot_tags(repo)
+draw_head(repo)
puts "}"