#!/usr/bin/perl -w use DBI; use IPC::Open2; system('mkdir doc') && die; chdir('doc'); qx{git init}; open AUTHORS, '../trac-authors' or die $!; my %authors = (); while (chomp ($line = )) { my ($username, $name); ($username, $name) = split / /, $line, 2; print "$username $name\n"; $authors{$username} = $name; } $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}..."; ($text = $row->{text}) =~ s/\r\n/\n/g; $pid = open2(OUT, IN, qw(git hash-object -w --stdin)); print IN $text; close(IN); chomp($blob = ); waitpid $pid, 0; $pid = open2(OUT, IN, qw(git mktree)); print IN `git ls-tree $head:doc | grep -v $row->{name}` if $head; print IN "100644 blob $blob\t$row->{name}\n"; close(IN); chomp($tree = ); waitpid $pid, 0; $pid = open2(OUT, IN, qw(git mktree)); print IN "040000 tree $tree\tdoc\n"; close(IN); chomp($tree = ); waitpid $pid, 0; $name = $authors{$row->{author}}; $ENV{GIT_AUTHOR_NAME} = "$name"; $ENV{GIT_AUTHOR_EMAIL} = "$row->{author}\@mit.edu"; $ENV{GIT_COMMITTER_NAME} = "Trac"; $ENV{GIT_COMMITTER_EMAIL} = "sipb-www\@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 = ); waitpid $pid, 0; print "committed as $head.\n"; } qx{git reset --hard $head};