Permalink
Browse files

[26] Moved parsing functions to new header

Signed-off-by: DoesntMatter <jaed1@gmx.net>
  • Loading branch information...
DoesntMatter committed Jan 22, 2012
1 parent b002aa9 commit 3ee52397eaeea34e307761a83853b3c71c724c0a
Showing with 68 additions and 37 deletions.
  1. +2 −1 gitlog_to_rss.pl
  2. +0 −35 headers/generic.ph
  3. +65 −0 headers/parser.ph
  4. +1 −1 headers/rss.ph
View
@@ -25,6 +25,7 @@
use HTML::Entities;
require "headers/generic.ph";
require "headers/parser.ph";
require "headers/rss.ph";
my %options;
@@ -99,7 +100,7 @@
# Do the job
#
$gitlog = GENERIC::ParseGitLog($options{'repo'}, $options{'count'});
$gitlog = PARSER::ParseGitLog($options{'repo'}, $options{'count'});
unless ($gitlog) {
print "Parsing `git log` command failed!\n";
exit;
View
@@ -94,39 +94,4 @@ sub GetGithubUrl {
return undef;
}
sub ParseGitLog {
my $repo = shift || return undef;
my $count = shift;
my ($cmd, $result);
if ($count) {
$cmd = "git log -n$count --pretty=tformat:%H%n%cd%n%cn%n%ce%n%s%n%b%m $repo";
}
else {
$cmd = "git log --pretty=tformat:%H%n%cd%n%cn%n%ce%n%s%n%b%m $repo";
}
$result = "\n" . qx/$cmd/;
if ($? == -1) {
print "Command failed: $!\n";
return undef;
}
$result =~ s/\s+$//; # Remove trailing whitespaces
return $result;
}
sub SplitCommits {
my $gitlog = shift || return undef;
my $seperator = shift || "\n>";
my @items = split(/$seperator/, $gitlog);
my $size = scalar @items;
my (@lines, @commit, $i);
for $i ( 0 .. ($size - 1) ) {
@lines = split(/\n/, $items[$i], 7);
$commit[$i] = [ @lines ];
}
return @commit;
}
return 1;
View
@@ -0,0 +1,65 @@
#!/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;
package PARSER;
#
# Subroutines
#
sub ParseGitLog {
my $repo = shift || return undef;
my $count = shift;
my ($cmd, $result);
if ($count) {
$cmd = "git log -n$count --pretty=tformat:%H%n%cd%n%cn%n%ce%n%s%n%b%m $repo";
}
else {
$cmd = "git log --pretty=tformat:%H%n%cd%n%cn%n%ce%n%s%n%b%m $repo";
}
$result = "\n" . qx/$cmd/;
if ($? == -1) {
print "Command failed: $!\n";
return undef;
}
$result =~ s/\s+$//; # Remove trailing whitespaces
return $result;
}
sub SplitCommits {
my $gitlog = shift || return undef;
my $seperator = shift || "\n>";
my @items = split(/$seperator/, $gitlog);
my $size = scalar @items;
my (@lines, @commit, $i);
for $i ( 0 .. ($size - 1) ) {
@lines = split(/\n/, $items[$i], 7);
$commit[$i] = [ @lines ];
}
return @commit;
}
return 1;
View
@@ -67,7 +67,7 @@ sub CreateRSS {
my $file = shift || return undef;
my $rss = shift || return undef;
my $github = shift;
my @items = GENERIC::SplitCommits($gitlog, "\n&gt;");
my @items = PARSER::SplitCommits($gitlog, "\n&gt;");
my $weblink = "https://github.com";
my $itemlink = $rss{'link'};
my $commit;

0 comments on commit 3ee5239

Please sign in to comment.