/
sql.ph
executable file
·93 lines (77 loc) · 2.65 KB
/
sql.ph
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/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 SQL;
#
# Subroutines
#
sub ShowHelp {
print <<"HELP";
Gitlog to SQL - Converts the output of `git log` to a SQL 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.sql
--prompt Prompt for input and do not use options
--help Show this output
HELP
exit;
}
sub TableStruct {
my $file = shift || return undef;
open(FILE, ">$file");
print FILE "-- Create table structure
CREATE TABLE IF NOT EXISTS `gitlog` (
`hash` varchar(40) NOT NULL DEFAULT '' COMMENT 'Unique identifier of commit',
`date` varchar(40) NOT NULL DEFAULT '' COMMENT 'Time of commit',
`author` varchar(30) NOT NULL DEFAULT '' COMMENT 'Author of commit',
`email` varchar(30) NOT NULL DEFAULT '' COMMENT 'Email of commit',
`subject` text NOT NULL COMMENT 'Subject of commit',
`body` text NOT NULL COMMENT 'Body message of commit',
PRIMARY KEY(`hash`)
);\n
-- Insert rows";
close(FILE);
return 1;
}
sub CreateSQL {
my $gitlog = shift || return undef;
my $file = shift || return undef;
my @items = PARSER::SplitCommits($gitlog);
TableStruct($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 "
INSERT IGNORE INTO `gitlog` VALUES ('$items[$i][1]', '$items[$i][2]', '$items[$i][3]', '$items[$i][4]', '$items[$i][5]', '$items[$i][6]');";
}
close(FILE);
return 1;
}
return 1;