From: Ben Elliston <bje@redhat.com>
To: overseers@sources.redhat.com
Subject: patch to log_accum
Date: Thu, 24 Oct 2002 18:02:00 -0000 [thread overview]
Message-ID: <m3fzuvl4a2.fsf@scooby.brisbane.redhat.com> (raw)
A patch to /usr/sourceware/bin/log_accum appears below that adds a
`-i' option to emit SQL INSERT statements to files in a spool
directory. I have proofread it a number of times and believe it is
innocuous. It certainly does nothing unless `-i' is selectively
passed by each project's loginfo file.
The reason behind this patch is that, for each commit, a file in
/var/spool/cvsql (or some other location) is created containing SQL
statements that a cron job of mine will process periodically. The CVS
commit information will be placed in an SQL database. I am currently
working on a web-based front-end (called `CVSQL') to allow all sorts
of expressive queries to be issued.
I would really like to see this patch go in, and so am willing to work
to make it palatable to the sources overseers. ;-)
Cheers, Ben
--- log_accum~ Fri Oct 25 10:51:59 2002
+++ log_accum Fri Oct 25 10:52:57 2002
@@ -27,6 +27,7 @@
# -D DOMAIN - Domain from which mail should appear
# -l - Update list of modified files in CVSROOT/commits.
# Must be run using %{sVv}.
+# -i - Generate SQL INSERT statements for CVSQL.
use POSIX;
@@ -35,6 +36,7 @@
#
$TMPDIR = "/sourceware/cvs-tmp";
+$SQL_SPOOLDIR = "/var/spool/cvsql";
# Set this to something that takes "-s"
$MAILER = "/usr/bin/Mail";
@@ -311,6 +313,45 @@
close(FILE);
}
+# Return a sequence of SQL inserts.
+sub generate_cvsql_inserts {
+ local ($dir, $branch, @files) = @_;
+ local (@sp, @result);
+ local ($now) = strftime ("%Y/%m/%d %H:%M:%S", localtime);
+ local ($msg) = join ("\n", @log_lines);
+
+ if ($branch eq '') {
+ $branch = 'null';
+ } else {
+ $branch = '\'' . $branch . '\'';
+ }
+
+ # Escape certain characters for psql(1).
+ $msg =~ s,(\'|\"|\\),\\$1,g;
+
+ push (@result, '\\set id `psql -d cvs -A -t -c "select nextval (\'changesetid_seq\');"`');
+ push (@result, 'INSERT INTO changeset (id,author,date,msg,cvsroot) values (:id,\'' .
+ $login . '\',\'' . $now . '\',\'' . $msg . '\',\'' . $hostdomain . ':' . $cvsroot . '\');');
+
+ foreach (@files) {
+ # List is (FILE OLD-REV NEW-REV).
+ @sp = split (',');
+ if ($sp[1] eq 'NONE') {
+ $sp[1] = 'null';
+ } else {
+ $sp[1] = '\'' . $sp[1] . '\'';
+ }
+ if ($sp[2] eq 'NONE') {
+ $sp[2] = 'null';
+ } else {
+ $sp[2] = '\'' . $sp[2] . '\'';
+ }
+ push (@result, 'INSERT INTO change (filename,prerev,postrev,branch,changeset) values (\'' .
+ $dir . '/' . $sp[0] . '\',' . $sp[1] . ',' . $sp[2] . ',' . $branch . ',:id);');
+ }
+ return @result;
+}
+
# Return a list of all cvsweb URLs for this commit.
sub generate_cvsweb_urls {
local ($dir, $branch, @files) = @_;
@@ -564,6 +605,7 @@
$do_cvsweb = 0;
$cvsweb_name = '';
$do_modlist = 0;
+$do_cvsql = 0;
# parse command line arguments (file list is seen as one arg)
#
@@ -596,6 +638,8 @@
$hostdomain = shift @ARGV;
} elsif ($arg eq '-l') {
$do_modlist = 1;
+ } elsif ($arg eq '-i') {
+ $do_cvsql = 1;
} else {
($donefiles) && die("Too many arguments! Check usage.\n");
$donefiles = 1;
@@ -762,6 +806,11 @@
@files[1 .. $#files]);
}
+if ($do_cvsql) {
+ @sql_stmts = &generate_cvsql_inserts (join ('/', @path), $branch,
+ @files[1 .. $#files]);
+}
+
if ($do_modlist) {
@modlist = generate_modlist (join ('/', @path),
\@changed_files, \@added_files, \@removed_files,
@@ -923,18 +972,42 @@
#
&mail_notification($mailto, $subject_txt, @text);
-# Send mail to Gnats, if required.
-if ($gnatsdb ne '') {
- $log_txt = join ("\n", @log_txt);
- while ($log_txt =~ m,PR ([a-z.+]+/[0-9]+)(.*)$,s) {
- $pr = $1;
- $log_txt = $2;
+$log_txt = join ("\n", @log_txt);
+while ($log_txt =~ m,PR ([a-z.+]+/[0-9]+)(.*)$,s) {
+ $pr = $1;
+ $log_txt = $2;
+
+ # Send mail to Gnats, if required.
+ if ($gnatsdb ne '') {
$file = sprintf ($GNATS_ROOT_FORMAT, $gnatsdb) . "/" . $pr;
if (-f $file) {
&mail_notification(sprintf ($GNATS_MAIL_FORMAT, $gnatsdb),
$pr, @text);
}
}
+ if ($do_cvsql) {
+ push(@sql_stmts, 'INSERT INTO bugreport (changeset,id) values (:id, \'' . $pr . '\');');
+ }
+}
+
+# Write out an SQL batch file.
+#
+if ($do_cvsql) {
+ $extension = $$;
+ do
+ {
+ $extension++;
+ $spoolfile = $SQL_SPOOLDIR . "/tmp." . $extension;
+ print "trying " . $spoolfile . "\n";
+ } while (!sysopen SQL, $spoolfile, O_WRONLY | O_CREAT | O_EXCL, 0644);
+
+ print SQL "BEGIN;";
+ if ($debug) { print join("\n", @sql_stmts), "\n"; }
+ print SQL join("\n", @sql_stmts), "\n";
+ print SQL "COMMIT;\n";
+ close (SQL);
+ $newfile = $SQL_SPOOLDIR . "/sql." . $extension;
+ rename $spoolfile, $newfile
}
# cleanup
next reply other threads:[~2002-10-25 1:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-24 18:02 Ben Elliston [this message]
2002-10-25 0:48 ` Jason Molenda
2002-10-25 2:13 ` Ben Elliston
2002-10-27 1:06 ` Ben Elliston
2002-10-28 2:19 ` Jason Molenda
2002-10-28 15:54 ` Ben Elliston
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3fzuvl4a2.fsf@scooby.brisbane.redhat.com \
--to=bje@redhat.com \
--cc=overseers@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).