2014-05-16 15:49:16 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
use Config::Simple;
|
|
|
|
use DBI;
|
|
|
|
use File::Basename;
|
|
|
|
use POSIX qw(strftime);
|
|
|
|
|
|
|
|
my $CFG_FILE = '@CFGDIR@/codepot.ini';
|
|
|
|
my $REPO = $ARGV[0];
|
|
|
|
my $REPOBASE = basename($REPO);
|
|
|
|
my $REV = $ARGV[1];
|
|
|
|
|
|
|
|
sub get_config
|
|
|
|
{
|
2014-06-23 14:57:07 +00:00
|
|
|
my $cfg = new Config::Simple();
|
2014-05-16 15:49:16 +00:00
|
|
|
|
2014-06-23 14:57:07 +00:00
|
|
|
if (!$cfg->read ($CFG_FILE))
|
|
|
|
{
|
|
|
|
return undef;
|
|
|
|
}
|
2014-05-16 15:49:16 +00:00
|
|
|
|
2014-06-23 14:57:07 +00:00
|
|
|
my $config = {
|
|
|
|
database_hostname => $cfg->param ("database_hostname"),
|
2015-04-28 05:12:06 +00:00
|
|
|
database_port => $cfg->param ("database_port"),
|
2014-06-23 14:57:07 +00:00
|
|
|
database_username => $cfg->param ("database_username"),
|
|
|
|
database_password => $cfg->param ("database_password"),
|
|
|
|
database_name => $cfg->param ("database_name"),
|
|
|
|
database_driver => $cfg->param ("database_driver"),
|
|
|
|
database_prefix => $cfg->param ("database_prefix")
|
|
|
|
};
|
2014-05-16 15:49:16 +00:00
|
|
|
|
2014-06-23 14:57:07 +00:00
|
|
|
return $config;
|
2014-05-16 15:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub open_database
|
|
|
|
{
|
|
|
|
my ($cfg) = @_;
|
|
|
|
|
|
|
|
my $dbtype = $cfg->{database_driver};
|
|
|
|
my $dbname = $cfg->{database_name};
|
|
|
|
my $dbhost = $cfg->{database_hostname};
|
2015-04-28 05:12:06 +00:00
|
|
|
my $dbport = $cfg->{database_port};
|
|
|
|
|
|
|
|
if ($dbtype eq 'postgre') { $dbtype = 'Pg'; }
|
|
|
|
|
|
|
|
my $dbstr = "DBI:$dbtype:database=$dbname;";
|
|
|
|
if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; }
|
|
|
|
if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; }
|
2014-05-16 15:49:16 +00:00
|
|
|
|
|
|
|
my $dbh = DBI->connect(
|
2015-04-28 05:12:06 +00:00
|
|
|
$dbstr,
|
2014-05-16 15:49:16 +00:00
|
|
|
$cfg->{database_username},
|
|
|
|
$cfg->{database_password},
|
|
|
|
{ RaiseError => 0, PrintError => 0, AutoCommit => 0 }
|
|
|
|
);
|
|
|
|
|
|
|
|
return $dbh;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub close_database
|
|
|
|
{
|
|
|
|
my ($dbh) = @_;
|
|
|
|
$dbh->disconnect ();
|
|
|
|
}
|
|
|
|
|
|
|
|
sub write_commit_log
|
|
|
|
{
|
|
|
|
my ($dbh, $prefix, $projectid, $revision, $userid) = @_;
|
|
|
|
|
|
|
|
#+------+---------+-----------+---------------------------+---------------------+---------------+-----------------+
|
|
|
|
#| id | type | projectid | message | createdon | action | userid |
|
|
|
|
#+------+---------+-----------+---------------------------+---------------------+---------------+-----------------+
|
|
|
|
#| 895 | code | codepot | svn,codepot,72 | 2011-10-10 14:26:43 | commit | hyunghwan.chung |
|
|
|
|
|
|
|
|
my $message = "svn,$projectid,$revision";
|
|
|
|
my $createdon = strftime ('%Y-%m-%d %H:%M:%S', localtime());
|
|
|
|
|
2014-05-16 16:11:33 +00:00
|
|
|
$dbh->begin_work ();
|
|
|
|
|
|
|
|
my $query = $dbh->prepare ("INSERT INTO ${prefix}log (type,projectid,message,createdon,action,userid) VALUES (?,?,?,?,?,?)");
|
2014-05-16 15:49:16 +00:00
|
|
|
if (!$query || !$query->execute ('code', $projectid, $message, $createdon, 'commit', $userid))
|
|
|
|
{
|
2014-05-16 16:11:33 +00:00
|
|
|
my $errstr = $dbh->errstr();
|
|
|
|
$query->finish ();
|
2014-05-16 15:49:16 +00:00
|
|
|
$dbh->rollback ();
|
2014-05-16 16:11:33 +00:00
|
|
|
return (-1, $errstr);
|
2014-05-16 15:49:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 16:11:33 +00:00
|
|
|
$query->finish ();
|
2014-05-16 15:49:16 +00:00
|
|
|
$dbh->commit ();
|
2014-05-16 16:11:33 +00:00
|
|
|
return (0, undef);
|
2014-05-16 15:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
#------------------------------------------------------------
|
|
|
|
|
|
|
|
my $AUTHOR = `svnlook author -r "${REV}" "${REPO}"`;
|
|
|
|
chomp ($AUTHOR);
|
|
|
|
|
|
|
|
my $cfg = get_config ();
|
|
|
|
if (!defined($cfg))
|
|
|
|
{
|
|
|
|
print (STDERR "Cannot load codepot configuration file\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
my $dbh = open_database ($cfg);
|
|
|
|
if (!defined($dbh))
|
|
|
|
{
|
2015-04-28 05:12:06 +00:00
|
|
|
printf (STDERR "Cannot open database - %s\n", $DBI::errstr);
|
2014-05-16 15:49:16 +00:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
write_commit_log ($dbh, $cfg->{database_prefix}, $REPOBASE, $REV, $AUTHOR);
|
|
|
|
close_database ($dbh);
|
|
|
|
|
|
|
|
exit (0);
|
|
|
|
|