Last active
November 11, 2015 18:18
-
-
Save Teino1978-Corp/4843648f06932bd42d6c to your computer and use it in GitHub Desktop.
git-graph
This file contains hidden or 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 '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 "}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment