Last active
December 20, 2015 10:59
-
-
Save nibrahim/6119925 to your computer and use it in GitHub Desktop.
Git repository visualisation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
showrepo () { | |
img=$(tempfile -s.png) | |
~/bin/showrepo.rb $1 | dot -Tpng > $img | |
echo $img | |
qiv $img | |
} | |
showdag () { | |
img=$(tempfile -s.png) | |
~/bin/showdag.rb $1 | dot -Tpng > $img | |
echo $img | |
qiv $img | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rugged' | |
$commits = {} | |
def plot_tree(repo, tree) | |
tree.each do |item| | |
puts "\"#{tree.oid.slice 0,5}\" -> \"#{item[:oid].slice 0,5}\";" | |
if item[:type] == :tree # item.is_a?(Rugged::Tree) | |
puts "\"#{item[:oid].slice 0,5}\" [shape=polygon, sides=3, style=filled,color=\"green\"];" | |
plot_tree(repo, repo.lookup(item[:oid])) | |
else | |
puts "\"#{item[:oid].slice 0,5}\" [style=filled,color=\"lightgray\"];" | |
end | |
end | |
end | |
def plot_commit (repo, commit) | |
if $commits.has_key? commit.oid | |
return | |
else | |
$commits[commit.oid] = 1 | |
puts "\"#{commit.oid.slice 0,5}\" [shape=polygon, sides=4, style=filled, color=\"yellow\"];" | |
puts "\"#{commit.tree.oid.slice 0,5}\" [shape=polygon, sides=3, style=filled, color=\"green\"];" | |
puts "\"#{commit.oid.slice 0,5}\" -> \"#{commit.tree.oid.slice 0,5}\";" | |
plot_tree(repo, commit.tree) | |
commit.parents.each do |c| | |
puts "\"#{commit.oid.slice 0,5}\" -> \"#{c.oid.slice 0,5}\";" | |
plot_commit(repo, c) | |
end | |
end | |
end | |
def plot_tags(repo) | |
repo.tags.each do |tag| | |
puts "\"#{tag.name}\" -> \"#{tag.target.oid.slice 0,5}\";" | |
puts "\"#{tag.name}\" [shape=box, style=filled, color = magenta];" | |
end | |
end | |
puts "Digraph F {" | |
puts 'ranksep=0.5; size = "17.5,7.5"; rankdir=RL;' | |
repo = Rugged::Repository.new(ARGV[0]); | |
repo.branches.each do |b| | |
puts "\"#{b.name}\" -> \"#{b.target.oid.slice 0,5}\";" | |
puts "\"#{b.name}\" [shape=polygon, sides=6, style=filled, color = red];" | |
plot_commit(repo, b.target) | |
end | |
plot_tags(repo) | |
puts "}" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rugged' | |
$commits = {} | |
def commit_node_label(commit) | |
return "#{commit.oid.slice 0,5}" | |
end | |
def plot_tree (commit) | |
if $commits.has_key? commit.oid | |
return | |
else | |
$commits[commit.oid] = 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.target}\";" | |
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.canonical_name}\" -> \"#{commit_node_label b.target}\";" | |
puts "\"#{b.canonical_name}\" [shape=polygon, sides=6, style=filled, color = red];" | |
plot_tree(b.target) | |
end | |
end | |
puts "Digraph F {" | |
puts 'ranksep=0.5; size = "17.5,7.5"; rankdir=RL;' | |
repo = Rugged::Repository.new(ARGV[0]); | |
draw_branch_heads(repo) | |
plot_tags(repo) | |
draw_head(repo) | |
puts "}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment