Skip to content

Instantly share code, notes, and snippets.

@ryands
Created April 25, 2012 16:56
Show Gist options
  • Save ryands/2491285 to your computer and use it in GitHub Desktop.
Save ryands/2491285 to your computer and use it in GitHub Desktop.
prettify git commit logs for html output/display
#!/usr/bin/perl -w
# Format a gitlog with html to look nice (for senior design doc)
# usage:
# perl gitlog.pl < logfile.txt > logfile.html
# - or -
# git log --pretty=fuller | perl gitlog.pl > logfile.html
$commit = {};
$state_log = 0;
while(my $line = <>) {
if( $state_log == 0 && $line =~ /^commit (.+)/ ) {
$state_log = 1;
$commit{'sha1'} = $1;
} elsif ($state_log == 1 && $line ne "\n" && $line =~ /^([^\s]+): (.+)$/ ) {
my $key = $1;
my $val = $2; $val =~ s/^\s+|\s+$//gi;
$commit{$key} = $val;
if( $key eq "Commit" ) {
$state_log = 2;
}
} elsif ($state_log == 2 && $line eq "\n" ) {
$commit{'log'} = "";
$state_log = 3;
} elsif ($state_log == 3 && $line ne "\n" ) {
$line =~ s/^ |\n$//;
$commit{'log'} .= $line;
} elsif ($state_log == 3 && $line eq "\n" ) {
# output
print <<EOL;
<div class="commit">
<div class="commit-entry">
<strong>Commit:</strong> $commit{sha1}
</div>
<div class="author-entry">
<strong>Author:</strong> $commit{Author}
</div>
<div class="date-entry">
<strong>Date:</strong> $commit{AuthorDate}
</div>
<div class="log-entry">
<pre>
$commit{log}
</pre>
</div>
</div>
EOL
# cleanup
$state_log = 0;
$commit = {};
}
}
@ryands
Copy link
Author

ryands commented Apr 25, 2012

It screws up on commits with no log message (normally you can't really generate these, but gist does). Probably won't fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment