Simplified and restyled trp.h
[svn-fe.git] / replay.pl
blob72fcf1e91d85a6820048d83af98d828a34330891
1 #!/usr/bin/perl
3 use SVN::Core;
4 use SVN::Repos;
5 use SVN::Fs;
7 use Date::Parse;
8 use File::Temp;
10 my $pool = SVN::Pool->new_default;
12 my $mirror = '/path/to/mirror';
14 my $repos = SVN::Repos::open($mirror);
15 my $fs = $repos->fs();
17 my $uuid = $fs->revision_prop(0, 'svn:sync-from-uuid');
18 my $url = $fs->revision_prop(0, 'svn:sync-from-url');
19 my $maxrev = int($fs->revision_prop(0, 'svn:sync-last-merged-rev'));
21 print "# SVN_UUID: $uuid\n";
22 print "# SVN_URL: $url\n";
23 print "# MAX_REV: $maxrev\n";
25 my $commitlog;
26 my $nextmark = 1;
27 my $marks;
29 $repos->get_logs([''], 1, $maxrev, 1, 0, sub {
30 my ($paths, $rev, $author, $date, $log, $pool) = @_;
31 my $pool = SVN::Pool->new_default_sub;
33 print "# SVN_AUTHOR: $author\n";
34 print "# SVN_DATE: $date\n";
36 my $GIT_COMMITTER_NAME=$author;
37 my $GIT_COMMITTER_EMAIL=$author.'@'.$uuid;
38 my $GIT_COMMITTER_DATE=int(str2time($date)).' +0000';
40 my @commitlogfile = File::Temp->new();
41 $commitlog = $commitlogfile[FH];
43 print $commitlog "commit refs/heads/master\n";
44 print $commitlog "committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE\n";
45 print $commitlog 'data '.length($log)."\n$log\n";
47 my $root = $fs->revision_root($rev, $pool);
49 for my $file (keys %$paths) {
50 my $node = $paths->{$file};
51 my $action = $node->action;
53 if ($action eq 'D') {
54 my $path = substr($file, 1);
55 print $commitlog "D $path\n";
56 next;
59 if ($root->is_dir($file, $pool) ) {
60 my $path = substr($file, 1);
61 print $commitlog "D $path\n";
62 modifydir($root, $file, $pool);
63 } else {
64 modifyfile($root, $file, $pool);
68 seek $commitlog, 0, 0;
69 local $/ = \16384;
70 while (<$commitlog>) {
71 print $_;
73 close $commitlog;
75 print "progress to revision $rev\n"
76 });
78 sub modifydir {
79 my ($root, $dir, $pool) = @_;
80 my $pool = SVN::Pool->new_default_sub;
82 my $dirents = $root->dir_entries($dir, $pool);
83 for my $name (keys %$dirents) {
84 my $entry = $dirents->{$name};
85 if ($entry->kind == $SVN::Node::dir) {
86 modifydir($root, $dir.'/'.$name, $pool);
87 } else {
88 modifyfile($root, $dir.'/'.$name, $pool);
93 sub modifyfile {
94 my ($root, $file, $pool) = @_;
95 my $pool = SVN::Pool->new_default_sub;
97 my $proplist = $root->node_proplist($file, $pool);
98 my $md5 = $root->file_md5_checksum($file, $pool);
99 # Strip the leading slash from the path for git
100 my $path = substr($file, 1);
102 my $mode;
104 if (defined $proplist->{'svn:special'}) {
105 $mode = '120000';
106 $md5 .= 'L';
107 } else {
108 $mode = defined $proplist->{'svn:executable'} ? '100755' : '100644';
111 my $mark = $marks->{$md5};
112 if (!defined $mark) {
113 $mark = $nextmark++;
114 $marks->{$md5} = $mark;
115 my $length = $root->file_length($file, $pool);
116 $length -= 5 if $mode == '120000';
117 my $contents = $root->file_contents($file, $pool);
118 print "# MD5: $md5\n";
119 print "blob\nmark :$mark\n";
120 print "data $length\n";
121 local $/ = \16384;
122 my $linkprefix;
123 read $contents, $linkprefix, 5 if $mode == '120000';
124 while (<$contents>) {
125 print $_;
127 close $contents;
128 print "\n";
130 print $commitlog "M $mode :$mark $path\n";