Permalink
Browse files

[42] Implemented new method to convert `git log` to HTML file

Signed-off-by: DoesntMatter <jaed1@gmx.net>
  • Loading branch information...
DoesntMatter committed Jan 23, 2012
1 parent aee61df commit 4429e42eaec08082f81662bfd06cda05405ddf79
Showing with 182 additions and 0 deletions.
  1. +92 −0 libs/HTML.pm
  2. +90 −0 scripts/gitlog_to_html.pl
View
@@ -0,0 +1,92 @@
#!/usr/bin/perl -w
# GitlogParser
# Converts the output of `git log` to different output types
#
# Copyright (C) 2012, by: Dennis Christ <jaed1@gmx.net>
# http://dev-blog.doesntmatter.de
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# The GNU General Public License is available at:
# http://www.gnu.org/copyleft/gpl.html
use strict;
no warnings 'uninitialized'; # We can use uninitialized variables without any problem here
package HTML;
#
# Subroutines
#
sub ShowHelp {
print <<"HELP";
Gitlog to HTML - Converts the output of `git log` to a HTML file
Copyright (C) 2012, by: Dennis Christ <jaed1\@gmx.net>
Options:
--repo REPO Path to your Git repository
--count COUNT Count of commits that shoud be parsed
Default: All commits
--outfile FILE Name and path of generated SQL file
Default: \$PWD/log.html
--prompt Prompt for input and do not use options
--help Show this output
HELP
exit;
}
sub CreateHTML {
my $gitlog = shift || return undef;
my $file = shift || return undef;
my @items = Parser::SplitCommits($gitlog, "\n&gt;");
open(FILE, ">$file");
print FILE "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE html
PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<title></title>
</head>
<body>";
close(FILE);
open(FILE, ">>$file");
for my $i ( 0 .. $#items ) {
# $items[$i][0] Blank
# $items[$i][1] Commit-Hash
# $items[$i][2] Commit-Date
# $items[$i][3] Author
# $items[$i][4] E-Mail
# $items[$i][5] Subject
# $items[$i][6] Body
print FILE "<h3>$items[$i][5]</h3>
<p>$items[$i][3] &lt;$items[$i][4]&gt; committed $items[$i][1]</p>
<p>$items[$i][2]</p>
<p>$items[$i][5]</p>
<p>$items[$i][6]</p>";
}
close(FILE);
open(FILE, ">>$file");
print FILE "</body>
</html>";
close(FILE);
return 1;
}
return 1;
View
@@ -0,0 +1,90 @@
#!/usr/bin/perl -w
# GitlogParser
# Converts the output of `git log` to different output types
#
# Copyright (C) 2012, by: Dennis Christ <jaed1@gmx.net>
# http://dev-blog.doesntmatter.de
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# The GNU General Public License is available at:
# http://www.gnu.org/copyleft/gpl.html
use strict;
use Getopt::Long;
use Cwd;
use HTML::Entities;
use FindBin;
use lib "$FindBin::Bin/../libs";
use Generic;
use Parser;
use HTML;
my ($gitlog, $giturl);
my %options = (
outfile => cwd() . "/log.html",
);
#
# Get options
#
GetOptions (
\%options,
"repo=s",
"count=i",
"outfile=s",
"prompt",
"help|?",
);
#
# Check and set options
#
unless ($options{'prompt'}) {
if ($options{'help'}) {
HTML::ShowHelp();
}
if (Generic::HasValue($options{'repo'})) {
unless (Generic::CheckRepo($options{'repo'})) {
HTML::ShowHelp();
}
}
else {
HTML::ShowHelp();
}
}
else {
$options{'repo'} = Generic::GetInput("Please enter repository path: ", 1);
unless (Generic::CheckRepo($options{'repo'})) {
HTML::ShowHelp();
}
$options{'count'} = Generic::GetInput("Please enter count of commits: ");
$options{'outfile'} = Generic::GetInput("Please enter outfile path: ");
}
#
# Do the job
#
$gitlog = Parser::ParseGitLog($options{'repo'}, $options{'count'});
unless ($gitlog) {
print "Parsing `git log` command failed!\n";
exit;
}
HTML::CreateHTML(HTML::Entities::encode($gitlog), $options{'outfile'});
exit;

0 comments on commit 4429e42

Please sign in to comment.