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