Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 56 lines (45 sloc) 1.37 KB
#!/usr/bin/env perl
use strict;
use warnings;
use GitGraph;
use Getopt::Long;
my %conf = ( repository => 'sierpinski' );
GetOptions( \%conf, 'repository=s' )
or die "Usage: $0 [ --repository <repository> ]";
# prepare some basic stuff
my $depth = shift || 0;
init( $conf{repository} ) if !-e $conf{repository};
my $r = Git::Repository->new( work_tree => $conf{repository} );
# a "node" is actually [ commit id, parent count ]
#
# in the following square:
#
# B C
# \ |
# A - N
#
# N is created to have the following parents:
# - A if A exists and has < 2 parents
# - B if B exists and has < 3 parents
# - C if C has < 3 parents
#
# if no parent is found, the node is not created
sub sierpinski {
my ( $branch, $prev ) = @_;
# empty row
return [ [ node($r, $branch), 0 ] ] if !$prev || !@$prev;
my $this;
for my $i ( 0 .. @$prev ) {
my @parents;
push @parents, $this->[ $i - 1 ][0], $prev->[ $i - 1 ][0]
if $i && $prev->[$i -1][0] && $prev->[ $i - 1 ][1] < 3;
push @parents, $prev->[$i][0] if $prev->[$i] && $prev->[$i][1] < 3;
@parents = grep {$_} @parents;
push @$this,
[ ( @parents ? node( $r, $branch, @parents ) : '' ), 0 + @parents ];
}
return $this;
}
my $row = [];
my $rows = 1 + ( $depth ? 2**( $depth - 1 ) : 0 );
$row = sierpinski( "sierpinski-$depth", $row ) for 1 .. $rows;