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