Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

GraphViz Git Commit Tree

View git.pl
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
#!perl
 
# Draw the commit graph of a git repository, using GraphViz. Supply the directory
# the repo is in as the first argument. Writes a file called 'repo.svg' to the CWD.
 
use strict; use warnings;
use Cwd;
use Git::PurePerl;
use GraphViz2;
 
my $directory = $ARGV[0] || getcwd();
 
# Load the GIT repo
my $repo = Git::PurePerl->new( directory => $directory );
my $head = $repo->master;
 
# Start a new Graph
my ($graph) = GraphViz2->new(
edge => { color => 'grey' },
global => { directed => 1 },
graph => { label => 'Repo Commit Tree', rankdir => 'TB' },
node => { shape => 'oval' },
);
 
# Recurse up the commit graph
add_commit( $head );
 
my %seen;
sub add_commit {
my $commit = shift;
my $name = substr( $commit->{'sha1'}, 0, 6 );
 
# Skip nodes we've already seen
return $name if $seen{ $name }++;
 
# Add the commit if we haven't already seen it
$graph->add_node( name => $name );
 
# Link back to parents
for my $parent ( $commit->parents ) {
no warnings 'recursion';
my $parent_name = add_commit( $parent );
$graph->add_edge( from => $parent_name, to => $name );
}
 
return $name;
}
 
$graph->run( output_file => 'repo.svg' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.