]> sipb.mit.edu Git - sipb-www.git/blob - import-trac
53f747896ca42a5fec9597d304281f4373f19b1c
[sipb-www.git] / import-trac
1 #!/usr/bin/perl
2 use DBI;
3 use IPC::Open2;
4
5 $password = qx(perl -F= -lane 'print \$F[1] if (\$F[0] eq "password")' \\
6                /mit/sipb-www/.my.cnf);
7 chomp $password;
8 $dbh = DBI->connect('DBI:mysql:sipb-www+doc;host=sql.mit.edu',
9                     'sipb-www', $password) or die;
10 $rows = $dbh->selectall_arrayref('SELECT * FROM wiki', {Slice=>{}});
11 foreach $row (@$rows) {
12   next if $row->{author} eq 'trac';
13   print "Processing revision $row->{version} of $row->{name} by $row->{author}...";
14
15   $pid = open2(OUT, IN, qw(git hash-object -w --stdin));
16   print IN $row->{text};
17   close(IN);
18   chomp($blob = <OUT>);
19   waitpid $pid, 0;
20
21   $pid = open2(OUT, IN, qw(git mktree));
22   print IN `git ls-tree $head | grep -v $row->{name}` if $head;
23   print IN "100644 blob $blob\t$row->{name}\n";
24   close(IN);
25   chomp($tree = <OUT>);
26   waitpid $pid, 0;
27
28   $ENV{GIT_AUTHOR_NAME} = "$row->{author} via Trac";
29   $ENV{GIT_AUTHOR_EMAIL} = "$row->{author}\@mit.edu";
30   $ENV{GIT_AUTHOR_DATE} = $row->{time};
31   $pid = open2(OUT, IN, qw{git commit-tree}, $tree, $head ? ('-p', $head) : ());
32   print IN $row->{comment};
33   close(IN);
34   chomp($head = <OUT>);
35   waitpid $pid, 0;
36
37   print "committed as $head.\n";
38 }
39
40 qx{git reset --hard $head};