Created
April 25, 2012 16:56
-
-
Save ryands/2491285 to your computer and use it in GitHub Desktop.
prettify git commit logs for html output/display
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/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 = {}; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It screws up on commits with no log message (normally you can't really generate these, but gist does). Probably won't fix.