rewrote the post-commit script in perl
This commit is contained in:
@ -38,7 +38,8 @@ POST_UNINSTALL = :
|
||||
subdir = etc
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
|
||||
$(srcdir)/codepot.a2ldap.in $(srcdir)/codepot.ini.in \
|
||||
$(srcdir)/pre-revprop-change.in $(srcdir)/start-commit.in
|
||||
$(srcdir)/post-commit.in $(srcdir)/pre-revprop-change.in \
|
||||
$(srcdir)/start-commit.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/ac/m4/as-ac-expand.m4 \
|
||||
$(top_srcdir)/configure.ac
|
||||
@ -47,7 +48,7 @@ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||
mkinstalldirs = $(install_sh) -d
|
||||
CONFIG_HEADER = $(top_builddir)/./config.h
|
||||
CONFIG_CLEAN_FILES = codepot.ini codepot.a2ldap start-commit \
|
||||
pre-revprop-change
|
||||
post-commit pre-revprop-change
|
||||
am__installdirs = "$(DESTDIR)$(cfgdir)" "$(DESTDIR)$(perldir)" \
|
||||
"$(DESTDIR)$(cfgdir)"
|
||||
cfgSCRIPT_INSTALL = $(INSTALL_SCRIPT)
|
||||
@ -190,6 +191,8 @@ codepot.a2ldap: $(top_builddir)/config.status $(srcdir)/codepot.a2ldap.in
|
||||
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
|
||||
start-commit: $(top_builddir)/config.status $(srcdir)/start-commit.in
|
||||
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
|
||||
post-commit: $(top_builddir)/config.status $(srcdir)/post-commit.in
|
||||
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
|
||||
pre-revprop-change: $(top_builddir)/config.status $(srcdir)/pre-revprop-change.in
|
||||
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
|
||||
install-cfgSCRIPTS: $(cfg_SCRIPTS)
|
||||
|
@ -1,10 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
REPOBASE="`basename "${1}"`"
|
||||
REV="${2}"
|
||||
|
||||
AUTHOR="`svnlook author -r ${REV} "${1}"`"
|
||||
|
||||
# does not care if logging has failed.
|
||||
wget -q -O- "%API%/logCodeCommit/svn/${REPOBASE}/${REV}/${AUTHOR}" 2>/dev/null
|
||||
exit 0
|
109
codepot/etc/post-commit.in
Normal file
109
codepot/etc/post-commit.in
Normal file
@ -0,0 +1,109 @@
|
||||
#!/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
|
||||
{
|
||||
my $cfg = new Config::Simple();
|
||||
|
||||
if (!$cfg->read ($CFG_FILE))
|
||||
{
|
||||
return undef;
|
||||
}
|
||||
|
||||
my $config = {
|
||||
database_hostname => $cfg->param ("database_hostname"),
|
||||
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")
|
||||
};
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
sub open_database
|
||||
{
|
||||
my ($cfg) = @_;
|
||||
|
||||
my $dbtype = $cfg->{database_driver};
|
||||
my $dbname = $cfg->{database_name};
|
||||
my $dbhost = $cfg->{database_hostname};
|
||||
|
||||
my $dbh = DBI->connect(
|
||||
"DBI:$dbtype:$dbname:$dbhost",
|
||||
$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());
|
||||
|
||||
print ("INSERT INTO ${prefix}log(type,projectid,message,createdon,action,userid) VALUES(?,?,?,?,?,? $createdon $message)\n");
|
||||
my $query = $dbh->prepare ("INSERT INTO ${prefix}log(type,projectid,message,createdon,action,userid) VALUES(?,?,?,?,?,?)");
|
||||
if (!$query || !$query->execute ('code', $projectid, $message, $createdon, 'commit', $userid))
|
||||
{
|
||||
$dbh->rollback ();
|
||||
return (-1, $dbh->errstr());
|
||||
}
|
||||
|
||||
$dbh->commit ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#------------------------------------------------------------
|
||||
# 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))
|
||||
{
|
||||
print (STDERR "Cannot open database\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
write_commit_log ($dbh, $cfg->{database_prefix}, $REPOBASE, $REV, $AUTHOR);
|
||||
close_database ($dbh);
|
||||
|
||||
exit (0);
|
||||
|
Reference in New Issue
Block a user