]> sipb.mit.edu Git - sipb-www.git/commitdiff
import geofft's script for importing the doc wiki
authorGreg Price <price@mit.edu>
Sun, 1 Feb 2009 01:31:58 +0000 (20:31 -0500)
committerGreg Price <price@mit.edu>
Sun, 1 Feb 2009 01:50:36 +0000 (20:50 -0500)
password excised in favor of reading /mit/sipb-www/.my.cnf

import-trac [new file with mode: 0755]

diff --git a/import-trac b/import-trac
new file mode 100755 (executable)
index 0000000..1d1656f
--- /dev/null
@@ -0,0 +1,38 @@
+#!/usr/bin/perl
+use DBI;
+use IPC::Open2;
+
+$password = qx(perl -F= -lane 'print \$F[1] if (\$F[0] eq "password")' \\
+               /mit/sipb-www/.my.cnf);
+chomp $password;
+$dbh = DBI->connect('DBI:mysql:sipb-www+doc;host=sql.mit.edu',
+                   'sipb-www', $password) or die;
+$rows = $dbh->selectall_arrayref('SELECT * FROM wiki', {Slice=>{}});
+foreach $row (@$rows) {
+  next if $row->{author} eq 'trac';
+  print "Processing revision $row->{version} of $row->{name} by $row->{author}...";
+
+  $pid = open2(OUT, IN, qw(git hash-object -w --stdin));
+  print IN $row->{text};
+  close(IN);
+  chomp($blob = <OUT>);
+  waitpid $pid, 0;
+
+  $pid = open2(OUT, IN, qw(git mktree));
+  print IN `git ls-tree $head | grep -v $row->{name}` if $head;
+  print IN "100644 blob $blob\t$row->{name}\n";
+  close(IN);
+  chomp($tree = <OUT>);
+  waitpid $pid, 0;
+
+  $ENV{GIT_AUTHOR_NAME} = "$row->{author} via Trac";
+  $ENV{GIT_AUTHOR_EMAIL} = "$row->{author}\@mit.edu";
+  $ENV{GIT_AUTHOR_DATE} = $row->{time};
+  $pid = open2(OUT, IN, qw{git commit-tree}, $tree, $head ? ('-p', $head) : ());
+  print IN $row->{comment};
+  close(IN);
+  chomp($head = <OUT>);
+  waitpid $pid, 0;
+
+  print "committed as $head.\n";
+}